In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/03 Report--
The theory is about $$.
First, why smooth upgrade to nginx
As nginx becomes more and more popular, and the advantages of nginx become more and more obvious, the iteration of the version of nginx also comes to accelerate the mode. Version 1.9.0 of nginx has updated many new features, such as the four-tier proxy function of stream. With the wide application of nginx, the version upgrade must be faster and faster, and the online business cannot be stopped. At this time, the upgrade of nginx is the work of operation and maintenance.
Second, nginx conveniently helps us to achieve a smooth upgrade. Its principle is simply summarized as follows:
(1) start a new process without stopping the old process.
(2) the old process is responsible for processing requests that have not yet been processed, but no longer accepts requests for processing.
(3) the new process accepts new requests.
(4) after the old process has processed all requests and closed all connections, it stops. This makes it easy to achieve a smooth upgrade. There are generally two situations where you need to upgrade nginx, one is to actually upgrade the version of nginx, and the other is to add a new module to nginx.
Third, the principle of nginx smooth upgrade
Request allocation in multi-process mode
Nginx works in multi-process mode by default, that is, after the main process (master process) starts, it completes the configuration loading and port binding and other actions. Fork sends out a specified number of worker processes (worker process). These child processes hold the file descriptor (fd) of the listening port and accept the connection (accept) by adding listening events to the descriptor.
Signal reception and processing
After starting, the nginx main process will enter the waiting state and be responsible for responding to all kinds of system messages, such as SIGCHLD, SIGHUP, SIGUSR2 and so on.
4. Brief introduction of Nginx signal:
Signals supported by the main process
TERM, INT: quit now
QUIT: wait for the end of the work process before quitting
KILL: force termination of a process
HUP: reload the configuration file, start the worker process with the new configuration, and gradually shut down the old process.
USR1: reopen the log file
USR2: start a new main process to achieve hot upgrade
WINCH: gradually shuts down the worker process
Signals supported by the worker process
TERM, INT: quit now
QUIT: wait for the request to be processed before quitting
USR1: reopen the log file
% nginx smooth upgrade process%
1. Nginx upgrade installed by yum, taking the upgrade from nginx to nginx-1.12.2 version to nginx-1.16.1 as an example
Yum-y install nginx (why can you yum directly, because nginx-1.12.2 exists in the epel extension source) systemctl start nginxsystemctl status nginx (make sure nginx is enabled) nginx- V check version and configuration parameters
Nginx version: nginx/1.12.2
Built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
Built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
Configure arguments:-prefix=/usr/share/nginx-- sbin-path=/usr/sbin/nginx-- modules-path=/usr/lib64/nginx/modules-- conf-path=/etc/nginx/nginx.conf-- error-log-path=/var/log/nginx/error.log-- http-log-path=/var/log/nginx/access.log-- http-client-body-temp-path=/var/lib/nginx/tmp/client_body-- http-proxy-temp-path=/var/lib / nginx/tmp/proxy-http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi-http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi-http-scgi-temp-path=/var/lib/nginx/tmp/scgi-pid-path=/run/nginx.pid-lock-path=/run/lock/subsys/nginx-user=nginx-group=nginx-with-file-aio-with-ipv6 with-http_auth_request_module with- Http_ssl_module-with-http_v2_module-with-http_realip_module-with-http_addition_module-with-http_xslt_module=dynamic-with-http_image_filter_module=dynamic-with-http_geoip_module=dynamic-with-http_sub_module-with-http_dav_module-with-http_flv_module-with-http_mp4_module with-http_gunzip_module with-http_gzip_static_module with-http_gzip_static_module with -http_random_index_module-with-http_secure_link_module-- with-http_degradation_module-- with-http_slice_module-- with-http_stub_status_module-- with-http_perl_module=dynamic-- with-mail=dynamic-- with-mail_ssl_module-- with-pcre--with-pcre-jit-- with-stream=dynamic-- with-stream_ssl_module-- with-google_perftools_module-- with-debug-- with-cc-opt='-O2-g-pipe-Wall-Wp -D_FORTIFY_SOURCE=2-fexceptions-fstack-protector-strong-- param=ssp-buffer-size=4-grecord-gcc-switches-specs=/usr/lib/rpm/redhat/redhat-hardened-cc1-M64-mtune=generic'-with-ld-opt='-Wl,-z,relro-specs=/usr/lib/rpm/redhat/redhat-hardened-ld-Wl,-E'
2. Start the upgrade version from nginx-1.12.2 to nginx-1.16.1. Install nginx according to the original compilation parameters, just go to make, never make install. If make install overwrites the original configuration file
Wget http://nginx.org/download/nginx-1.16.1.tar.gz
Tar xzf nginx-1.16.1.tar.gz-C / usr/local decompress the package to the specified location
Yum-y install GeoIP GeoIP-devel GeoIP-data perl-devel perl-ExtUtils-Embed gd-devel libxml2 libxslt-devel gperftools
Yum install-y gcc gcc-c++ pcre-devel openssl-devel zlib-devel add environment
Cd / usr/local (cd to the decompressed directory)
Ls
Cd nginx-1.16.1/
[root@localhost nginx-1.16.1] # nginx- V (check the parameters of the original version before configuring parameters)
[root@localhost nginx-1.16.1] # / configure-- prefix=/usr/share/nginx-- sbin-path=/usr/sbin/nginx-- modules-path=/usr/lib64/nginx/modules-- conf-path=/etc/nginx/nginx.conf-- error-log-path=/var/log/nginx/error.log-- http-log-path=/var/log/nginx/access.log-- http-client-body-temp-path=/var/lib/nginx/tmp/client_body- -http-proxy-temp-path=/var/lib/nginx/tmp/proxy-http-fastcgi-temp-path=/var/lib/nginx/tmp/fastcgi-- http-uwsgi-temp-path=/var/lib/nginx/tmp/uwsgi-- http-scgi-temp-path=/var/lib/nginx/tmp/scgi-- pid-path=/run/nginx.pid-- lock-path=/run/lock/subsys/nginx-- user=nginx-- group=nginx-- with-file-aio-- with-ipv6-- with -http_auth_request_module-with-http_ssl_module-with-http_v2_module-with-http_realip_module-with-http_addition_module-with-http_xslt_module=dynamic-with-http_image_filter_module=dynamic-with-http_geoip_module=dynamic-with-http_sub_module-with-http_dav_module-with-http_flv_module-with-http_mp4_module-with-http_gunzip_module With-http_gzip_static_module-with-http_random_index_module-with-http_secure_link_module-with-http_degradation_module-with-http_slice_module-with-http_stub_status_module-with-http_perl_module=dynamic-with-mail=dynamic-with-mail_ssl_module-with-pcre- with-pcre-jit-with-stream=dynamic with-stream_ssl_module with-stream_ssl_module with-google_perftools_module with-debug
(configure the parameters of the upgrade version to be the same as those of the original version, which can be copied to-- with-debug, and none of the subsequent-- with cc parameters are required)
Make
3. Back up the original nginx binaries (nginx installed by yum, whose binaries and configuration files are stored in / usr/sbin/ by default) backup binaries and configuration files of nginx (during which nginx will not stop service)
Mv / usr/sbin/nginx / usr/sbin/nginx_$ (date +% F)
4. Copy the new version of nginx binaries and enter the new nginx source code package
Cp / usr/local/nginx-1.16.1/objs/nginx / usr/sbin/
5. Test whether the new version of nginx is normal.
/ usr/sbin/nginx-t
If the following error occurs:
Nginx: [emerg] module "/ usr/lib64/nginx/modules/ngx_http_geoip_module.so" version 1012002 instead of 1016001 in / usr/share/nginx/modules/mod-http-geoip.conf:1
Nginx: configuration file / etc/nginx/nginx.conf test failed
Solution:
# vim / etc/nginx/nginx.conf (edit the main configuration file of nginx)
Just find the sentence # include / usr/share/nginx/modules/*.conf; and comment it.
/ usr/sbin/nginx-t (test again and no error will be reported)
6. Send a smooth migration signal to nginx (if you don't know the pid path, please check / etc/nginx/nginx.conf configuration file)
Kill-USR2 cat / var/run/nginx.pid
(to view pid, you can also find /-name "nginx.pid")
7. Check the nginx pid and a nginx.pid.oldbin will appear
[root@localhost nginx-1.16.1] # ll / var/run/nginx.pid*
-rw-r--r--. 1 root root 5 August 24 01:30 / var/run/nginx.pid
-rw-r--r--. 1 root root 5 August 24 01:30 / var/run/nginx.pid.oldbin
8. Calmly shut down the old Nginx process
# kill-WINCH cat / var/run/nginx.pid.oldbin
9. Do not reload the configuration to start the old worker process at this time
# kill-HUP cat / var/run/nginx.pid.oldbin
10. End the work process and complete the upgrade
# kill-QUIT cat / var/run/nginx.pid.oldbin
11. Verify whether the Nginx upgrade is successful
Nginx-V
Nginx version: nginx/1.16.1 version upgraded to nginx-1.16.1 successfully
Built by gcc 4.8.5 20150623 (Red Hat 4.8.5-36) (GCC)
Built with OpenSSL 1.0.2k-fips 26 Jan 2017
TLS SNI support enabled
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.