1.nginx-upsync-module安裝
半自動平滑升級
所謂半自動,其實就是在最後遷移的時候使用源碼自帶的升級命令:make upgrade 來自動完成
說明地址:
https://github.com/weibocom/nginx-upsync-module
nginx-upsync-module
Nginx C模塊,可以同步Consul或其他模塊的上游。它動態地修改了後端服務器的屬性(weight,max_fails等),而無需重新加載NGINX。
修改配置文件並重新啓動NGINX可能並不總是很方便。例如,如果您遇到大量的流量和高負載,則在那時重啓NGINX並重新加載配置會進一步增加系統的負載並可能暫時降低性能。
1.1 下載並安裝擴展:nginx-upsync-module
下載地址:https://github.com/weibocom/nginx-upsync-module/releases
[root@localhost ~]# wget https://github.com/weibocom/nginx-upsync-module/archive/v2.1.0.tar.gz
1.2 解壓
[root@localhost ~]# tar -zxvf v2.1.0.tar.gz
1.3 進入nginx解壓目錄,安裝
[root@localhost ~]# ls
nginx-1.14.1
[root@localhost ~]# cd nginx-1.14.1
#1.清空之前的編譯文件
[root@localhost nginx-1.14.1]# make clean
#2.執行 nginx -V 查看之前的編譯參數
[root@localhost nginx-1.14.1]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.1
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/local/nginx --with-pcre --with-http_ssl_module --with-http_gzip_static_module
#3.添加擴展執行編譯
[root@localhost nginx-1.14.1]# ./configure --prefix=/usr/local/nginx --with-pcre --with-http_ssl_module --with-http_gzip_static_module --add-module=/root/nginx-upsync-module-2.1.0
#4.執行make (不能執行 make install)
[root@localhost nginx-1.14.1]# make
#5.(打開新連接窗口操作)重命名 nginx 舊版本二進制文件,即 sbin 目錄下的 nginx(期間 nginx 並不會停止服務)
》》客戶端2:
[root@localhost ~]# cd /usr/local/nginx/sbin/
[root@localhost sbin]# ls
nginx
[root@localhost sbin]# mv nginx nginx.old
[root@localhost sbin]# ls
nginx.old
#6.拷貝一份新編譯的二進制文件到安裝目錄
[root@localhost nginx-1.14.1]# cd objs/
[root@localhost objs]# ll
total 6092
drwxr-xr-x. 3 root root 17 Apr 20 16:47 addon
-rw-r--r--. 1 root root 17835 Apr 20 16:47 autoconf.err
-rw-r--r--. 1 root root 42011 Apr 20 16:47 Makefile
-rwxr-xr-x. 1 root root 6053512 Apr 20 16:48 nginx
-rw-r--r--. 1 root root 5341 Apr 20 16:48 nginx.8
-rw-r--r--. 1 root root 7181 Apr 20 16:47 ngx_auto_config.h
-rw-r--r--. 1 root root 657 Apr 20 16:47 ngx_auto_headers.h
-rw-r--r--. 1 root root 6135 Apr 20 16:47 ngx_modules.c
-rw-r--r--. 1 root root 86656 Apr 20 16:48 ngx_modules.o
drwxr-xr-x. 9 root root 91 Apr 20 16:47 src
[root@localhost objs]# cp nginx /usr/local/nginx/sbin/
》》客戶端2(拷貝的nginx):
[root@localhost sbin]# pwd
/usr/local/nginx/sbin
[root@localhost sbin]# ls
nginx nginx.old
#7.在源碼目錄執行 make upgrade 開始升級
[root@localhost objs]# cd ..
[root@localhost nginx-1.14.1]# pwd
/root/nginx-1.14.1
[root@localhost nginx-1.14.1]# make upgrade
/usr/local/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/nginx/conf/nginx.conf test is successful
kill -USR2 `cat /usr/local/nginx/logs/nginx.pid`
sleep 1
test -f /usr/local/nginx/logs/nginx.pid.oldbin
kill -QUIT `cat /usr/local/nginx/logs/nginx.pid.oldbin`
(查看進程的方式可以查看是否重啓成功 ps -ef|grep nginx)
#8 查看安裝命令的方式,可以查看是否安裝成功
[root@localhost nginx-1.14.1]# /usr/local/nginx/sbin/nginx -V
nginx version: nginx/1.14.1
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/local/nginx --with-pcre --with-http_ssl_module --with-http_gzip_static_module --add-module=/root/nginx-upsync-module-2.1.0
=====================================================
2.安裝consul
2.1下載consul
[root@localhost ~]# wget https://releases.hashicorp.com/consul/1.6.3/consul_1.6.3_linux_amd64.zip