部署前准備:
iptables和selinux沒配置,關掉
掛載系統鏡像作為本地yum源,修改yum文件
源碼包准備keepalived-1.2.13.tar.gz
環境介紹:
2台centos6.5虛擬機,主服務器ip:192.168.100.150;從服務器ip:192.168.100.151;集群vip:192.168.100.95
1.安裝keepalived(主從上都需要安裝)
yum -y install kernel-devel openssl-devel popt-devel ipvsadm
tar zxvf keepalived-1.2.2.tar.gz -C /usr/src/
cd /usr/src/keepalived-1.2.2/
./configure --prefix=/ --with-kernel-dir=/usr/src/kernels/2.6.32-431.el6.x86_64/
make &&make install
chkconfig --add keepalived
chkconfig keepalived on
2.配置HA
主配置:(192.168.100.150上操作)
cd /etc/keepalived/
mv keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
global_defs {
router_id HA_TEST_R1 ##本服務器的名稱
}
vrrp_instance VI_1 { ##定義VRRP熱備實例
state MASTER ##MASTER表示主服務器
interface eth0 ##承載VIP地址的物理接口
virtual_router_id 1 ##虛擬路由器的ID號
priority 100 ##優先級,數值越大優先級越高
advert_int 1 ##通告間隔秒數(心跳頻率)
authentication { ##認證信息
auth_type PASS ##認證類型
auth_pass 123456 ##密碼字串
}
virtual_ipaddress {
192.168.100.95 ##指定漂移地址(VIP)
}
}
:wq
從配置:(192.168.100.151上操作)
cd /etc/keepalived/
mv keepalived.conf keepalived.conf.bak
vi /etc/keepalived/keepalived.conf
global_defs {
router_id HA_TEST_R2 ##本服務器的名稱
}
vrrp_instance VI_1 {
state BACKUP ##SLAVE表示從服務器
interface eth0
virtual_router_id 1
priority 99 ##優先級,低於主服務器
advert_int 1
authentication {
auth_type PASS
auth_pass 123456
}
virtual_ipaddress {
192.168.100.95
}
}
:wq
3.啟動服務及應用服務:
1)啟動keepalived:
/etc/init.d/keepalived start
ip addr show dev eth0 ##驗證vip是否在主服務器上
2)主、備機均啟用FTP、Web服務,內容相同
yum -y install httpd vsftpd
/etc/init.d/vsftpd restart
/etc/init.d/httpd restart
chkconfig vsftpd on
chkconfig httpd on
4.測試雙機熱備的效果
先後禁用、啟用主服務器的網卡,執行以下測試
cat /var/log/messages
測試1:使用ping檢測192.168.100.95的連通性
測試2:訪問ftp://192.168.100.95,確認可用性及內容變化
測試3:訪問http://192.168.100.95/,確認可用性及內容變化
測試4:查看日志文件/var/log/messages中的變化
本文出自 “LP-linux” 博客,請務必保留此出處http://linuxlp.blog.51cto.com/11463376/1773635