部署openresty遇到的一些坑

您所在的位置:网站首页 workfor中文翻译 部署openresty遇到的一些坑

部署openresty遇到的一些坑

2023-12-31 03:50| 来源: 网络整理| 查看: 265

最近,遇到一个问题,就是我们CMS系统制作的产品页面和产品列表页面,发布到nginx服务器上,因为业务要求,客户看到的链接必须是短链接,当前的做法就是在nginx的配置中通过rewrite的方式做的。这个是静态的做法,当业务要修改短链接或者有新产品发布的话,就存在问题,要运维人员去修改nginx的配置文件,若这个运维忘记了或者改错了,或者业务运营人员找不到运维人员,会是什么效果?404呗。

 

针对这个问题,我希望通过lua+nginx+redis的方式,动态的加载这些链接的映射关系。

 

openresty对lua以及nginx的诸多模块都有很好的封装,所以,我就要自己在测试环境下尝试下,基于openresty的lua功能,首先就是部署openresty。

 

1. 下载openresty。从官网下载最新的版本。本博文案例用到的是openresty-1.11.2.2.tar.gz。

    解压缩,首先,因为openresty(确切的说,是nginx)依赖pcre做正则引擎,还有要用openssl做安全引擎。所以,先要安装pcre和openssl。千万注意,要用源码,在安装openresty的时候,通过--with-指定源码路径。

1 [root@localhost openresty-1.11.2.2]# ./configure --prefix=/usr/local/openresty --with-pcre=/opt/pcre2-10.23 --with-openssl=/opt/openssl-1.1.0e 2 。。。。。。。 3 Configuration summary 4 + using PCRE library: /opt/pcre2-10.23 5 + using OpenSSL library: /opt/openssl-1.1.0e 6 + using system zlib library 7 8 nginx path prefix: "/usr/local/openresty/nginx" 9 nginx binary file: "/usr/local/openresty/nginx/sbin/nginx" 10 nginx modules path: "/usr/local/openresty/nginx/modules" 11 nginx configuration prefix: "/usr/local/openresty/nginx/conf" 12 nginx configuration file: "/usr/local/openresty/nginx/conf/nginx.conf" 13 nginx pid file: "/usr/local/openresty/nginx/logs/nginx.pid" 14 nginx error log file: "/usr/local/openresty/nginx/logs/error.log" 15 nginx http access log file: "/usr/local/openresty/nginx/logs/access.log" 16 nginx http client request body temporary files: "client_body_temp" 17 nginx http proxy temporary files: "proxy_temp" 18 nginx http fastcgi temporary files: "fastcgi_temp" 19 nginx http uwsgi temporary files: "uwsgi_temp" 20 nginx http scgi temporary files: "scgi_temp" 21 22 cd ../.. 23 Type the following commands to build and install: 24 gmake 25 gmake install

上面日志中可以看出来,我的pcre和openssl的版本。pcre是pcre2-10.23,openssl的版本是openssl-1.1.0e。

 

这时看上去一切ok,没问题,可以依据提示信息,执行gmake了。

 

2. 执行gmake

。。。。。。。。。。。。。。。install apps/openssl -> /opt/openssl-1.1.0e/.openssl/bin/openssl install ./tools/c_rehash -> /opt/openssl-1.1.0e/.openssl/bin/c_rehash gmake[3]: 离开目录“/opt/openssl-1.1.0e” cc -c -I/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1 -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='"/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='"/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so"' -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_devel_kit-0.3.0/objs -I objs/addon/ndk -I ../ngx_lua-0.10.7/src/api -I /opt/pcre2-10.23 -I /opt/openssl-1.1.0e/.openssl/include -I objs \ -o objs/src/core/nginx.o \ src/core/nginx.c In file included from src/core/ngx_core.h:72:0, from src/core/nginx.c:9: src/core/ngx_regex.h:15:18: 致命错误:pcre.h:没有那个文件或目录 #include ^ 编译中断。 gmake[2]: *** [objs/src/core/nginx.o] 错误 1 gmake[2]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake[1]: *** [build] 错误 2 gmake[1]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake: *** [all] 错误 2

gmake有问题,如上红色的错误显示,找不到pcre.h,我到/opt/pcre2-10.23/src下面看,的确没有这个文件,莫非是版本的问题?我果断的更换了一个pcre的版本,没有用pcre2,选择的是pcre-8.40.再次configure并gmake。

