[原创]CentOS7编译安装OpenResty1.15.8.2(填坑之旅)
admin
2023-03-02 01:21:50
0次

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

一、安装前置环境

1、编译工具安装

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

2、调整系统时区

date
timedatectl
sudo timedatectl set-timezone Asia/Shanghai
sudo 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 www
useradd -r -g www -s /sbin/nologin -M www
mkdir -pv /data/{src,local}/
mkdir -pv /data/logs/nginx
chown -R www:www /data/logs/nginx

3、下载相关软件和模块

cd /data/src
wget -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/src
tar -xzf nginx-http-flv-module-1.2.7.tar.gz
tar -xzf openresty-1.15.8.2.tar.gz
cd 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.7

gmake -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”就表明编译安装成功了。

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

5、校验

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

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

[root@node1 ~]# openresty -V
nginx version: openresty/1.15.8.2
built by gcc 8.3.0 (GCC) 
built with OpenSSL 1.0.2k-fips  26 Jan 2017
TLS SNI support enabled
configure 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.gz
http://zlib.net/zlib-1.2.11.tar.gz
https://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 -h
nginx version: openresty/1.15.8.2
Usage: 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 -tnl
sudo cp /usr/lib/firewalld/services/http.xml /etc/firewalld/services/
sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --reload

或关闭防火墙:

systemctl stop firewalld.service
ss -tnl

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

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

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

相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...