keepalived01:雙網卡伺服器雙機熱備 01keepalived雙網卡伺服器雙機熱備02 03環境:04 master: eth0(192.168.0.100/24) eth1(10.0.0.100/24)05 backup: eth0(192.168.0.200/24) eth1(10.0.0.200/24)06 07軟體安裝:08 安裝依賴:09 yum install ipvsadm kernel-devel openssl-devel popt-devel \10 libnl-devel gcc make -y11 解壓編譯:12 tar zxf keepalived-1.2.7.tar.gz13 cd keepalived-1.2.714 ./configure --prefix=/usr/local/keepalived15 make && make install16 做連結:17 ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/18 ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/19 ln -s /usr/local/keepalived/etc/keepalived/ /etc/20 ln -s /usr/local/keepalived/sbin/keepalived /usr/sbin/21 備份設定檔:22 cp /etc/keepalived/keepalived.conf /etc/keepalived/keepalived.conf.bak23 添加使用者:24 useradd keepalived25 26修改配置:27 vi /etc/keepalived/keepalived.conf28###############################################################29! Configuration File for keepalived30 31global_defs {32 notification_email {33 oscersong007@gmail.com34 }35 notification_email_from keepalived@localhost36 smtp_server 127.0.0.137 smtp_connect_timeout 3038 router_id LVS_DEVEL39}40vrrp_sync_group VGM {41 group {42 VI_143 }44}45vrrp_instance VI_1 {46 state MASTER #BACKUP47 interface eth048 virtual_router_id 5149 priority 100 #5050 advert_int 151 authentication {52 auth_type PASS53 auth_pass westos54 }55 track_interface {56 eth057 eth158 }59 virtual_ipaddress {60 192.168.0.150/24 dev eth061 10.0.0.150/24 dev eth162 }63}64 65###############################################################66 67啟動服務測試:68 tail -f /var/log/message69 /etc/init.d/keepalived start(master,backup)70 master的測試頁面“MASTER”,backup的測試頁面“BACKUP”71 72master,backup的keepalived都啟動時在backup端測試:73[root@backup ~]# curl http://192.168.0.15074MASKTER75[root@backup ~]# curl http://10.0.0.15076MASKTER77將master的eht1 down掉後在backup端測試:78[root@backup ~]# curl http://192.168.0.15079BACKUP80[root@backup ~]# curl http://10.0.0.15081BACKUP