![]()
1.编译安装luajit:
wget https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20220411.tar.gz
mv v2.1-20220411.tar.gz luajit2-v2.1-20220411.tar.gz
tar xvf luajit2-v2.1-20220411.tar.gz
cd luajit2-2.1-20220411/
[root@xianchaonode1 lua]# mkdir -p /usr/local/luajit2-2.1
make install PREFIX=/usr/local/luajit2-2.1
=>==== Successfully installed LuaJIT 2.1.0-beta3 to /usr/local/luajit2-2.1 ====
配置系统环境变量-编译安装nginx的时候使用:
vim /etc/profile
export LUAJIT_LIB=/usr/local/luajit2-2.1/lib
export LUAJIT_INC=/usr/local/luajit2-2.1/include/luajit-2.1
source /etc/profile
加载luajit2模块,nginx启动需要调用libluajit-5.1.so.2模块
vim /etc/ld.so.conf.d/libc.conf
/usr/local/lib
/usr/local/luajit2-2.1/lib/
ldconfig
2.编译安装lua核心库,nginx需要加载lua库:
2.1: lua-resty-core22
# wget https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.23.tar.gz23
# mv v0.1.23.tar.gz lua-resty-core-v0.1.23.tar.gz
# tar zxvf lua-resty-core-v0.1.23.tar.gz
# cd lua-resty-core-0.1.23/
# make install PREFIX=/usr/local/luacore
2.2: lua-resty-lrucache
# wget https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.13.tar.gz
# mv v0.13.tar.gz lua-resty-rucache-v0.13.tar.gz
# tar xvf lua-resty-lrucache-v0.13.tar.gz
# cd lua-resty-lrucache-0.13/
# make install PREFIX=/usr/local/luacore
3.编译安装lua-cjson:
# wget https://github.com/mpx/lua-cjson/archive/refs/tags/2.1.0.tar.gz
# mv 2.1.0.tar.gz lua-cjson-2.1.0.tar.gz
# tar xvf lua-cjson-2.1.0.tar.gz
# cd lua-cjson-2.1.0/
# vim Makefile
21 LUA_INCLUDE_DIR = /usr/local/luajit2-2.1/include/luajit-2.1
# vim lua_cjson.c
1291 /*_-=-- INITIALISATION ===-= */
1292
1293 #if !defined(LUA_VERSION_NUM) || LUA_VERSION_NUM < 502
1294 /* Compatibility for Lua 5.1.
1295
1296* luaL_setfuncs() is used to create a module table where the functions have
1297* json_config_t as their first upvalue. Code borrowed from Lua 5.2 source. */
修改去掉static :1298 void luaL_setfuncs (lua_State *l, const luaL_Reg *reg, int nup)
注,有警告无影响:
[root@xianchaonode1 lua-cjson-2.1.0]# make
cc -c -O3 -Wall -pedantic -DNDEBUG -I/usr/local/luajit2-2.1/include/luajit-2.1 -fpic -o lua_cjson.o lua_cjson.c
cc -c -O3 -Wall -pedantic -DNDEBUG -I/usr/local/luajit2-2.1/include/luajit-2.1 -fpic -o strbuf.o strbuf.c
cc -c -O3 -Wall -pedantic -DNDEBUG -I/usr/local/luajit2-2.1/include/luajit-2.1 -fpic -o fpconv.o fpconv.c
cc -shared -o cjson.so lua_cjson.o strbuf.o fpconv.o
[root@xianchaonode1 lua-cjson-2.1.0]# make install
mkdir -p //usr/local/lib/lua/5.1
cp cjson.so //usr/local/lib/lua/5.1
chmod 755 //usr/local/lib/lua/5.1/cjson.so
4.建备ngx_devel_kit源码:
# wget https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.1.tar.gz
# mv v0.3.1.tar.gz ngx_devel_kit-v0.3.1.tar.gz
# tar xvf ngx_devel_kit-v0.3.1.tar.gz
5.准备Lua-nginx-module源码:
# wget https://github,com/openresty/lua-nginx-module/archive/refs/tags/v0.10.21.tar.gz
# mv v0.10.21.tar.gz lua-nginx-module-v0.10.21.tar.gz
[root@xianchaonode1 lua]# tar zxvf lua-nginx-module-v0.10.21.tar.gz
编译安装nginx:
# wget https://nginx.org/download/nginx-1.20.2.tar.gz
# tar xvf nginx-1.20.2.tar.gz
# cd nginx-1.20.2/
# ./configure --prefix=/apps/nginx \
--with-http_ssl_module \
--with-http_v2_module \
--with-http_realip_module \
--with-http_stub_status_module \
--with-http_gzip_static_module \
--with-pcre \
--with-stream \
--with-stream_ssl_module \
--with-stream_realip_module \
--add-module=../ngx_devel_kit-0.3.1/ \
--add-module=../lua-nginx-module-0.10.21/
# make && make install
验证lua环境:
# vim /apps/nginx/conf/nginx.conf
include mime.types;
default_type application/octet-stream;
lua_package_path "/usr/local/luacore/lib/lua/?.lua;;";:
location /hello {
default_type text/html;
content_by_lua_block {
ngx.say("Hello Lua!")
}
}
# /apps/nginx/sbin/nginx -t
nginx: the configuration file /apps/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /apps/nginx/conf/nginx.conf test is successful
#/apps/nginx/sbin/nginx
![]()
配置 Nginx-agent
![]()
# mkdir /data
# cd /data/
# wget https://github.com/apache/skywalking-nginx-lua/archive/refs/tags/v0.6.0.tar.gz
# mv v0.6.0.tar.gz skywalking-nginx-lua-v0.6.0.tar.gz
# tar zxvf skywalking-nginx-lua-v0.6.0.tar.gz
# vim /apps/nginx/conf/nginx.conf
include mime.types;
default_type application/octet-stream;
#lua_package_path"/usr/local/luacore/lib/lua/?.lua;;";
lua_package_path "/usr/local/luacore/lib/lua/?.lua;/data/skywalking-nginx-lua-0.6.0/lib/?.lua;;";
include /apps/nginx/conf/conf.d/*.conf;
# mkdir /apps/nginx/conf/conf.d/
# cd /apps/nginx/conf/conf.d/
# vim myserver.conf
#这里之前已经配置过 不能重复配置
#lua_package_path "/data/skywalking-nginx-lua-0.6.0/lib/?.lua;;";
# Buffer represents the register inform and the queue of the finished segment
lua_shared_dict tracing_buffer 100m;
# Init is the timer setter and keeper
# Setup an infinite loop timer to do register and trace report.
init_worker_by_lua_block {
local metadata_buffer = ngx.shared.tracing_buffer
-- Set service name
metadata_buffer:set('serviceName', 'myserver-nginx')
-- Instance means the number of Nginx deployment, does not mean the worker instances
metadata_buffer:set('serviceInstanceName', 'myserver-nginx-node1')
-- type 'boolean', mark the entrySpan include host/domain
metadata_buffer:set('includeHostInEntrySpan', false)
-- set ignoreSuffix, If the operation name(HTTP URI) of the entry span includes suffixes in this set, this segment would be ignored. Multiple values should be separated by a comma(',').
-- require("skywalking.util").set_ignore_suffix(".jpg,.jpeg,.js,.css,.png,.bmp,.gif,.ico,.mp3,.mp4,.svg")
-- set random seed
require("skywalking.util").set_randomseed()
require("skywalking.client"):startBackendTimer("http://192.169.40.181:12800")
-- If there is a bug of this `tablepool` implementation, we can
-- disable it in this way
-- require("skywalking.util").disable_tablepool()
skywalking_tracer = require("skywalking.tracer")
}
server {
listen 80;
server_name www.myserver.com;
location /jenkins {
default_type text/html;
rewrite_by_lua_block {
------------------------------------------------------
-- NOTICE, this should be changed manually
-- This variable represents the upstream logic address
-- Please set them as service logic name or DNS name
--
-- Currently, we can not have the upstream real network address
------------------------------------------------------
skywalking_tracer:start("www.myserver.com")
-- If you want correlation custom data to the downstream service
-- skywalking_tracer:start("upstream service", {custom = "custom_value"})
}
#代理到jenkins
proxy_pass http://192.168.40.181:8080;
body_filter_by_lua_block {
if ngx.arg[2] then
skywalking_tracer:finish()
end
}
log_by_lua_block {
skywalking_tracer:prepareForReport()
}
}
}
[root@xianchaonode1 sbin]# ./nginx -s reload
#hosts文件
192.168.40.181 www.myserver.com
#解决bug
git clone https://github.com/openresty/lua-tablepool.git
cd lua-tablepool/
cp lib/tablepool.lua /data/skywalking-nginx-lua-0.6.0/
cd /apps/nginx/sbin/
./nginx -s reload