Research on the configuration and deployment of high-performance WEB server nginx (14) smooth upgrade of your nginx

Source: Internet
Author: User

1. Overview (skip Part 1)

Nginx helps us achieve smooth upgrade. The principle is as follows:

(1) Start a new process without stopping the old process.

(2) The old process is responsible for processing requests that are still not processed, but will not accept the requests.

(3) The new process accepts new requests.

(4) After the old process processes all requests and closes all connections, it stops.

This facilitates smooth upgrade. Generally, you need to upgrade nginx in two cases. One is to upgrade nginx, and the other is to add a new module for nginx.

2. Upgrade process

The specific operation is also very simple, as follows:

(0) view the current version

Enter:

./nginx -V

(1) download and compile the new nginx version.

wget nginx-1.0.11.tar.gztar zxvf nginx-1.0.11.tar.gzcd nginx-1.0.11./configure --add-module=/customized_module_0 --add-module=/customized_module_1make

Do not make install

(2) Back up executable files of earlier versions

cd /usr/local/nginx/sbinsudo cp nginx nginx.old

(3) modify the configuration file

Modify the configuration file if necessary.

(4) copy a new executable file

sudo cp /home/michael/tmp/nginx-1.0.11/objs/nginx /usr/local/nginx/sbin/

(5) Upgrade

cd /home/michael/tmp/nginx-1.0.11make upgrade

(6) Clear unnecessary files

rm -rf /home/michael/tmp/nginx-1.0.11

(7) view nginx version

cd /usr/local/nginx/sbin./nginx -V

3. Observe process changes

On my machine, we can see that I have configured 10 worker processes. After starting, we can see that:

root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  2 10:51 ?        00:00:00 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6251  6241  1 10:51 ?        00:00:00 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processnobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader processluming    6310 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginxnobody    7995 10419  0 Jan12 ?        00:20:37 nginx: worker process is shutting downnobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting downnobody    7998 10419  0 Jan12 ?        00:20:04 nginx: worker process is shutting downnobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting downroot     10419     1  0 Jan08 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

It can be seen that the new process has one master and ten workers, and one old master (as can be seen from time) and 4 workers (the other 6 old workers have completed all connections and shutdown ). There is also a loader process. In a few seconds, we can see that there are only two workers:

root      6241 10419  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  1 10:51 ?        00:00:00 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6251  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processnobody    6253  6241  0 10:51 ?        00:00:00 nginx: cache loader processluming    6430 25051  0 10:51 pts/1    00:00:00 grep --color=auto nginxnobody    7996 10419  0 Jan12 ?        00:20:11 nginx: worker process is shutting downnobody    8003 10419  0 Jan12 ?        00:20:12 nginx: worker process is shutting downroot     10419     1  0 Jan08 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginx

Let's take a short look:

root      6241     1  0 10:51 ?        00:00:00 nginx: master process /usr/local/nginx/sbin/nginxnobody    6242  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6243  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6244  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6245  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6246  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6247  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6248  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6249  6241  0 10:51 ?        00:00:00 nginx: worker process      nobody    6250  6241  0 10:51 ?        00:00:01 nginx: worker process      nobody    6251  6241  0 10:51 ?        00:00:02 nginx: worker process      nobody    6252  6241  0 10:51 ?        00:00:00 nginx: cache manager processluming    8680 25051  0 10:56 pts/1    00:00:00 grep --color=auto nginx

Congratulations! You can upgrade your nginx server gracefully.

-

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.