2013-09-27 09:31:01
来 源
kejihao
Nginx
本文介绍Nginx+keepalived配置双主负载均衡集群环境,希望对于初学Nginx服务器相关的朋友有帮助,更多Nginx安装、配置、报错处理等资源请本站内搜索。。

主要区别如下:

//蓝色与红色仔细观察

192.168.10.1主服务器的keepalived配置

!ConfigurationFileforkeepalived

global_defs{

notification_email{

[email protected]

}

notification_email_from[email protected]

smtp_server127.0.0.1

smtp_connect_timeout30

}

vrrp_scriptchk_http_port{

script"/etc/keepalived/chk_nginx_pid.sh"

interval2

weight2

}

vrrp_instanceVI_1{

stateMASTER

interfaceeth0

virtual_router_id51//VI_2为52

priority100//备用是99

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

track_script{

chk_http_port

}

virtual_ipaddress{

192.168.10.6//VIP1

}

}

vrrp_instanceVI_2{

stateBACKUP

interfaceeth0

virtual_router_id52//VI_1是51

priority99//主是100

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

track_script{

chk_http_port

}

virtual_ipaddress{

192.168.10.5//VIP2

}

}

192.168.10.2主服务器的keepalived配置

!ConfigurationFileforkeepalived

global_defs{

notification_email{

[email protected]

}

notification_email_from[email protected]

smtp_server127.0.0.1

smtp_connect_timeout30

}

vrrp_scriptchk_http_port{

script"/etc/keepalived/chk_nginx_pid.sh"

interval2

weight2

}

vrrp_instanceVI_1{

stateBACKUP

interfaceeth3

virtual_router_id51

priority99

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

track_script{

chk_http_port

}

virtual_ipaddress{

192.168.10.6

}

}

vrrp_instanceVI_2{

stateMASTER

interfaceeth3

virtual_router_id52

priority100

advert_int1

authentication{

auth_typePASS

auth_pass1111

}

track_script{

chk_http_port

}

virtual_ipaddress{

192.168.10.5

}

}

测试

停止192.168.10.1的nginx服务访问http://192.168.10.5与http://192.168.10.6刷新也正常

启动192.168.10.1的nginx服务与keepalived服务(因为脚本写为nginx服务停止了,keepalived也停止)

停止192.168.10.4的nginx服务访问http://192.168.10.5与http://192.168.10.6刷新也正常

查看ipa

会发现停掉10.4之后10.1eth0会出现192.168.10.5与192.168.10.6

nginx+keepalived双主负载均衡的[主要配置]

同理如此停掉10.1之后10.4eth3也会出现如图

不足之处欢迎前来留言指正。还有好的想法也可以留言共同学习与讨论。

声明: 此文观点不代表本站立场;转载须要保留原文链接;版权疑问请联系我们。