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:
- ./nginx-v
(1) Download the new Nginx version and compile it.
- wget nginx-1.0. 11.tar.gz
- Tar zxvf nginx-1.0. 11.tar.gz
- CD nginx-1.0. One
- ./configure--add-module=/customized_module_0--add-module=/customized_module_1
- Make
Be careful not to make the install
(2) Back up the old version of the executable file
- Cd/usr/local/nginx/sbin
- sudo cp nginx Nginx.old
(3) Modify the configuration file
If necessary, make changes to the configuration file.
(4) Copy the 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. One
- Make upgrade
(6) Clean up redundant files
- rm-rf/home/michael/tmp/nginx-1.0. One
(7) View Nginx version
- Cd/usr/local/nginx/sbin
- ./nginx-v
3. Observing process changes
As I can see on my machine, I am configuring 10 worker processes, which are observed after startup:
- Root 6241 10419 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
- Nobody 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 Process
- Nobody 6253 6241 0 10:51? 00:00:00 Nginx:cache Loader Process
- Luming 6310 25051 0 10:51 pts/1 00:00:00 grep--color=auto nginx
- Nobody 7995 10419 0 Jan12? 00:20:37 Nginx:worker process is shutting down
- Nobody 7996 10419 0 Jan12? 00:20:11 Nginx:worker process is shutting down
- Nobody 7998 10419 0 Jan12? 00:20:04 Nginx:worker process is shutting down
- Nobody 8003 10419 0 Jan12? 00:20:12 Nginx:worker process is shutting down
- 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:
- Root 6241 10419 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
- Nobody 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 Process
- Nobody 6253 6241 0 10:51? 00:00:00 Nginx:cache Loader Process
- Luming 6430 25051 0 10:51 pts/1 00:00:00 grep--color=auto nginx
- Nobody 7996 10419 0 Jan12? 00:20:11 Nginx:worker process is shutting down
- Nobody 8003 10419 0 Jan12? 00:20:12 Nginx:worker process is shutting down
- Root 10419 1 0 Jan08? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
In a little while to observe:
- Root 6241 1 0 10:51? 00:00:00 Nginx:master Process/usr/local/nginx/sbin/nginx
- Nobody 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 Process
- 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