原文:http://www.jb51.net/article/79878.htm
首先查看現在環境nginx的版本為1.8.0 編譯的參數只指定了安裝路徑;
[root@localhost sbin]# ./nginx -V
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC)
configure arguments: --prefix=/usr/local/nginx
平滑升級步驟如下:
下載nginx1.9.7版本,解壓並進入解壓后的目錄
[root@localhost ~]# wget -P /usr/local/src/ http://nginx.org/download/nginx-1.9.7.tar.gz
[root@localhost ~]# cd /usr/local/src/
[root@localhost src]# tar -zxvf nginx-1.9.7.tar.gz
[root@localhost src]# cd nginx-1.9.7
編譯安裝之前查看nginx進程ID信息:
[root@localhost nginx-1.9.7]# ps -ef |grep nginx
root 894 1 0 16:06 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 896 894 0 16:06 ? 00:00:00 nginx: worker process
nobody 897 894 0 16:06 ? 00:00:00 nginx: worker process
編譯安裝:指定用戶www 支持ssl 支持pcre 支持狀態查詢 支持靜態壓縮模塊;
[root@localhost nginx-1.9.7]# ./configure --user=www --group=www --prefix=/usr/local/nginx/ --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
編譯安裝后可以echo $?查看是否成功,成功后只需要執行make,不需要make install;
[root@localhost nginx-1.9.7]# make
平滑升級,先移走現有的nginx二進制文件
[root@localhost nginx-1.9.7]# mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
拷貝新生成的nginx二進制文件到指定目錄
[root@localhost nginx-1.9.7]# cp objs/nginx /usr/local/nginx/sbin/
執行升級命令
[root@localhost nginx-1.9.7]# make upgrade
/usr/local/nginx//sbin/nginx -t
nginx: the configuration file /usr/local/nginx//conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx//conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx//logs/nginx.pid`
sleep 1
test -f /usr/local/nginx//logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx//logs/nginx.pid.oldbin`
查看版本,發現已經是1.9.7版本,編譯的參數也存在;
[root@localhost nginx-1.9.7]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.9.7
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --user=www --group=www --prefix=/usr/local/nginx/ --with-pcre --with-http_stub_status_module --with-http_ssl_module --with-http_gzip_static_module
創建www用戶
[root@localhost nginx-1.9.7]# useradd -s /sbin/nologin -M www
查看nginx進程 PID已經更改
[root@localhost sbin]# ps -ef |grep nginx
root 3814 1 0 16:23 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
nobody 3815 3814 0 16:23 ? 00:00:00 nginx: worker process
nobody 3816 3814 0 16:23 ? 00:00:00 nginx: worker process
修改nginx.conf配置文件,更改用戶和用戶組為www用戶,保存退出,重啟nginx服務;
[root@localhost conf]# ps -ef |grep nginx
root 3814 1 0 16:23 ? 00:00:00 nginx: master process /usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/nginx.conf
www 4200 3814 0 16:48 ? 00:00:00 nginx: worker process
www 4201 3814 0 16:48 ? 00:00:00 nginx: worker process
Nginx1.8.0版本平滑升級新版本1.9.7就給大家介紹到這里,希望對大家有所幫助!