[原创]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

相关内容

热门资讯

20名“高考状元”选择学医!此... 2026年香港高考的24名“状元”中,有20人明确表示将留港攻读医科。多年来,香港最顶尖的“学霸们”...
“抢人大战”,风向有变? 各地一场“抢老人”的大战,已然徐徐拉开大幕。最近,有着人口净流出压力的吉林,计划拿出3亿元发展旅居康...
石家庄一家不限量的爱心素食面馆... 7月24日正午时分,记者来到位于石家庄市新华区东明家居西二环店北门旁的“素面”小店,不大的店面里坐满...
中材科技申请风电叶片外补强辅助... 国家知识产权局信息显示,中材科技(伊吾)风电叶片有限公司申请一项名为“风电叶片外补强辅助固化装置”的...
为人工智能治理提供重要公共产品 图为2026世界人工智能大会暨人工智能全球治理高级别会议举办期间,在世博展览馆灵心巧手展位,参观者观...
泽连斯基称俄对乌多地发动大规模... 当地时间25日,乌克兰总统泽连斯基通报称,俄军于当日凌晨对乌克兰多地发动大规模空袭,使用2枚导弹、近...
不怕没水!武汉科学家找到水稻身... 干旱来了,水稻启动"抗旱模式",可一启动就长不大、结得少——这是困扰育种界几十年的老难题。7月23日...
多款手机涨价超1000元,大存... 今年暑期消费旺季,国内智能手机市场迎来一轮显著的价格上调。第一财经记者走访深圳多家品牌门店发现,以v...
SpaceX上市后星舰首飞:首... 界面新闻实习记者 | 李响 在经历多次波折后,SpaceX公司的星舰(Starship)终于完成了...
博世洗衣机强制解锁 博世洗衣机强制解锁的方法可能因型号和具体情况而异。以下是一些常见的方法:1. 按住电源键:有些博世洗...