。。。。。。。。。。。。。。。 -o objs/src/os/unix/ngx_linux_sendfile_chain.o \ src/os/unix/ngx_linux_sendfile_chain.c cc -c -I/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/include/luajit-2.1 -pipe -O -W -Wall -Wpointer-arith -Wno-unused-parameter -g -O2 -DNDK_SET_VAR -DNDK_UPSTREAM_LIST -DNDK_SET_VAR -DNDK_SET_VAR -DNDK_SET_VAR -DLUA_DEFAULT_PATH='"/usr/local/openresty/site/lualib/?.lua;/usr/local/openresty/site/lualib/?/init.lua;/usr/local/openresty/lualib/?.lua;/usr/local/openresty/lualib/?/init.lua"' -DLUA_DEFAULT_CPATH='"/usr/local/openresty/site/lualib/?.so;/usr/local/openresty/lualib/?.so"' -DNDK_SET_VAR -I src/core -I src/event -I src/event/modules -I src/os/unix -I ../ngx_devel_kit-0.3.0/objs -I objs/addon/ndk -I ../ngx_lua-0.10.7/src/api -I /opt/pcre-8.40 -I /opt/openssl-1.1.0e/.openssl/include -I objs \ -o objs/src/event/ngx_event_openssl.o \ src/event/ngx_event_openssl.c src/event/ngx_event_openssl.c: 在函数‘ngx_ssl_connection_error’中: src/event/ngx_event_openssl.c:2048:21: 错误:‘SSL_R_NO_CIPHERS_PASSED’未声明(在此函数内第一次使用) || n == SSL_R_NO_CIPHERS_PASSED /* 182 */ ^ src/event/ngx_event_openssl.c:2048:21: 附注:每个未声明的标识符在其出现的函数内只报告一次 gmake[2]: *** [objs/src/event/ngx_event_openssl.o] 错误 1 gmake[2]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake[1]: *** [build] 错误 2 gmake[1]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake: *** [all] 错误 2

这次看来,没有pcre的那个头文件找不到的问题了,走的更远一步了,这次报错是openssl有问题,这个就不是那么简单好查看了,去网络上查看吧,找到原因,是因为openssl的API改动很大,对应openresty的使用,我选择了老版本的openssl,将当前的1.1.0e版本的改成1.0.1u的了。再次configure并gamke。

。。。。。。。。。。。。。objs/addon/src/ngx_http_rds_csv_output.o \ objs/ngx_modules.o \ -L/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-E -ldl -lpthread -lcrypt -L/opt/openresty-1.11.2.2/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl /opt/pcre-8.40/.libs/libpcre.a /opt/openssl-1.0.1u/.openssl/lib/libssl.a /opt/openssl-1.0.1u/.openssl/lib/libcrypto.a -ldl -lz \ -Wl,-E sed -e "s|%%PREFIX%%|/usr/local/openresty/nginx|" \ -e "s|%%PID_PATH%%|/usr/local/openresty/nginx/logs/nginx.pid|" \ -e "s|%%CONF_PATH%%|/usr/local/openresty/nginx/conf/nginx.conf|" \ -e "s|%%ERROR_LOG_PATH%%|/usr/local/openresty/nginx/logs/error.log|" \ < docs/man/nginx.8 > objs/nginx.8 gmake[2]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake[1]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2”

这次,没有openssl的问题了。gmake的过程ok。

 

3. gmake install

