Smooth upgrade of Nginx

1. Check the system environment

# cat /etc/redhat-release
CentOS release 6.7 (Final)
# uname -r
2.6.32-573.el6.x86_64
# uname -m
x86_64

 

Second, compile and install nginx-1.8.1.tar.gz

1. Install the compiler and related tools

# yum install gcc gcc-c++ autoconf automake -y

 

2. Install the library that the module depends on

# yum install zlib-devel openssl-devel pcre-devel -y

 

3. Create Nginx management user

# useradd -s /sbin/nologin -M nginx

 

4. Download nginx-1.8.1.tar.gz

# wget http://nginx.org/download/nginx-1.8.1.tar.gz

 

5. Unzip and compile and install

# 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. Start 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

 

3. Smooth upgrade of nginx-1.10.1.tar.gz

1. Backup old executables

# cp /application/nginx/sbin/nginx /application/nginx/sbin/nginx.old

 

2. Download nginx-1.10.1.tar.gz

# wget http://nginx.org/download/nginx-1.10.1.tar.gz

 

3. Unzip and compile and install the new program according to the old installation directory

# 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. Smoothly upgrade executable programs, rename old .pid files to .pid.oldbin

# kill -USR2 3597

# ls /application/nginx/logs/
access.log  error.log  nginx.pid  nginx.pid.oldbin

 

5. Re-execute the executable file and start the new main process and worker process in turn

# /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. Gracefully shut down old worker processes

# 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. At this point, you can decide whether to restore the old version or continue to upgrade

1) If you continue to upgrade, calmly shut down the old main process

# 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) If you want to return to the old version, then

kill -HUP old main process number: Nginx will start its worker process without reloading the configuration file;
kill -QUIT new main process number: gracefully shut down its worker process;

After the new master process exits, the old master process removes the .oldbin prefix and reverts to a .pid file, so that everything is back to before the upgrade.

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326565711&siteId=291194637