openresty1.15.8替换nginx1.14.2

openresty介绍

OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。

OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。

OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

openresty官方文档:https://openresty.org/cn/

1、原环境的nginx1.14.2

#指定pcre源码目录
cd /opt
yum -y install gcc-c++
wget https://sourceforge.net/projects/pcre/files/pcre/8.42/pcre-8.42.tar.gz
tar -zxf pcre-8.42.tar.gz

#安装nginx
wget http://nginx.org/download/nginx-1.14.2.tar.gz
tar -zxf nginx-1.14.2.tar.gz
cd nginx-1.14.2
./configure  --prefix=/opt/nginx --with-pcre=/opt/pcre-8.42
make && make install

# /opt/nginx/sbin/nginx -V
nginx version: nginx/1.14.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-23) (GCC) 
configure arguments: --prefix=/opt/nginx --with-pcre=/opt/pcre-8.42
# ps -ef | grep nginx
root       684     1  0 17:03 ?        00:00:00 nginx: master process /opt/nginx/sbin/nginx
nobody     685   684  0 17:03 ?        00:00:00 nginx: worker process   
root       687 12259  0 17:03 pts/0    00:00:00 grep nginx

2、下载openresty相关安装包:

https://openresty.org/package/centos/6/x86_64/

https://openresty.org/package/centos/6/x86_64/openresty-1.15.8.3-1.el6.x86_64.rpm
https://openresty.org/package/centos/6/x86_64/openresty-zlib-1.2.11-3.el6.x86_64.rpm
https://openresty.org/package/centos/6/x86_64/openresty-openssl-1.1.0l-1.el6.x86_64.rpm
https://openresty.org/package/centos/6/x86_64/openresty-pcre-8.44-1.el6.x86_64.rpm

3、安装openresty 1.15.8

yum localinstall ./* -y
#默认安装到了/usr/local/openresty
ln -s /usr/local/openresty /opt/openresty
#软链接到bin目录
ln -s /opt/openresty/bin/openresty /usr/bin/nginx

mv /opt/openresty/nginx/conf/nginx.conf{,.bak}
#将原有配置文件复制到openresty
cp /opt/nginx/conf/nginx.conf /opt/openresty/nginx/conf/

#启动脚本
cp /etc/init.d/openresty{,.bak}
vim /etc/init.d/openresty
:% s@usr\/local@opt@g

#加入开机自启动
chkconfig --add openresty

4、替换:关闭原有nginx进程,启动openresty

/opt/nginx/sbin/nginx -s stop
/opt/openresty/nginx/sbin/nginx -t
如果提示"nginx: [warn] the "ssl" directive is deprecated, use the "listen ... ssl"",原因是nginx1.15版本及以后已经不需要使用ssl on命令了,可以去掉。

service openresty start
# ps -ef | grep nginx
root       983     1  0 17:52 ?        00:00:00 nginx: master process /opt/openresty/nginx/sbin/nginx -c /opt/openresty/nginx/conf/nginx.conf
nobody     984   983  0 17:52 ?        00:00:00 nginx: worker process                                                        
root       987 12259  0 17:52 pts/0    00:00:00 grep nginx

/opt/openresty/nginx/sbin/nginx -c /opt/openresty/nginx/conf/nginx.conf
5、CentOS 7配置system启动nginx
$ cat /etc/systemd/system/nginx.service
[Unit]
Description=NGINX 
After=syslog.target network.target remote-fs.target nss-lookup.target

[Service]
Type=forking
User=opt
Group=opt
PIDFile=/opt/openresty/nginx/logs/nginx.pid
ExecStartPre=/opt/openresty/nginx/sbin/nginx -t
ExecStart=/opt/openresty/nginx/sbin/nginx
ExecReload=/opt/openresty/nginx/sbin/nginx -s reload
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

#启动的时候,使用普通用户启动
$ systemctl enable nginx
$ systemctl start nginx

猜你喜欢

转载自blog.csdn.net/change_can/article/details/107251781