本文示範以兩台 CentOS 6.5 建置 Keepalived 主從熱備,並搭配 VIP 提供高可用性服務。
主服務器:192.168.100.150;從服務器:192.168.100.151;VIP:192.168.100.95。
yum -y install kernel-devel openssl-devel popt-devel ipvsadm tar zxvf keepalived-1.2.13.tar.gz -C /usr/src/ cd /usr/src/keepalived-1.2.13/ ./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/ make && make install chkconfig --add keepalived chkconfig keepalived on
global_defs {
router_id HA_TEST_R1
}
vrrp_instance VI_1 {
state MASTER
interface eth0
virtual_router_id 1
priority 100
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.95
}
}global_defs {
router_id HA_TEST_R2
}
vrrp_instance VI_1 {
state BACKUP
interface eth0
virtual_router_id 1
priority 99
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.95
}
}/etc/init.d/keepalived start ip addr show dev eth0
主從節點均可啟用 httpd 與 vsftpd。測試時可禁用主節點網卡,確認 VIP 是否漂移,並檢查 /var/log/messages 中的 VRRP 切換紀錄。