1、自1.11.2.2開始,OpenResty版本已經包含並默認安裝opm。所以通常你不需要自己安裝opm。
2、我們在這里只需要做一個軟連接就可以了
cd /usr/local/openresty/bin sudo ln -s `pwd`/opm /usr/local/bin/opm
3、搜索指定軟件包名稱
www@TinywanAliYun:~$ opm search session bungle/lua-resty-session Session Library for OpenResty - Flexible and Secure
4、搜索具有多個模式“lru”和“cache”的軟件包名稱和摘要。
www@TinywanAliYun:~$ opm search lru cache openresty/lua-resty-lrucache Lua-land LRU Cache based on LuaJIT FFI
5、在一些作者的名字下安裝名為lua-resty-logger-socket的軟件包
www@TinywanAliYun:~$ opm get p0pr0ck5/lua-resty-logger-socket* Fetching p0pr0ck5/lua-resty-logger-socket Downloading https://opm.openresty.org/api/pkg/tarball/p0pr0ck5/lua-resty-logger-socket-0.03.opm.tar.gz
% Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 7423 100 7423 0 0 23691 0 --:--:-- --:--:-- --:--:-- 23715 Package p0pr0ck5/lua-resty-logger-socket 0.03 installed successfully under /usr/local/openresty/site/ .
結果在 /usr/local/openresty/lualib/resty 目錄下沒有這個文件下載下來
結果該文件默認下載到以下目錄了
/usr/local/openresty/site/lualib/resty
編寫代碼測試
local uuid = require 'resty.jit-uuid'
ngx.say(uuid())
問題來了,項目中直接應用,報錯,提示找不到該文件
[C]: in function 'require'
in function /status"
[error] 7626#7626: init_worker_by_lua error: init_worker_by_lua:2: module 'resty.jit-uuid' not found:
no field package.preload['resty.jit-uuid']
no file '/usr/local/openresty/lualib/resty/jit-uuid.lua'
no file '/usr/local/openresty/nginx/conf/waf/resty/jit-uuid.lua'
no file '/usr/local/openresty/lualib/resty/jit-uuid.so'
no file '/opt/verynginx/verynginx/lua_script/resty/jit-uuid.so'
no file '/usr/local/openresty/site/lualib/resty/jit-uuid.so'
no file '/usr/local/openresty/lualib/resty/jit-uuid.so'
如果復制到該目錄下,則是可以正常訪問的
/usr/local/openresty/lualib/resty
要想安裝到以上目錄
則在下載的時候指定安裝目錄就可以了
opm --install-dir=/usr/local/openresty get thibaultcha/lua-resty-jit-uuid
通過上面這種安裝方式,直接在項目中就可以使用
參考