Nginx 1.8.0平滑升级至1.9.7版本详细步骤
首先确认当前环境运行的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
执行平滑升级的具体步骤如下:
获取Nginx 1.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
创建用于运行Nginx的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
至此,Nginx 1.8.0版本平滑升级至1.9.7版本的操作已完成,希望以上内容能对大家有所帮助!