。。。。。。。。。。 gmake[1]: 进入目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake -f objs/Makefile install gmake[2]: 进入目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” test -d '/usr/local/openresty/nginx' || mkdir -p '/usr/local/openresty/nginx' test -d '/usr/local/openresty/nginx/sbin' \ || mkdir -p '/usr/local/openresty/nginx/sbin' test ! -f '/usr/local/openresty/nginx/sbin/nginx' \ || mv '/usr/local/openresty/nginx/sbin/nginx' \ '/usr/local/openresty/nginx/sbin/nginx.old' cp objs/nginx '/usr/local/openresty/nginx/sbin/nginx' test -d '/usr/local/openresty/nginx/conf' \ || mkdir -p '/usr/local/openresty/nginx/conf' cp conf/koi-win '/usr/local/openresty/nginx/conf' cp conf/koi-utf '/usr/local/openresty/nginx/conf' cp conf/win-utf '/usr/local/openresty/nginx/conf' test -f '/usr/local/openresty/nginx/conf/mime.types' \ || cp conf/mime.types '/usr/local/openresty/nginx/conf' cp conf/mime.types '/usr/local/openresty/nginx/conf/mime.types.default' test -f '/usr/local/openresty/nginx/conf/fastcgi_params' \ || cp conf/fastcgi_params '/usr/local/openresty/nginx/conf' cp conf/fastcgi_params \ '/usr/local/openresty/nginx/conf/fastcgi_params.default' test -f '/usr/local/openresty/nginx/conf/fastcgi.conf' \ || cp conf/fastcgi.conf '/usr/local/openresty/nginx/conf' cp conf/fastcgi.conf '/usr/local/openresty/nginx/conf/fastcgi.conf.default' test -f '/usr/local/openresty/nginx/conf/uwsgi_params' \ || cp conf/uwsgi_params '/usr/local/openresty/nginx/conf' cp conf/uwsgi_params \ '/usr/local/openresty/nginx/conf/uwsgi_params.default' test -f '/usr/local/openresty/nginx/conf/scgi_params' \ || cp conf/scgi_params '/usr/local/openresty/nginx/conf' cp conf/scgi_params \ '/usr/local/openresty/nginx/conf/scgi_params.default' test -f '/usr/local/openresty/nginx/conf/nginx.conf' \ || cp conf/nginx.conf '/usr/local/openresty/nginx/conf/nginx.conf' cp conf/nginx.conf '/usr/local/openresty/nginx/conf/nginx.conf.default' test -d '/usr/local/openresty/nginx/logs' \ || mkdir -p '/usr/local/openresty/nginx/logs' test -d '/usr/local/openresty/nginx/logs' \ || mkdir -p '/usr/local/openresty/nginx/logs' test -d '/usr/local/openresty/nginx/html' \ || cp -R docs/html '/usr/local/openresty/nginx' test -d '/usr/local/openresty/nginx/logs' \ || mkdir -p '/usr/local/openresty/nginx/logs' gmake[2]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” gmake[1]: 离开目录“/opt/openresty-1.11.2.2/build/nginx-1.11.2” mkdir -p /usr/local/openresty/site/lualib /usr/local/openresty/site/pod /usr/local/openresty/site/manifest ln -sf /usr/local/openresty/nginx/sbin/nginx /usr/local/openresty/bin/openresty

这么看来,openresty安装部署完毕,是不是要检查一下,openresty能否启用呢?先查看下openresty的文件目录结构,如下,含有lua的组件,测试lua,后续就靠它了。

[root@localhost openresty]# ll 总用量 176 drwxr-xr-x. 2 root root 4096 3月 8 13:20 bin drwxr-xr-x. 6 root root 52 3月 8 12:08 luajit drwxr-xr-x. 6 root root 65 3月 8 13:20 lualib drwxr-xr-x. 11 root root 4096 3月 8 12:42 nginx drwxr-xr-x. 43 root root 4096 3月 8 12:08 pod -rw-r--r--. 1 root root 165176 3月 8 13:20 resty.index drwxr-xr-x. 5 root root 44 3月 8 12:08 site

 

4.验证openresty是否安装成功

[root@localhost sbin]# pwd /usr/local/openresty/nginx/sbin [root@localhost sbin]# ./nginx nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use) nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)

报错,地址被占用了,看到这个第一时间想到的是这个机器上安装了基本版的nginx,于是乎,将openresty的nginx配置文件中listen的端口修改一下,不用默认的80,改成8090.重新启动nginx。这次没有地址被占用的错误了。在地址栏输入地址http://localhost:8090, 看到下面的内容,OK,部署完毕!

 

 

到此,openresty部署完毕,总结一下,这里的坑无外乎两点:

1》 openresty需要的pcre插件,不能用pcre2来代替。

2》 openssl的版本更替中,API的改动非常大,版本兼容有问题,openresty需要的openssl版本,一定要匹配。

解除上面两个坑之后,我的部署其实变成了openresty-1.11.2.2 + pcre-8.40 + openssl-1.0.1u。

 



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3