千家信息网

[原创]CentOS7编译安装OpenResty1.15.8.2(填坑之旅)

发表于:2025-12-02 作者:千家信息网编辑
千家信息网最后更新 2025年12月02日,原创文章,转载请注明出处:https://blog.51cto.com/indian/2445786一、安装前置环境1、编译工具安装yum install -y epel-releaseyum ins
千家信息网最后更新 2025年12月02日[原创]CentOS7编译安装OpenResty1.15.8.2(填坑之旅)

原创文章,转载请注明出处:https://blog.51cto.com/indian/2445786

一、安装前置环境

1、编译工具安装

yum install -y epel-releaseyum install -y gcc gcc-c++ curl

2、调整系统时区

datetimedatectlsudo timedatectl set-timezone Asia/Shanghaisudo dnf install -y chrony

3、其它自己需要的工具

yum install -y vim man tree screen wget bash-completion tcp_wrappers lrzsz

二、openresty编译安装

1、依赖库
您必须将这些库 perl 5.6.1+, libpcre, libssl安装在您的电脑之中。 对于 Linux来说, 您需要确认使用 ldconfig 命令,让其在您的系统环境路径中能找到它们。

yum install pcre-devel openssl-devel

2、设置专用用户和组及相关目录

groupadd wwwuseradd -r -g www -s /sbin/nologin -M wwwmkdir -pv /data/{src,local}/mkdir -pv /data/logs/nginxchown -R www:www /data/logs/nginx

3、下载相关软件和模块

cd /data/srcwget -c -P '/data/src/' 'https://github.com/winshining/nginx-http-flv-module/archive/v1.2.7.tar.gz' -O 'nginx-http-flv-module-1.2.7.tar.gz'wget -c -P '/data/src' 'https://openresty.org/download/openresty-1.15.8.2.tar.gz'

注意,不要用X宝的"echo-nginx-module"模块(坑之一),用了这个模块后编译出错,我就在这里踩坑了,折腾了好久。

4、开始安装

cd /data/srctar -xzf nginx-http-flv-module-1.2.7.tar.gztar -xzf openresty-1.15.8.2.tar.gzcd openresty-1.15.8.2/./configure \--prefix=/data/local/openresty-1.15.8.2 \--sbin-path=/usr/sbin/openresty \--user=www \--group=www \--with-luajit \--with-http_ssl_module \--with-http_iconv_module \--with-http_v2_module \--with-http_realip_module \--with-http_sub_module \--with-http_flv_module \--with-http_mp4_module \--with-http_gunzip_module \--with-http_gzip_static_module \--with-http_auth_request_module \--with-http_secure_link_module \--with-http_stub_status_module \--with-http_addition_module \--add-module=/data/src/nginx-http-flv-module-1.2.7gmake -j `grep processor /proc/cpuinfo | wc -l` && make install

nginx-http-flv-module 是流媒体模块,是"nginx-rtmp-module"模块的升级版。具体见我的另一篇笔记《[原创]openresty搭建流媒体》。
试着使用 ./configure --help 查看更多的选项。
配置文件(./configure script)运行出错可以到 build/nginx-VERSION/objs/autoconf.err 找到。 VERSION 的地方必须与OpenResty版本号相对应, 比如 0.8.54.6。
全程如果没有报错,最后出现"ln -sf /usr/sbin/openresty /data/local/openresty-1.15.8.2/bin/openresty"就表明编译安装成功了。

5、校验

[root@node1 ~]# openresty -vnginx version: openresty/1.15.8.2

6、安装成功后的编译参数

[root@node1 ~]# openresty -Vnginx version: openresty/1.15.8.2built by gcc 8.3.0 (GCC) built with OpenSSL 1.0.2k-fips  26 Jan 2017TLS SNI support enabledconfigure arguments: --prefix=/data/local/openresty-1.15.8.2/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.1rc1 --add-module=../iconv-nginx-module-0.14 --add-module=../echo-nginx-module-0.61 --add-module=../xss-nginx-module-0.06 --add-module=../ngx_coolkit-0.2 --add-module=../set-misc-nginx-module-0.32 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.08 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.15 --add-module=../ngx_lua_upstream-0.07 --add-module=../headers-more-nginx-module-0.33 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.19 --add-module=../redis2-nginx-module-0.15 --add-module=../redis-nginx-module-0.3.7 --add-module=../rds-json-nginx-module-0.15 --add-module=../rds-csv-nginx-module-0.09 --add-module=../ngx_stream_lua-0.0.7 --with-ld-opt=-Wl,-rpath,/data/local/openresty-1.15.8.2/luajit/lib --sbin-path=/usr/sbin/openresty --user=www --group=www --with-http_ssl_module --with-http_v2_module --with-http_realip_module --with-http_sub_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_auth_request_module --with-http_secure_link_module --with-http_stub_status_module --with-http_addition_module --add-module=/data/src/nginx-http-flv-module-1.2.7 --with-stream --with-stream_ssl_module --with-stream_ssl_preread_module[root@node1 ~]# 

