温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

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

发布时间:2020-04-08 14:30:24 来源:网络 阅读:3452 作者:卓格 栏目:系统运维

原创文章,转载请注明出处: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

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI