1.前期需要的安裝包下載地址:
對(duì)應(yīng)下載的網(wǎng)站:https://github.com/openresty
luajit: wget --no-check-certificate https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20210510.tar.gz
lua-nginx-module:wget --no-check-certificate https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.19rc1.tar.gz
lua-resty-core:wget --no-check-certificate https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.22.tar.gz
lua-resty-lrucache:wget --no-check-certificate https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.11.tar.gz
nginx-1.20.2:wget --no-check-certificate http://nginx.org/download/nginx-1.20.2.tar.gz
ngx_devel_kit-0.3.0:wget --no-check-certificate https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.0.tar.gz
備注:
luajit? ? ? ?#不要下載官網(wǎng)的枉证,要去下載openresty的優(yōu)化版本 后面會(huì)說出現(xiàn)的坑
lua-resty-core和lua-resty-lrucache是必須的包封孙,0.10.16 以后都需要這兩個(gè)包
2.安裝(app用戶安裝):
#安裝包放到這個(gè)目錄下面
mkdir /app/nginx_plug? ? ? ? ? ?
tar xf? v2.1-20210510.tar.gz
cd luajit2-2.1-20210510
make install? PREFIX=/app/nginx_plug/LuaJIT
#添加環(huán)境變量
export LUAJIT_LIB=/app/nginx_plug/LuaJIT/lib
export LUAJIT_INC=/app/nginx_plug/LuaJIT/include/luajit-2.1
[app@web01 /opt/download]$ tail -3f /etc/profile
#Lua
export LUAJIT_LIB=//app/nginx_plug/LuaJIT/lib
export LUAJIT_INC=/app/nginx_plug/LuaJIT/include/luajit-2.1
source??/etc/profile
#安裝Lua核心庫
lua-resty-core-0.1.21.tar.gz [必須]
lua-resty-lrucache-0.11.tar.gz [必須]
#安裝在同一個(gè)目錄下
cd lua-resty-core-0.1.22
make install PREFIX=?/etc/profile/lua_core
cd ../lua-resty-lrucache-0.11
make install PREFIX=?/etc/profile/lua_core
#解壓v0.3.0.tar.gz和v0.10.19rc1.tar.gz
#nginx安裝
cd nginx-1.20.2/
./configure?--prefix=/app/nginx20 --pid-path=/app/nginx20/logs/nginx.pid --with-http_ssl_module --with-http_v2_module --with-http_dav_module --with-http_flv_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_stub_status_module --with-http_sub_module --with-http_random_index_module --with-http_degradation_module --with-http_secure_link_module --with-http_gzip_static_module --http-client-body-temp-path=/app/nginx20/client_body --http-proxy-temp-path=/app/nginx20/proxy --http-fastcgi-temp-path=/app/nginx20/fastcgi --http-uwsgi-temp-path=/app/nginx20/uwsgi --http-scgi-temp-path=/app/nginx20/scgi --with-stream --with-ld-opt=-Wl,-E --add-module=/app/nginx_plug/lua-nginx-module-0.10.19rc1/ --add-module=/app/nginx_plug/ngx_devel_kit-0.3.0
make
make install
#加載lua庫糊啡,加入到ld.so.conf文件
[root@web01 ~]# echo "/app/nginx_plug/LuaJIT/lib" >> /etc/ld.so.conf
[root@web01 ~]#? ldconfig
#啟動(dòng)nginx
/app/nginx20/sbin/nginx -c /app/nginx20/conf/nginx.conf
3.上面都是經(jīng)過安裝的一些坑之后安裝完成的,下面是安裝過程中出現(xiàn)的坑
報(bào)錯(cuò)截圖:配置文件沒有問題,但是起不來
1)nginx: [alert] detected a LuaJIT version which is not OpenResty's; many optimizations will be disabled and performance will be compromised (see https://github.com/openresty/luajit2 for OpenResty's LuaJIT or, even better, consider using the OpenResty releases from https://openresty.org/en/download.html)
# 讓我不要用這個(gè)luajit版本莹捡,可以用openresty提供的luajit優(yōu)化版本怕犁,或者干脆直接用openresty
#卸載luajit官網(wǎng)版本,下載openresty提供的luajit優(yōu)化版本
對(duì)應(yīng)luajit-----#不要下載官網(wǎng)的幢码,要去下載openresty的優(yōu)化版本 后面會(huì)說出現(xiàn)的坑
2)報(bào)錯(cuò)信息:
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
no field package.preload['resty.core']
no file './resty/core.lua'
no file '/usr/local/share/luajit-2.0.5/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core.lua'
no file '/usr/local/share/lua/5.1/resty/core/init.lua'
no file './resty/core.so'
no file '/usr/local/lib/lua/5.1/resty/core.so'
no file '/usr/local/lib/lua/5.1/loadall.so'
no file './resty.so'
no file '/usr/local/lib/lua/5.1/resty.so'
no file '/usr/local/lib/lua/5.1/loadall.so') in /app/nginx20/conf/nginx.conf:441
解決方法:
1)這個(gè)問題到git上面看了,就是在nginx.conf 中的 http{}模塊中加入下面這行代碼:lua_load_resty_core off;但是檢查的時(shí)候發(fā)現(xiàn)這命令已經(jīng)廢棄,顯然這樣不行笤休,造成這樣的原因是:nginx_lua 0.10.16之后的版本是需要lua_resty_core庫的,需要需要在安裝lua-resty-core-0.1.21和lua-resty-lrucache-0.11(安裝參考上面)
2)安裝完成之后依然還是報(bào)錯(cuò):
nginx: [alert] failed to load the 'resty.core' module (https://github.com/openresty/lua-resty-core); ensure you are using an OpenResty release from https://openresty.org/en/download.html (reason: module 'resty.core' not found:
解決方法:創(chuàng)建超鏈接
ln -s /app/nginx_plug/lua_core/lib/lua/resty? ? /app/nginx_plug/LuaJIT/share/luajit-2.1.0-beta3/resty
3)再重啟發(fā)現(xiàn)服務(wù)可以啟動(dòng)了