nginx 做爲一個反向代理、負載均衡服務器,必須具有高可用的特色,所以 nginx 支持熱部署。
nginx 的熱部署和其併發模型有着密不可分的關係。說白了,就是由於 master 進程的關係。當通知 ngnix 重讀配置文件的時候,master 進程會進行語法錯誤的判斷。若是存在語法錯誤的話,返回錯誤,不進行裝載;若是配置文件沒有語法錯誤,那麼 ngnix 也不會將新的配置調整到全部 worker 中。而是,先不改變已經創建鏈接的 worker,等待 worker 將全部請求結束以後,將原先在舊的配置下啓動的 worker 殺死,而後使用新的配置建立新的 worker。
Nginx 做爲一個服務器,咱們不可能把服務停了在進行配置升級、軟件版本升級吧。因此,Nginx 的熱部署就極大的方便了咱們對服務器軟件的升級維護。html
whereis nginx
cd /usr/local/nginx ./sbin/nginx -V #大寫V
nginx version: nginx/1.12.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-18) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/usr/local/nginx --user=nginx --group=nginx --with-http_ssl_module --with-http_flv_module --with-http_stub_status_module --with-http_gzip_static_module --with-http_realip_module --with-openssl=/opt/openssl-1.0.2r --with-stream --with-stream_ssl_modulenginx
cd /opt wget http://nginx.org/download/nginx-1.15.0.tar.gz
tar xf nginx-1.15.0.tar.gz cd nginx-1.15.0 .configure --prefix=/usr/local/nginx --user=nginx --group=nginx \ --with-http_ssl_module --with-http_flv_module \ --with-http_stub_status_module --with-http_gzip_static_module \ --with-http_realip_module --with-openssl=/opt/openssl-1.0.2r \ --with-stream --with-stream_ssl_module make # 這裏只編譯不安裝,不要執行make install 命令,編譯後的nginx文件在/objs/目錄下
mv /usr/local/nginx/sbin/nginx /usr/local/nginx/sbin/nginx.old
cp -a /opt/nginx-1.15.0/objs/nginx /usr/local/nginx/sbin/
kill -USR2 cat /var/run/nginx/nginx.pid
ls -l /usr/local/nginx/logs/
...
nginx.pid
nginx.pid.oldbin
...服務器
kill -QUIT cat /var/run/nginx/nginx.pid.oldbin
./usr/local/nginx/sbin/nginx -v #小寫v
nginx version: nginx/1.15.0併發
至此,nginx熱部署完成了。負載均衡