Research on the configuration and deployment of high performance Web server Nginx (14) Smooth Upgrade your Nginx

Source: Internet
Author: User
Tags nginx server

1, overview (you can skip to see the 2nd part)

Nginx easily helps us to achieve a smooth upgrade. The principle of simple generalization is:

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

(2) The old process is responsible for processing requests that are still not processed, but no longer accepting processing requests.

(3) The new process accepts new requests.

(4) The old process finishes processing all requests, closes all connections, and then stops.

This makes it easy to implement a smooth upgrade. There are generally two cases need to upgrade nginx, one is really to upgrade Nginx version, the other is to add a new module for Nginx.

2. Upgrade process

The specific operation is also very simple, as follows:

(0) View current version

In the directory where the nginx executable file is stored, enter:

    1. ./nginx-v


(1) Download the new Nginx version and compile it.

    1. wget nginx-1.0. 11.tar.gz
    2. Tar zxvf nginx-1.0. 11.tar.gz
    3. CD nginx-1.0. One
    4. ./configure--add-module=/customized_module_0--add-module=/customized_module_1
    5. Make


Be careful not to make the install

(2) Back up the old version of the executable file

    1. Cd/usr/local/nginx/sbin
    2. sudo cp nginx Nginx.old


(3) Modify the configuration file

If necessary, make changes to the configuration file.

(4) Copy the new executable file

    1. sudo cp/home/michael/tmp/nginx-1.0. 11/objs/nginx/usr/local/nginx/sbin/


(5) Upgrade

    1. cd/home/michael/tmp/nginx-1.0. One
    2. Make upgrade

(6) Clean up redundant files

    1. rm-rf/home/michael/tmp/nginx-1.0. One


(7) View Nginx version

    1. Cd/usr/local/nginx/sbin
    2. ./nginx-v

3. Observing process changes

As I can see on my machine, I am configuring 10 worker processes, which are observed after startup:

  1. Root 6241 10419 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
  2. Nobody 6242 6241 2 10:51? 00:00:00 Nginx:worker Process
  3. Nobody 6243 6241 0 10:51? 00:00:00 Nginx:worker Process
  4. Nobody 6244 6241 0 10:51? 00:00:00 Nginx:worker Process
  5. Nobody 6245 6241 0 10:51? 00:00:00 Nginx:worker Process
  6. Nobody 6246 6241 0 10:51? 00:00:00 Nginx:worker Process
  7. Nobody 6247 6241 0 10:51? 00:00:00 Nginx:worker Process
  8. Nobody 6248 6241 0 10:51? 00:00:00 Nginx:worker Process
  9. Nobody 6249 6241 0 10:51? 00:00:00 Nginx:worker Process
  10. Nobody 6250 6241 0 10:51? 00:00:00 Nginx:worker Process
  11. Nobody 6251 6241 1 10:51? 00:00:00 Nginx:worker Process
  12. Nobody 6252 6241 0 10:51? 00:00:00 Nginx:cache Manager Process
  13. Nobody 6253 6241 0 10:51? 00:00:00 Nginx:cache Loader Process
  14. Luming 6310 25051 0 10:51 pts/1 00:00:00 grep--color=auto nginx
  15. Nobody 7995 10419 0 Jan12? 00:20:37 Nginx:worker process is shutting down
  16. Nobody 7996 10419 0 Jan12? 00:20:11 Nginx:worker process is shutting down
  17. Nobody 7998 10419 0 Jan12? 00:20:04 Nginx:worker process is shutting down
  18. Nobody 8003 10419 0 Jan12? 00:20:12 Nginx:worker process is shutting down
  19. Root 10419 1 0 Jan08? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx


The new process is visible with 1 master and 10 workers, plus 1 old master (which can be seen from time) and 4 workers (the other 6 older workers have already processed all connections and shutdown). There is also a loader process. In a few seconds, there are only two workers who can see the worker:

  1. Root 6241 10419 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
  2. Nobody 6242 6241 1 10:51? 00:00:00 Nginx:worker Process
  3. Nobody 6243 6241 0 10:51? 00:00:00 Nginx:worker Process
  4. Nobody 6244 6241 0 10:51? 00:00:00 Nginx:worker Process
  5. Nobody 6245 6241 0 10:51? 00:00:00 Nginx:worker Process
  6. Nobody 6246 6241 0 10:51? 00:00:00 Nginx:worker Process
  7. Nobody 6247 6241 0 10:51? 00:00:00 Nginx:worker Process
  8. Nobody 6248 6241 0 10:51? 00:00:00 Nginx:worker Process
  9. Nobody 6249 6241 0 10:51? 00:00:00 Nginx:worker Process
  10. Nobody 6250 6241 0 10:51? 00:00:00 Nginx:worker Process
  11. Nobody 6251 6241 0 10:51? 00:00:00 Nginx:worker Process
  12. Nobody 6252 6241 0 10:51? 00:00:00 Nginx:cache Manager Process
  13. Nobody 6253 6241 0 10:51? 00:00:00 Nginx:cache Loader Process
  14. Luming 6430 25051 0 10:51 pts/1 00:00:00 grep--color=auto nginx
  15. Nobody 7996 10419 0 Jan12? 00:20:11 Nginx:worker process is shutting down
  16. Nobody 8003 10419 0 Jan12? 00:20:12 Nginx:worker process is shutting down
  17. Root 10419 1 0 Jan08? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx


In a little while to observe:

  1. Root 6241 1 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
  2. Nobody 6242 6241 0 10:51? 00:00:01 Nginx:worker Process
  3. Nobody 6243 6241 0 10:51? 00:00:01 Nginx:worker Process
  4. Nobody 6244 6241 0 10:51? 00:00:01 Nginx:worker Process
  5. Nobody 6245 6241 0 10:51? 00:00:00 Nginx:worker Process
  6. Nobody 6246 6241 0 10:51? 00:00:00 Nginx:worker Process
  7. Nobody 6247 6241 0 10:51? 00:00:00 Nginx:worker Process
  8. Nobody 6248 6241 0 10:51? 00:00:00 Nginx:worker Process
  9. Nobody 6249 6241 0 10:51? 00:00:00 Nginx:worker Process
  10. Nobody 6250 6241 0 10:51? 00:00:01 Nginx:worker Process
  11. Nobody 6251 6241 0 10:51? 00:00:02 Nginx:worker Process
  12. Nobody 6252 6241 0 10:51? 00:00:00 Nginx:cache Manager Process
  13. Luming 8680 25051 0 10:56 pts/1 00:00:00 grep--color=auto nginx

congratulations! You can upgrade your Nginx server gracefully.

Research on the configuration and deployment of high performance Web server Nginx (14) Smooth Upgrade your Nginx

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.