|
在二台Nginx机上安装及配置keepalived,做双机互备
nginx(主负载均衡器):192.168.1.106
nginx(从负载均衡器):192.168.1.107
VIP地址:192.168.1.108
#wget http://www.keepalived.org/software/keepalived-1.1.15.tar.gz
#tar zxvf keepalived-1.1.15.tar.gz
#cd keepalived-1.1.15
#./configure
#make
#make install
将keepalived做成启动脚务,方便管理:
#cp /usr/local/etc/rc.d/init.d/keepalived /etc/rc.d/init.d/
#cp /usr/local/etc/sysconfig/keepalived /etc/sysconfig/
#mkdir /etc/keepalived
#cp /usr/local/etc/keepalived/keepalived.conf /etc/keepalived/
#cp /usr/local/sbin/keepalived /usr/sbin/
#service keepalived start|stop
在二台Nginx上,我分别贴出keepalived.conf配置文件,配置完成后分别用service keepalived start启动?检验keepalived是否成功可用命令
主负载均衡器:
ip avrrp_instance VI_INET1 {
state MASTER
interface eth0
virtual_router_id 53
priority 200
advert_int 1
authentication {
auth_type pass
auth_pass yourpass
}
从负载均衡器:
virtual_ipaddress {
192.168.1.108
}
}
vrrp_instance VI_INET1 {
state BACKUP
interface eth0
virtual_router_id 53
priority 100
advert_int 1
authentication {
auth_type pass
auth_pass yourpass
}
virtual_ipaddress {
192.168.1.108
}
}
以上完成nginx负载均衡设置后,就是检测了,大家可任意停掉其中一台的任何服务;在正常结果中大家应该发现,其中任意一台服务器宕机后,不影响整个系统的运作 |
|