技術文檔
Centos下Nginx版本如何平滑升級與回滾?nginx升級,nginx怎么升級?centos升級nginx
操作系統:CentOS 7.x
準備篇
一、防火墻配置
CentOS 7.x默認使用的是firewall作為防火墻,這里改為iptables防火墻。
1、關閉firewall:
systemctl stop firewalld.service #停止firewall
systemctl disable firewalld.service #禁止firewall開機啟動
systemctl mask firewalld
systemctl stop firewalld
yum remove firewalld
2、安裝iptables防火墻
yum install iptables-services #安裝
vi /etc/sysconfig/iptables #編輯防火墻配置文件
# sample configuration for iptables service
# you can edit this manually or use system-config-firewall
# please do not ask us to add additional ports/services to this default configuration
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 22 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 80 -j ACCEPT
-A INPUT -p tcp -m state --state NEW -m tcp --dport 443 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
:wq! #保存退出
systemctl restart iptables.service #最后重啟防火墻使配置生效
systemctl enable iptables.service #設置防火墻開機啟動
/usr/libexec/iptables/iptables.init restart #重啟防火墻
二、關閉SELINUX
vi /etc/selinux/config
#SELINUX=enforcing #注釋掉
#SELINUXTYPE=targeted #注釋掉
SELINUX=disabled #增加
:wq! #保存退出
setenforce 0 #使配置立即生效
三 、系統約定
軟件源代碼包存放位置:/usr/local/src
源碼包編譯安裝位置:/usr/local/軟件名字
四、下載軟件包
1、下載nginx
http://nginx.org/download/nginx-1.18.0.tar.gz
http://nginx.org/download/nginx-1.22.0.tar.gz
2、下載pcre(支持nginx偽靜態)
https://ftp.exim.org/pub/pcre/pcre-8.45.tar.gz
3、下載zlib(nginx擴展)
https://zlib.net/zlib-1.2.12.tar.gz
4、下載openssl(適用于nginx擴展https)
https://www.openssl.org/source/openssl-1.1.1q.tar.gz
5、下載ngx_cache_purge(nginx緩存模塊)
http://labs.frickle.com/files/ngx_cache_purge-2.3.tar.gz
以上軟件包上傳到/usr/local/src目錄
五、安裝編譯工具包
yum install make gcc gcc-c++ perl zlib-devel
安裝篇
一、安裝Nginx
1、安裝pcre
cd /usr/local/src
mkdir /usr/local/pcre
tar zxvf pcre-8.45.tar.gz
cd pcre-8.45
./configure --prefix=/usr/local/pcre
make
make install
2、安裝zlib
cd /usr/local/src
mkdir /usr/local/zlib
tar zxvf zlib-1.2.12.tar.gz
cd zlib-1.2.12
./configure --prefix=/usr/local/zlib
make
make install
3、安裝openssl
cd /usr/local/src
mkdir /usr/local/openssl
tar zxvf openssl-1.1.1q.tar.gz
cd openssl-1.1.1q
./config -fPIC shared zlib --prefix=/usr/local/openssl
make
make install
4、安裝Nginx
groupadd www
useradd -g www www -s /bin/false
cd /usr/local/src
tar zxvf ngx_cache_purge-2.3.tar.gz
tar zxvf nginx-1.18.0.tar.gz
cd nginx-1.18.0
./configure --prefix=/usr/local/nginx --user=www --group=www --without-http_memcached_module --with-http_stub_status_module --with-http_ssl_module --with-http_v2_module --with-http_gzip_static_module --with-http_realip_module --with-stream--with-openssl=/usr/local/src/openssl-1.1.1q --with-zlib=/usr/local/src/zlib-1.2.12 --with-pcre=/usr/local/src/pcre-8.45 --add-module=../ngx_cache_purge-2.3
注意:--with-openssl=/usr/local/src/openssl-1.1.1q --with-zlib=/usr/local/src/zlib-1.2.12 --with-pcre=/usr/local/src/pcre-8.45指向的是源碼包解壓的路徑,而不是安裝的路徑,否則會報錯。
make
make install
/usr/local/nginx/sbin/nginx #啟動Nginx
#查看nginx版本和安裝模塊信息
/usr/local/nginx/sbin/nginx -V
二、平滑升級nginx版本
1、備份舊版nginx
cp -r /usr/local/nginx /usr/local/nginx.bak
2、查看舊版編譯信息??????????????????????????