概述
近年來隨着Nginx在國內的發展潮流,越來越多的互聯網公司使用Nginx;憑Nginx的高性能、穩定性等成爲了衆多IT者青睞的WEB反向代理服務器;但是Nginx雖然有很強大的代理功能,只有一臺Nginx服務器難免不會出現問題,這就形成了單點故障的問題,而恰好可以使用Keepalived來解決單點的故障問題,Keepalived故障轉移時間比較短,而且配置簡單易用,這也是選擇Keepalived做高可用的一個主要原因所在,如果日PV值不是很大的中小型企業可以考慮使用這種方案
Tengine
Tengine是由淘寶網發起的Web服務器項目。它在Nginx的基礎上,針對大訪問量網站的需求,添加了很多高級功能和特性。Tengine的性能和穩定性已經在大型的網站如淘寶、天貓商城等得到了很好的檢驗。它的最終目標是打造一個高效、穩定、安全、易用的Web平臺
Tengine特性:
1、繼承Nginx-1.2.9的所有特性,100%兼容Nginx的配置
2、動態模塊加載(DSO)支持。加入一個模塊不再需要重新編譯整個Tengine
3、更加強大的負載均衡能力,包括一致性hash模塊、會話保持模塊,還可以對後端的服務器進行主動健康4、檢查,根據服務器狀態自動上線下線
5、輸入過濾器機制支持。通過使用這種機制Web應用防火牆的編寫更爲方便
6、組合多個CSS、JavaScript文件的訪問請求變成一個請求
7、自動根據CPU數目設置進程個數和綁定CPU親緣性
8、監控系統的負載和資源佔用從而對系統進行保護
9、更強大的防攻擊(訪問速度限制)模塊
10、動態腳本語言Lua支持。擴展功能非常高效簡單
......
一、Nginx+Keepalived有兩種配置高可用方法
1、Nginx+Keepalived主備模式
使用一個虛擬IP地址即可,前端有兩臺Nginx服務器做調度,其中一臺爲主節點而另一臺有備用節點,兩臺服務器只有一臺提供服務,而另一臺處於閒置的狀態,只有主節點服務器出現故障時備用節點服務器纔會接管主節點服務器上的所有服務及虛擬IP並繼續提供服務,而這一切對客戶端來說是透明的
2、Nginx+Keepalived主主模式
這種模式需要使用兩個虛擬IP地址,前端有兩臺Nginx服務器做調度,兩臺服務器互爲主備並同時工作,如果其中一臺服務器出現故障時,將會把所有請求都轉發到另一臺服務器上面,這種做是不是很經濟實惠,兩臺服務器同時提供服務,相比主備模式不僅分擔了一臺服務器的壓力還提高了併發量
二、下面以一個案例來配置說明Keepalived+Nginx是如何實現高可用
環境介紹:
系統版本:CentOS 6_x86_64
Tengine版本: Tengine-1.5.1
Keepalived版本:keepalived-1.2.7-3.el6
1、在Nginx1與Nginx2服務器上安裝Tengine
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
######在Nginx1安裝 [root@nginx1 ~] # useradd -r nginx [root@nginx1 ~] # tar xf tengine-1.5.1.tar.gz [root@nginx1 ~] # cd tengine-1.5.1 ######安裝Tengine的依賴環境包 [root@nginx1 ~] # yum -y install pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel lua-devel GeoIP-devel gcc gcc-c++ [root@nginx1 ~] # ./configure \ --prefix= /usr/local/nginx \ --sbin-path= /usr/local/nginx/sbin/nginx \ --conf-path= /etc/nginx/nginx .conf \ --error-log-path= /var/log/nginx/error .log \ --http-log-path= /var/log/nginx/access .log \ --pid-path= /var/run/nginx/nginx .pid \ --lock-path= /var/lock/nginx .lock \ --user=nginx \ --group=nginx \ -- enable -mods-shared=all [root@nginx1 tengine-1.5.1] # make && make install ######在Nginx2安裝 [root@nginx2 ~] # scp 172.16.14.1:/root/tengine-1.5.1.tar.gz ./ [root@nginx2 tengine-1.5.1] # yum -y install pcre-devel openssl-devel libxml2-devel libxslt-devel gd-devel lua-devel GeoIP-devel gcc gcc-c++ [root@nginx2 tengine-1.5.1] # ./configure \ --prefix= /usr/local/nginx \ --sbin-path= /usr/local/nginx/sbin/nginx \ --conf-path= /etc/nginx/nginx .conf \ --error-log-path= /var/log/nginx/error .log \ --http-log-path= /var/log/nginx/access .log \ --pid-path= /var/run/nginx/nginx .pid \ --lock-path= /var/lock/nginx .lock \ --user=nginx \ --group=nginx \ -- enable -mods-shared=all [root@nginx2 tengine-1.5.1] # make && make install |
2、在Nginx1與Nginx2服務器上爲Tengine準備Sysv服務腳本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
|
######Nginx1提供腳本 [root@nginx1 ~] # vim /etc/init.d/nginx #!/bin/sh # nginx - this script starts and stops the nginx daemon # chkconfig: - 85 15 # description: Nginx is an HTTP(S) server, HTTP(S) reverse \ # processname: nginx # config: /etc/nginx/nginx.conf # config: /etc/sysconfig/nginx # pidfile: /var/run/nginx.pid # Source function library. . /etc/rc .d /init .d /functions # Source networking configuration. . /etc/sysconfig/network # Check that networking is up. [ "$NETWORKING" =
"no" ] &&
exit 0 nginx= "/usr/local/nginx/sbin/nginx" prog=$( basename $nginx) NGINX_CONF_FILE= "/etc/nginx/nginx.conf" [ -f /etc/sysconfig/nginx ] && .
/etc/sysconfig/nginx lockfile= /var/lock/subsys/nginx make_dirs() { # make required directories user=`nginx -V 2>&1 | grep
"configure arguments:" |
sed 's/[^*]*--user=\([^ ]*\).*/\1/g'
-` options=`$nginx -V 2>&1 | grep
'configure arguments:' ` for opt
in $options;
do if [ ` echo
$opt | grep
'.*-temp-path' ` ]; then
value=` echo
$opt | cut -d "="
-f 2`
if [ ! -d "$value" ];
then
# echo "creating" $value
mkdir -p $value &&
chown -R $user $value
fi fi done } start() { [ -x $nginx ] || exit
5 [ -f $NGINX_CONF_FILE ] || exit
6 make_dirs echo -n $ "Starting $prog: " daemon $nginx -c $NGINX_CONF_FILE retval=$? echo [ $retval - eq 0 ] &&
touch $lockfile return $retval } stop() { echo -n $ "Stopping $prog: " killproc $prog -QUIT retval=$? echo [ $retval - eq 0 ] &&
rm -f $lockfile return $retval } restart() { configtest || return
$? stop sleep 1 start } reload() { configtest || return
$? echo -n $ "Reloading $prog: " killproc $nginx -HUP RETVAL=$? echo } force_reload() { restart } configtest() { $nginx -t -c $NGINX_CONF_FILE } rh_status() { status $prog } rh_status_q() { rh_status > /dev/null 2>&1 } case
"$1" in start)
rh_status_q && exit 0
$1
;; stop)
rh_status_q || exit 0
$1
;; restart|configtest)
$1
;; reload)
rh_status_q || exit 7
$1
;; force-reload)
force_reload
;; status)
rh_status
;; condrestart|try-restart)
rh_status_q || exit 0
;; *)
echo $"Usage: $0 {start|stop|status|restart|condrestart| try-restart|reload|force-reload|configtest}"
exit 2 esac ######將Nginx加入到系統服務並啓動 [root@nginx1 ~] # chmod +x /etc/init.d/nginx [root@nginx1 ~] # chkconfig --add nginx [root@nginx1 ~] # service nginx start ######將Nginx1腳本拷貝到Nignx2服務器上並加入系統服務 [root@nginx2 ~] # scp 172.16.14.1:/etc/init.d/nginx /etc/init.d/ [root@nginx2 ~] # chmod +x /etc/init.d/nginx [root@nginx2 ~] # chkconfig --add nginx [root@nginx2 ~] # service nginx start |
3、訪問測試Nginx服務是否正常
3.1、在Nginx1服務器上測試
1
2
|
[root@nginx1 ~] # netstat -anpt|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 15088 /nginx |
3.2、在Nginx2服務器上測試
1
2
|
[root@nginx2 ~] # netstat -anpt|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7281 /nginx |
三、在Httpd1與Httpd2服務器上安裝Apache
1、在Httpd1服務器配置好YUM源,使用YUM安裝HTTPD服務
1
2
3
4
5
|
[root@httpd1 ~] # yum -y install httpd [root@httpd1 ~] # chkconfig httpd on [root@httpd1 ~] # service httpd start ######爲Httpd1提供測試頁 [root@httpd1 ~] # echo '<h1>172.16.14.3 httpd1</h1>' > /var/www/html/index.html |
2、在Httpd2服務器配置好YUM源,使用YUM安裝HTTPD服務
1
2
3
4
|
[root@httpd2 ~] # yum -y install httpd [root@httpd2 ~] # chkconfig httpd on [root@httpd2 ~] # service httpd start [root@httpd2 ~] # echo '<h1>172.16.14.4 httpd2</h1>' > /var/www/html/index.html |
四、配置Tengine
1、將主配置文件備份一份然後修改主配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
[root@nginx1 ~]# cd /etc/nginx/ [root@nginx1 nginx]# cp nginx.conf nginx.conf.bak [root@nginx1 nginx]# vim nginx.conf user nginx nginx; worker_processes 2; worker_rlimit_nofile 51200; #error_log logs/error.log; #pid logs/nginx.pid; events { use epoll; worker_connections 51200; } # load modules compiled as Dynamic Shared Object (DSO) dso { #實現動態加載模塊 load ngx_http_upstream_session_sticky_module.so; #加載session模塊 } http { include mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"' ; access_log logs/access. log main; client_max_body_size 20m; client_header_buffer_size 16k; large_client_header_buffers 4 16k; sendfile on; tcp_nopush on; keepalive_timeout 65; gzip on; #開啓壓縮 gzip_min_length 1k; gzip_buffers 4 16k; gzip_proxied any; gzip_http_version 1.1; gzip_comp_level 3; gzip_types text/plain application/x-javascript text/css application/xml; gzip_vary on; proxy_temp_path /tmp/proxy_temp; proxy_cache_path /tmp/proxy_cache levels=1:2 keys_zone=cache_one:500m inactive=1d max_size=3g; proxy_connect_timeout 50; proxy_read_timeout 600; proxy_send_timeout 600; proxy_buffer_size 128k; proxy_buffers 16 256k; proxy_busy_buffers_size 512k; proxy_temp_file_write_size 1024m; proxy_next_upstream error timeout invalid_header http_500 http_503 http_404 http_502 http_504; upstream allen { server 172.16.14.3; server 172.16.14.4; check interval=3000 rise=2 fall=5 timeout=1000 type=http; #後端Server健康狀態檢查 check_http_send "GET / HTTP/1.0\r\n\r\n" ; check_http_expect_alive http_2xx http_3xx; session_sticky; #保持會話連接 } server { listen 80; server_name localhost; #charset koi8-r; #access_log logs/host.access.log main; location / { proxy_pass http: //allen; } location /status { #實現狀態監控
check_status; } #error_page 404 /404.html; # redirect server error pages to the static page /50x.html # error_page 500 502 503 504 /50x.html; location = /50x.html {
root html; } # proxy the PHP scripts to Apache listening on 127.0.0.1:80 # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000 # #location ~ \.php$ { # root html; # fastcgi_pass 127.0.0.1:9000; # fastcgi_index index.php; # fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name; # include fastcgi_params; #} # deny access to .htaccess files, if Apache's document root # concurs with nginx's one # #location ~ /\.ht { # deny all; #} } # HTTPS server # #server { # listen 443; # server_name localhost; # ssl on; # ssl_certificate cert.pem; # ssl_certificate_key cert.key; # ssl_session_timeout 5m; # ssl_protocols SSLv2 SSLv3 TLSv1; # ssl_ciphers HIGH:!aNULL:!MD5; # ssl_prefer_server_ciphers on; # location / { # root html; # index index.html index.htm; # } #} } 註釋:Nginx的更多參數介紹請查看前面的博客 |
2、重啓Tengine服務訪問測試負載均衡
1
|
[root@nginx1 ~] # service nginx restart |
由上圖可見可以成功訪問到後端的Httpd服務,接下來訪問測試狀態監控模塊
3、在Nginx2服務器配置Tengine主配置文件
1
2
3
4
|
######複製Nginx1服務器上的配置文件到Nginx2服務器 [root@nginx2 ~] # scp 172.16.14.1:/etc/nginx/nginx.conf /etc/nginx/ [root@nginx2 ~] # service nginx restart 註釋:重啓Tengine服務並測試;測試方法同Nginx1服務器,這裏就不再做測試了 |
五、安裝Keepalived並配置
1、在Nginx1與Nginx2服務器上安裝Keepalived
1
2
3
4
|
######在Nginx1服務器安裝 [root@nginx1 ~] # yum -y install keepalived ######在Nginx2服務器安裝 [root@nginx2 ~] # yum -y install keepalived |
2、配置Keepalived雙主模式
2.1、修改Nginx1服務器上的Keepalived主配置文件定義
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
|
[root@nginx1 ~] # vim /etc/keepalived/keepalived.conf ! Configuration File for
keepalived global_defs { notification_email { root@localhost #通知收件人地址,可以寫換行寫多個 } smtp_server 127.0.0.1 #郵件smtp服務器地址 smtp_connect_timeout 30 #郵件smtp連接超時時間 router_id LVS_DEVEL #運行Keepalived服務器的標識,自定義;發郵件時顯示在郵件標題中的信息 } vrrp_script chk_nginx { #定義一個外部腳本 script "/etc/keepalived/chk_nginx.sh" #腳本的路徑 interval 1 #通知間隔 weight 2 } vrrp_script chk_proess { script "/etc/keepalived/chk_proess.sh" interval 1 weight 2 } vrrp_instance nginx_1 { state MASTER #角色{MASTER|BACKUP} interface eth0 #HA監測的網卡 virtual_router_id 56 #虛擬路由ID;一組集羣ID號必須一樣 priority 100 #權重,BACKUP不能高於MASTER advert_int 1 #檢測時間間隔 garp_master_delay 1 authentication {
auth_type PASS #認證類型
auth_pass 1234 #認證密碼,同一集羣密碼要一樣 } virtual_ipaddress { #定義虛擬IP地址,可以有多個 172.16.14.10 } track_script { #定義狀態跟蹤
chk_nginx #名稱爲vrrp_script中定義的 chk_proess } notify_master "/etc/keepalived/chk_nginx.sh master"
#指定切換到Master狀態時執行的腳本 notify_backup "/etc/keepalived/chk_nginx.sh backup"
#指定切換到Backup狀態時執行的腳本 notify_fault "/etc/keepalived/chk_nginx.sh fault"
#指定切換到Fault狀態時執行的腳本 } vrrp_instance nginx_2 { state BACKUP interface eth0 virtual_router_id 58 priority 90 advert_int 1 authentication {
auth_type PASS
auth_pass 4321 } virtual_ipaddress { 172.16.14.11 } track_script {
chk_nginx } } |
2.2、修改Nginx2服務器上的Keepalived主配置文件定義
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
[root@nginx2 ~] # vim /etc/keepalived/keepalived.conf ! Configuration File for
keepalived global_defs { notification_email { root@localhost } notification_email_from [email protected] smtp_server 127.0.0.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_script chk_nginx { script "/etc/keepalived/chk_nginx.sh" interval 1 weight 2 } vrrp_script chk_nginx { script "/etc/keepalived/chk_proess.sh" interval 1 weight 2 } vrrp_instance nginx_1 { state BACKUP interface eth0 virtual_router_id 56 priority 98 advert_int 1 authentication {
auth_type PASS
auth_pass 1234 } virtual_ipaddress { 172.16.14.10 } track_script {
chk_nginx } } vrrp_instance nginx_2 { state MASTER interface eth0 virtual_router_id 58 priority 92 advert_int 1 authentication {
auth_type PASS
auth_pass 4321 } virtual_ipaddress { 172.16.14.11 } track_script {
chk_nginx chk_proess } notify_master "/etc/keepalived/chk_nginx.sh master" notify_backup "/etc/keepalived/chk_nginx.sh backup" notify_fault "/etc/keepalived/chk_nginx.sh fault" } |
3、在Nginx1與Nginx2服務器分別爲Keepalived提供狀態檢測腳本及通知腳本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
######通知腳本 vim /etc/keepalived/chk_nginx .sh #!/bin/bash # Author: ALLEN # description: An example of notify script # vip=172.16.14.10 contact= 'root@localhost' notify() { mailsubject= "`hostname` to be $1: $vip floating" mailbody= "`date '+%F %H:%M:%S'`: vrrp transition, `hostname` changed to be $1" echo $mailbody | mail -s
"$mailsubject" $contact } case
"$1" in master)
notify master
/usr/local/keepalived/sbin/keepalived
start
exit 0 ;; backup)
notify backup
/usr/local/keepalived/sbin/keepalived
stop
exit 0 ;; fault)
notify fault
exit 0 ;; *)
echo 'Usage: `basename $0` {master|backup|fault}'
exit 1 ;; esac ######狀態檢測腳本 vim /etc/keepalived/chk_proess .sh #!/bin/bash killall -0 nginx if
[[ $? - ne 0 ]]; then /etc/init .d /keepalived stop fi ######添加執行權限 chkmod +x
/etc/keepalived/chk_ * |
六、測試Keepalived+Tengine高可用
1、分別重新啓動Nginx1與Nginx2服務器上面的Keepalived與Tengine服務
1
2
|
[root@nginx1 ~] # service keepalived restart;service nginx restart [root@nginx2 ~] # service keepalived restart;service nginx restart |
2、分別查看Nginx1與Nginx2服務器上的IP地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
|
######查看Nginx1服務器 [root@nginx1 ~] # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:2c:1a:24 brd ff:ff:ff:ff:ff:ff inet 172.16.14.1 /16 brd 172.16.255.255 scope global eth0 inet 172.16.14.10 /32 scope global eth0 inet6 fe80::20c:29ff:fe2c:1a24 /64 scope link valid_lft forever preferred_lft forever ######查看Nginx2服務器 [root@nginx2 ~] # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:ec:f6:3f brd ff:ff:ff:ff:ff:ff inet 172.16.14.2 /16 brd 172.16.255.255 scope global eth0 inet 172.16.14.11 /32 scope global eth0 inet6 fe80::20c:29ff:feec:f63f /64 scope link valid_lft forever preferred_lft forever 註釋:由上可見,兩臺服務器都有虛擬IP地址 |
3、訪問測試172.16.14.10
4、模擬其中一臺前端Nginx服務器出現故障不能正常提供服務
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
|
[root@nginx1 ~] # killall nginx [root@nginx1 ~] # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:2c:1a:24 brd ff:ff:ff:ff:ff:ff inet 172.16.14.1 /16 brd 172.16.255.255 scope global eth0 inet6 fe80::20c:29ff:fe2c:1a24 /64 scope link valid_lft forever preferred_lft forever ######由上可見,虛擬IP地址已刪除 ======================================================================== ######在Nginx2服務器上查看IP地址 [root@nginx2 ~] # ip addr show eth0 2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000 link /ether 00:0c:29:ec:f6:3f brd ff:ff:ff:ff:ff:ff inet 172.16.14.2 /16 brd 172.16.255.255 scope global eth0 inet 172.16.14.11 /32 scope global eth0 inet 172.16.14.10 /32 scope global eth0 inet6 fe80::20c:29ff:feec:f63f /64 scope link valid_lft forever preferred_lft forever 註釋:由上可見,虛擬IP地址已成功切換 |
5、在Nginx2服務器查看郵件通知
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
[root@nginx2 ~] # mail Heirloom Mail version 12.4 7 /29/08 . Type ? for
help. "/var/spool/mail/root" : 3 messages 2 unread >U 1 root Wed Sep 25 16:54 19 /712 "nginx2.allen.com to be master: 172.16.14.10 floating"
U 2 root Wed Sep 25 17:23 19 /712 "nginx2.allen.com to be master: 172.16.14.10
floating" 3 root Wed Sep 25 18:06 19 /713 "nginx2.allen.com to be master: 172.16.14.10
floating" & 3 Message 3: From [email protected] Wed Sep 25 18:06:27 2013 Return-Path: <[email protected]> X-Original-To: root@localhost Delivered-To: [email protected] Date: Wed, 25 Sep 2013 18:06:27 +0800 Subject: nginx2.allen.com to be master: 172.16.14.10 floating User-Agent: Heirloom mailx 12.4 7 /29/08 Content-Type: text /plain ; charset=us-ascii From: [email protected] (root) Status: RO 2013-09-25 18:06:27: vrrp transition, nginx2.allen.com changed to be master & quit #退出 註釋:可以看出此時Nginx2服務器已經成功Master,當然Nginx1服務器成功了Backup;這裏就不在查看Nginx1的郵件了,各位博友可以查看一下 |
6、再次訪問172.16.14.10測試
由上圖可見,依然可以正常訪問;Keepalived+Tengine高可用已實現
7、這裏就不在對另一個虛擬IP(172.16.14.11)做測試了,測試方法與(172.16.14.10)相同;在實際環境中在DNS服務器爲兩個虛擬IP地址做A記錄,能實現兩個前端Nginx調度的負載均衡;這裏配置個兩個實例均使用的是eth0網卡,但在實際環境中最好使用不同的網卡;由於內容較多,下面就不寫Corosync+DRBD+Mysql的實現了,