一、查看系统环境
# cat /etc/redhat-release
CentOS release 6.7 (Final)
# uname -r
2.6.32-573.el6.x86_64
# uname -m
x86_64
二、编译安装nginx-1.8.1.tar.gz
1、安装编译器及相关工具
# yum install gcc gcc-c++ autoconf automake -y
2、安装模块依赖的库
# yum install zlib-devel openssl-devel pcre-devel -y
3、创建Nginx管理用户
# useradd -s /sbin/nologin -M nginx
4、下载nginx-1.8.1.tar.gz
# wget http://nginx.org/download/nginx-1.8.1.tar.gz
5、解压并编译安装
# tar zxf nginx-1.8.1.tar.gz
# cd nginx-1.8.1
# ./configure \
--prefix=/application/nginx-1.8.1 \
--user=nginx \
--group=nginx \
--with-http_ssl_module
# make && make install
# ln -s /application/nginx-1.8.1/ /application/nginx
# cd ../
6、启动Nginx
# /application/nginx/sbin/nginx -t
nginx: the configuration file /application/nginx-1.8.1/conf/nginx.conf syntax is ok
nginx: configuration file /application/nginx-1.8.1/conf/nginx.conf test is successful
# /application/nginx/sbin/nginx
# ss -lntup|grep nginx
tcp LISTEN 0 511 *:80 *:* users:(("nginx",3597,6),("nginx",3598,6))
# ps -ef|grep nginx|grep -v grep
root 3597 1 0 23:41 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 3598 3597 0 23:41 ? 00:00:00 nginx: worker process
# ls /application/nginx/logs/
access.log error.log nginx.pid
三、平滑升级nginx-1.10.1.tar.gz
1、备份旧的可执行文件
# cp /application/nginx/sbin/nginx /application/nginx/sbin/nginx.old
2、下载nginx-1.10.1.tar.gz
# wget http://nginx.org/download/nginx-1.10.1.tar.gz
3、解压并按照旧的安装目录编译安装新的程序
# tar zxf nginx-1.10.1.tar.gz
# cd nginx-1.10.1
# ./configure \
--prefix=/application/nginx-1.8.1 \
--user=nginx \
--group=nginx \
--with-http_ssl_module
# make && make install
# cd
4、平滑升级可执行程序,旧的.pid文件重命名.pid.oldbin
# kill -USR2 3597
# ls /application/nginx/logs/
access.log error.log nginx.pid nginx.pid.oldbin
5、重新执行可执行文件,依次启动新的主进程和工作进程
# /application/nginx/sbin/nginx
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:80 failed (98: Address already in use)
nginx: [emerg] still could not bind()
# ps -ef|grep nginx|grep -v grep
root 3597 1 0 23:41 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 3598 3597 0 23:41 ? 00:00:00 nginx: worker process
root 6022 3597 0 23:45 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 6023 6022 0 23:45 ? 00:00:00 nginx: worker process
6、从容关闭旧的工作进程
# kill -WINCH 3597
# ps -ef|grep nginx|grep -v grep
root 3597 1 0 23:41 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
root 6022 3597 0 23:45 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 6023 6022 0 23:45 ? 00:00:00 nginx: worker process
7、此时,可以决定是还原旧的版本,还是继续升级
1)若继续升级,则从容关闭旧的主进程
# kill -QUIT 3597
# ps -ef|grep nginx|grep -v grep
root 6022 1 0 23:45 ? 00:00:00 nginx: master process /application/nginx/sbin/nginx
nginx 6023 6022 0 23:45 ? 00:00:00 nginx: worker process
# ls /application/nginx/logs/
access.log error.log nginx.pid
2)若想退回老版本,则
kill -HUP 旧的主进程号:Nginx将在不重载配置文件的情况下启动它的工作进程;
kill -QUIT 新的主进程号:从容关闭其工作进程;
新的主进程退出后,旧的主进程会移除 .oldbin 前缀,恢复为 .pid 文件,这样,一切就都恢复到升级之前了。