tengine定制加上lua tengine-2.3.3 版本 cjson使用,
tengine定制加上lua tengine-2.3.3 版本 cjson使用,
tengine定制加上lua tengine-2.3.3 版本
简洁
因为需要tengine的特定功能,也需要lua进行一些定制开发,结合两个功能,需要编译支持lua的版本的tengine
各个软件依赖版本
软件 | 版本号 | 备注 |
---|---|---|
system | centos7.4 | 系统 |
jemalloc | 5.3.0 | jemalloc是tengine用于内存管理的插件 |
luajit | 2.1 | 使用openrestry库里面luajit2 |
lua-nginx-module | 0.10.21 | |
ngx_devel_kit | 0.3.1 | |
echo-nginx-module | 0.62 | |
openssl | 1.1.1q | |
pcre | 8.45 | |
zlib | 1.2.12 | |
lua-resty-core | 0.1.23 | |
lua-resty-lrucache | 0.13 | |
drizzle-nginx-module | 0.1.11 | |
rds-json-nginx-module | 0.15 | |
lua-cjson | 2.1.0.10 |
下载软件包
#jemalloc wget -c https://github.com/jemalloc/jemalloc/releases/download/5.3.0/jemalloc-5.3.0.tar.bz2 -O /export/softwares/jemalloc-5.3.0.tar.bz2 #luajit wget -c https://github.com/openresty/luajit2/archive/refs/tags/v2.1-20220411.tar.gz -O /export/softwares/luajit2-2.1-20220411.tar.bz2 #lua-nginx-module wget -c https://github.com/openresty/lua-nginx-module/archive/refs/tags/v0.10.21.tar.gz -O /export/softwares/lua-nginx-module-0.10.21.tar.gz #ngx_devel_kit wget -c https://github.com/vision5/ngx_devel_kit/archive/refs/tags/v0.3.1.tar.gz -O /export/softwares/ngx_devel_kit-v0.3.1.tar.gz #openssl wget -c --no-check-certificate https://www.openssl.org/source/openssl-1.1.1q.tar.gz -O /export/softwares/openssl-1.1.1q.tar.gz #pcre wget -c --no-check-certificate https://sourceforge.net/projects/pcre/files/pcre/8.45/pcre-8.45.tar.bz2/download -O /export/softwares/pcre-8.45.tar.bz2 #zlib wget -c http://www.zlib.net/zlib-1.2.12.tar.gz -O /export/softwares/zlib-1.2.12.tar.gz #tengine wget -c https://github.com/alibaba/tengine/archive/refs/tags/2.3.3.tar.gz -O /export/softwares/tengine-2.3.3.tar.gz #echo-nginx-module wget -c https://github.com/openresty/echo-nginx-module/archive/refs/tags/v0.62.tar.gz -O echo-nginx-module-0.62.tar.gz #lua-resty-core wget -c https://github.com/openresty/lua-resty-core/archive/refs/tags/v0.1.23.tar.gz -O /export/softwares/lua-resty-core-0.1.23.tar.gz #lua-resty-lrucache wget -c https://github.com/openresty/lua-resty-lrucache/archive/refs/tags/v0.13.tar.gz -O /export/softwares/lua-resty-lrucache-0.13.tar.gz #drizzle-nginx-module wget -c https://github.com/openresty/drizzle-nginx-module/archive/refs/tags/v0.1.11.tar.gz -O /export/softwares/drizzle-nginx-module-0.1.11.tar.gz #drizzle7 wget -c http://agentzh.org/misc/nginx/drizzle7-2011.07.21.tar.gz -O /export/softwares/drizzle7-2011.07.21.tar.gz #rds-json-nginx-module wget -c https://github.com/openresty/rds-json-nginx-module/archive/refs/tags/v0.15.tar.gz -O /export/softwares/rds-json-nginx-module-0.15.tar.gz
安装
tar -xf luajit2-2.1-20220411.tar.bz2 cd luajit2-2.1-20220411/ make install PREFIX=/usr/local/luajit export LUAJIT_LIB=/usr/local/luajit/lib #临时生效 export LUAJIT_INC=/usr/local/luajit/include/luajit-2.1 #临时生效 /usr/local/bin/luajit -v #查看版本 tar -xf jemalloc-5.3.0.tar.bz2 tar -xf openssl-1.1.1q.tar.gz tar -xf pcre-8.45.tar.bz2 tar -xf zlib-1.2.12.tar.gz tar -xf lua-nginx-module-0.10.21.tar.gz tar -xf ngx_devel_kit-v0.3.1.tar.gz tar -xf echo-nginx-module-0.62.tar.gz tar -xf drizzle-nginx-module-0.1.11.tar.gz tar -xf drizzle7-2011.07.21.tar.gz cd drizzle7-2011.07.21 ./configure --without-server make libdrizzle-1.0 make install-libdrizzle-1.0 tar -xf rds-json-nginx-module-0.15.tar.gz tar -xf tengine-2.3.3.tar.gz cd tengine-2.3.3 #=============执行安装编译=========================== ./configure \ --prefix=/export/servers/tengine \ --user=nginx \ --group=nginx \ --with-http_stub_status_module \ --with-http_ssl_module \ --with-pcre \ --with-stream \ --with-http_realip_module \ --with-jemalloc=/export/softwares/jemalloc-5.3.0/ \ --add-module=./modules/ngx_http_upstream_check_module/ \ --add-module=./modules/ngx_http_upstream_session_sticky_module \ --with-ld-opt="-Wl,-rpath,/usr/local/luajit/lib" \ --add-module=/export/softwares/ngx_devel_kit-0.3.1 \ --add-module=/export/softwares/lua-nginx-module-0.10.21 \ --add-module=/export/softwares/drizzle-nginx-module-0.1.11 \ --add-module=/export/softwares/rds-json-nginx-module-0.15 \ --add-dynamic-module=/export/softwares/echo-nginx-module-0.62 \ --with-openssl=/export/softwares/openssl-1.1.1q \ --with-pcre=/export/softwares/pcre-8.45 \ --with-zlib=/export/softwares/zlib-1.2.12 make -j16 make install export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH #临时生效 #创建nginx用户 useradd -s /sbin/nologin nginx #nginx-lua模块 tar -xf lua-resty-core-0.1.23.tar.gz -C /usr/local/src/ tar -xf lua-resty-lrucache-0.13.tar.gz -C /usr/local/src/ #修改nginx.conf cd /export/servers/tengine vi conf/nginx.conf # keepalive_timeout 65; 下面增加 # lua 包模块依赖路径 load_module /export/servers/tengine/modules/ngx_http_echo_module.so; lua_package_path '/usr/local/src/lua-resty-core-0.1.23/lib/?.lua;/usr/local/src/lua-resty-lrucache-0.13/lib/?.lua;'; upstream backend { drizzle_server 192.168.0.139:3307 dbname=${dbname} password=${password} user=${user} protocol=mysql; } #server下载增加 location /hello { default_type 'text/plain'; content_by_lua 'ngx.say("hello, lua")'; } location /mysql { set $my_sql 'SELECT * FROM sys_dept'; drizzle_query $my_sql; drizzle_pass backend; drizzle_connect_timeout 500ms; # default 60s drizzle_send_query_timeout 2s; # default 60s drizzle_recv_cols_timeout 1s; # default 60s drizzle_recv_rows_timeout 1s; # default 60s rds_json on; } ./sbin/nginx -t ./sbin/nginx #验证 curl 127.0.0.1/hello
其他可以增加lua中mysql redis kafka之类模块进行使用
使用cjson
wget -c https://github.com/openresty/lua-cjson/archive/refs/tags/2.1.0.10.tar.gz -o /usr/local/src/lua-cjson-2.1.0.10.tar.gz tar -xf lua-cjson-2.1.0.10.tar.gz cc -c -O3 -Wall -pedantic -DNDEBUG -I/usr/local/luajit/include/luajit-2.1/ -fpic -o lua_cjson.o lua_cjson.c make make install
json.lua
local cjson = require("cjson"); --数据响应类型JSON ngx.header.content_type="application/json;charset=utf8" --定义响应数据 local response = {} response["code"]=200 response["message"]="SUCCESS" ngx.say(cjson.encode(response))
location /json { content_by_lua_file lua/json.lua; }
评论暂时关闭