注意问题:

1、编译参数问题
如果编译参数带下面这3个参数

--with-pcre=/data/src/pcre-8.43 \--with-zlib=/data/src/zlib-1.2.11 \--with-openssl=/data/src/openssl-1.1.1d \

这3个参数后面的路径,不是指它们的安装路径,而是下载对应的包,再解压后的路径。我就在这里踩坑N久(坑之二)。

包下载地址参考:

https://ftp.pcre.org/pub/pcre/pcre-8.43.tar.gzhttp://zlib.net/zlib-1.2.11.tar.gzhttps://www.openssl.org/source/openssl-1.1.1d.tar.gz

如果不加这3个参数,编译时会自动调用系统库,前提是yum安装了着3个软件的devel包(见前面)。如果在make时出现下列信息,就表明调用成功,否则要安装它们的库文件。

Configuration summary  + using system PCRE library  + using system OpenSSL library  + using system zlib library

三、启动

shell> ss -tnl      #查看启动的端口shell> openresty    #启动shell> ss -tnl      #查看openresty开放的端口是否启动shell> openresty -s stop    #停止shell> openresty -s reload   #重载shell> openresty -t   #语法检查

openresty 命令帮助,与nginx用法类似,可以加 "-c"调用配置文件

[root@node1 openresty-1.15.8.2]# openresty -hnginx version: openresty/1.15.8.2Usage: nginx [-?hvVtTq] [-s signal] [-c filename] [-p prefix] [-g directives]Options:  -?,-h         : this help  -v            : show version and exit  -V            : show version and configure options then exit  -t            : test configuration and exit  -T            : test configuration, dump it and exit  -q            : suppress non-error messages during configuration testing  -s signal     : send signal to a master process: stop, quit, reopen, reload  -p prefix     : set prefix path (default: /data/local/openresty-1.15.8.2/nginx/)  -c filename   : set configuration file (default: conf/nginx.conf)  -g directives : set global directives out of configuration file[root@node1 openresty-1.15.8.2]# openresty

四、测试
浏览器输入:http://你测试机器IP/
如果浏览器没有显示,放行防火墙端口:

sudo ss -tnlsudo cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/sudo firewall-cmd --permanent --zone=public --add-service=httpsudo firewall-cmd --reload

或关闭防火墙:

systemctl stop firewalld.servicess -tnl

如果觉得本文对你有帮助,请给我点攒或回应评论,谢谢!

英文版:https://github.com/openresty/openresty/issues/551

原创文章,转载请注明出处:https://blog.51cto.com/indian/2445786

编译 参数 模块 路径 成功 端口 系统 出处 原创文章 命令 工具 文件 文章 流媒 流媒体 浏览器 环境 软件 问题 防火墙 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 生物信息学软件开发算法 数据库可视化管理app 自己搭建免流量服务器 衡水app软件开发服务 超大铃声软件开发 专业做架构的软件开发 网络安全红海市场 ec服务器需要正版账号吗 网络安全专业中科院考研好考吗 最混乱的服务器解说合集 海康流媒体服务器管理地址 excel如何使用数据库 河北华为服务器hba卡 用户网络安全现状调研模板 软件开发环境管理制度 网络安全软件应用介绍 手机怎么更换信息服务器 贵州省网络安全与信息化协会 服务器未响应怎么修改适配器 华为云服务器无法输入代码 网络安全代理公司 杨浦网络技术公司 计算机网络技术应用的未来 软件开发找工作需要学历 服务器不能登陆软件怎么办 方舟服务器家养龙打不到野生恐龙 网络安全费用不低于5% 对网络安全行业的看法 中安网络安全培训靠谱吗 南京微商城软件开发
0