一、环境:
redhat5.4、keepalived-1.1.17、nginx-1.0.6 
主nginx负载均衡器:192.168.0.10 
辅nginx负载均衡器:192.168.9.20 
vip:192.168.0.100
二、keepalived部署
1.下载最新稳定版 wget  http://www.keepalived.org/software/keepalived-1.1.17.tar.gz
2.安装keepalived
tar zxvf keepalived-1.1.17.tar.gz 
cd keepalived-1.1.17 
./configure –prefix=/usr/local/keepalive 
make ; make install
cp /usr/local/keepalived/sbin/keepalived /usr/sbin/ 
cp /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
3.配置keepalived
#master配置 
mkdir /etc/keepalived 
vim /etc/keepalived/keepalived.conf
global_defs { 
smtp_server 127.0.0.1 
smtp_connect_timeout 30 
router_id LVS_DEVEL 

vrrp_instance VI_1 { 
state MASTER 
interface eth0 
virtual_router_id 51 
#backup ipaddress 
mcast_src_ip 192.168.0.20 
priority 100 
advert_int 1 
authentication { 
auth_type PASS 
auth_pass ufsoft 

virtual_ipaddress { 
192.168.0.100 

}
#backup配置 
mkdir /etc/keepalived 
vim /etc/keepalived/keepalived.conf
global_defs { 
smtp_server 127.0.0.1 
smtp_connect_timeout 30 
router_id LVS_DEVEL 

vrrp_instance VI_1 { 
state BACKUP 
interface eth0 
virtual_router_id 51 
#master ipaddress 
mcast_src_ip 192.168.0.10 
priority 50 
advert_int 1 
authentication { 
auth_type PASS 
auth_pass ufsoft 

virtual_ipaddress { 
192.168.0.100 

}
通过命令:#ip a 来检查 
启动keepalived: 
keepalived -f /etc/keepalived/keepalived.conf -D 
//-f指定了keepalived的配置文件位置 
三、nginx部署
参考文档 《nginx+tomcat集群+session复制》。

转自: http://baiying.blog.51cto.com