web1 IP 192.168.0.47
web2 IP 192.168.0.48
haproxy_master 192.168.0.200
haproxy_backup 192.168.0.199
VIP 192.168.0.155
一.安装keepalived
#wget #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/
配置keepalived.conf
#vim /etc/keepalived/keepalived.conf
! Configuration File for keepalived global_defs { notification_email { gaoming@123.com } notification_email_from gaoming@123.com smtp_server 192.168.200.1 smtp_connect_timeout 30 router_id LVS_DEVEL } vrrp_instance VI_1 { state MASTER #备用服务器上改为 BACKUP interface eth0 virtual_router_id 51 priority 100 #备用服务器上改为99 advert_int 1 authentication { auth_type PASS auth_pass 1111 } virtual_ipaddress { 192.168.0.155/24 dev eth0 scope global } }
启动keepalivedservice keepalived start
启动之后可以用ip add 查看网卡多了一条192.168.0.155的IP
eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 00:0c:29:ff:6c:c7 brd ff:ff:ff:ff:ff:ff
inet 192.168.0.200/24 brd 192.168.0.255 scope global eth0
inet 192.168.0.155/24 scope global secondary eth0
inet6 fe80::20c:29ff:feff:6cc7/64 scope link
valid_lft forever preferred_lft forever
说明keepalived启动成功,配置生效