安装指定版本openresty-nginx

Posted 日暮西山

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了安装指定版本openresty-nginx相关的知识,希望对你有一定的参考价值。

OpenResty介绍

以下介绍内容引用于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

随手整理了安装过程,提供各位看官参考。

如有错漏,烦劳指出,谢谢!
如有侵权,烦劳告知,跪谢!


系统适用范围

使用范围:centos类操作系统 \\ redhat操作系统


安装过程1-系统环境检查

查看操作系统版本
[root@10-13-135-162 ~]# cat /etc/system-release
CentOS Linux release 7.9.2009 (Core)

[root@10-13-135-162 ~]# uname -a
Linux 10-13-135-162 4.19.188-10.el7.ucloud.x86_64 #1 SMP Wed Apr 28 09:54:38 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux


查看系统用户为root
[root@10-13-135-162 ~]# id
uid=0(root) gid=0(root) groups=0(root)

确认服务器能上网
[root@10-13-135-162 ~]# ping -c2 baidu.com
PING baidu.com (220.181.38.148) 56(84) bytes of data.
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=1 ttl=48 time=40.7 ms
64 bytes from 220.181.38.148 (220.181.38.148): icmp_seq=2 ttl=48 time=40.6 ms

--- baidu.com ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1001ms
rtt min/avg/max/mdev = 40.665/40.712/40.759/0.047 ms



安装过程2-OpenResty配置yum源

OpenResty配置源
[root@10-13-135-162 ~]# yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo

清空操作系统yum离线缓存
[root@10-13-135-162 ~]# yum clean all

更新操作系统yum离线缓存
[root@10-13-135-162 ~] yum makecache


官方安装介绍看这里===> ​​OpenResty 官方Linux包安装页​


安装过程3-OpenResty支持yum版本

查看OpenResty可以安装的yum版本
[root@10-13-135-162 ~]# yum list openresty --showduplicates
Loaded plugins: fastestmirror, langpacks, versionlock
Loading mirror speeds from cached hostfile
Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
Installed Packages
openresty.x86_64 1.19.3.1-1.el7 @openresty
Available Packages
openresty.x86_64 1.17.8.1-1.el7 openresty
openresty.x86_64 1.17.8.2-1.el7 openresty
openresty.x86_64 1.19.3.1-1.el7 openresty
openresty.x86_64 1.19.3.2-1.el7 openresty
openresty.x86_64 1.19.9.1-1.el7 openresty

安装指定版本OpenResty
[root@10-13-135-162 ~]# yum install -y openresty-1.19.3.1-1.el7
语法格式: yum install -y openresty-[xx版本].[xx操作系统]


OpenResty安装后效果-yum检查
[root@10-13-135-162 tmp]# yum info openresty-1.19.3.1-1.el7
Loaded plugins: fastestmirror, langpacks, versionlock
Loading mirror speeds from cached hostfile
Excluding 1 update due to versionlock (use "yum versionlock status" to show it)
Installed Packages
Name : openresty
Arch : x86_64
Version : 1.19.3.1
Release : 1.el7
Size : 3.4 M
Repo : installed
From repo : openresty
Summary : OpenResty, scalable web platform by extending nginx with Lua
URL : https://openresty.org/
License : BSD
Description : This package contains the core server for OpenResty. Built for production
: uses.
:
: OpenResty is a full-fledged web platform by integrating the standard Nginx
: core, LuaJIT, many carefully written Lua libraries, lots of high quality
: 3rd-party Nginx modules, and most of their external dependencies. It is
: designed to help developers easily build scalable web applications, web
: services, and dynamic web gateways.
:
: By taking advantage of various well-designed Nginx modules (most of which
: are developed by the OpenResty team themselves), OpenResty effectively
: turns the nginx server into a powerful web app server, in which the web
: developers can use the Lua programming language to script various existing
: nginx C modules and Lua modules and construct extremely high-performance
: web applications that are capable to handle 10K ~ 1000K+ connections in
: a single box.


OpenResty安装后效果-rpm检查
[root@10-13-135-162 ~]# rpm -qa|grep -Ei "openresty"
openresty-pcre-8.44-1.el7.x86_64
openresty-openssl111-1.1.1l-1.el7.x86_64
openresty-1.19.3.1-1.el7.x86_64
openresty-zlib-1.2.11-3.el7.centos.x86_64



安装过程4-OpenResty日志自动轮转压缩

设置OpenResty的日志自动轮转压缩 -- (不设置服务器磁盘空间就用没的)
[root@10-13-135-162 ~]# cat /etc/logrotate.d/nginx
/var/log/nginx/*.log
daily
missingok
rotate 52
compress
delaycompress
notifempty
create 640 nginx nginx
sharedscripts
postrotate
if [ -f /usr/local/openresty/nginx/logs/nginx.pid ]; then
kill -USR1 `cat /usr/local/openresty/nginx/logs/nginx.pid`
fi
endscript





安装过程5-OpenResty启动与开机启动

这里的systemctl命令是内核3.0以上版本才有,我所用操作系统为centos7


设置启动加载 (为了让进程在查看的时候,更美观,个人喜好)

设置启动加载 - 修改前
[root@10-13-135-162 ~]# cat /usr/lib/systemd/system/openresty.service
[Unit]
Description=The OpenResty Application Platform
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx
ExecStart=/usr/local/openresty/nginx/sbin/nginx
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

设置启动加载 - 修改后
[root@10-13-135-162 ~]# vim /usr/lib/systemd/system/openresty.service
[Unit]
Description=The OpenResty Application Platform
After=syslog.target network-online.target remote-fs.target nss-lookup.target
Wants=network-online.target

[Service]
Type=forking
PIDFile=/usr/local/openresty/nginx/logs/nginx.pid
ExecStartPre=/usr/local/openresty/nginx/sbin/nginx -t -c /usr/local/openresty/nginx/conf/nginx.conf
ExecStart=/usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID
PrivateTmp=true

[Install]
WantedBy=multi-user.target

====

启动OpenResty
[root@10-13-135-162 ~]# systemctl start openresty

设置开机自动启动
[root@10-13-135-162 ~]# systemctl enable openresty


查看启动状态与开机状态 (如下附图)
[root@10-13-135-162 ~]# systemctl status openresty
● openresty.service - The OpenResty Application Platform
Loaded: loaded (/usr/lib/systemd/system/openresty.service; enabled; vendor preset: disabled)
Active: active (running) since Tue 2021-12-21 22:05:20 CST; 2 days ago
Main PID: 17962 (nginx)
Tasks: 5
Memory: 89.5M
CGroup: /system.slice/openresty.service
├─17962 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
├─19649 nginx: worker process
├─19650 nginx: worker process
├─19651 nginx: worker process
└─19652 nginx: worker process

Dec 21 22:05:20 10-13-135-162 systemd[1]: Starting The OpenResty Application Platform...
Dec 21 22:05:20 10-13-135-162 nginx[17958]: nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
Dec 21 22:05:20 10-13-135-162 nginx[17958]: nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
Dec 21 22:05:20 10-13-135-162 systemd[1]: Started The OpenResty Application Platform.


查看启动状态
[root@10-13-135-162 ~]# ps aux |grep nginx
root 17962 0.0 0.1 35752 9040 ? Ss Dec21 0:00 nginx: master process /usr/local/openresty/nginx/sbin/nginx -c /usr/local/openresty/nginx/conf/nginx.conf
nobody 19649 0.0 0.3 58644 26420 ? S 17:29 0:01 nginx: worker process
nobody 19650 0.0 0.3 58644 26436 ? S 17:29 0:00 nginx: worker process
nobody 19651 0.0 0.3 58644 26500 ? S 17:29 0:00 nginx: worker process
nobody 19652 0.0 0.3 58644 26500 ? S 17:29 0:00 nginx: worker process

安装指定版本openresty-nginx_centos安装openresty



yum语法引用补充

[root@10-13-135-162 ~ ]# yum --help
Loaded plugins: fastestmirror, langpacks, versionlock
Usage: yum [options] COMMAND

List of Commands:
clean Remove cached data
makecache Generate the metadata cache
install Install a package or packages on your system


Options:
--showduplicates show duplicates, in repos, in list/search commands
-y, --assumeyes answer yes for all questions


以上是关于安装指定版本openresty-nginx的主要内容,如果未能解决你的问题,请参考以下文章

续:纠正:ubuntu7.04可以安装,而且完美的安装 ! for《Oracle-10.2.0.1,打补丁10.2.0.5:在 debian 版本4不含4以上,及 ubuntu 7.04不含(代码片段

nodejs常用代码片段

安装 BlueJeans 会议 API 客户端时出现“pipenv 需要 #egg 片段以获取版本控制的依赖项”警告

如何管理在每个 git 版本中添加私有代码片段?

ubuntu 14.04怎么安装指定版本的svn

pip 查看已安装模块卸载指定模块安装指定版本模块