1.heartbeatvim
yum install heartbeat-* -y負載均衡
cd /usr/share/doc/heartbeat-3.0.4/ide
cp ha.cf authkeys haresources /etc/ha.d/測試
cd /etc/ha.dspa
vim ha.cf3d
vim authkeysserver
vim haresourcesblog
chmod 600 authkeys圖片
scp ha.cf authkeys haresources server1:/etc/ha.dip
/etc/init.d/heartbeat start
測試:
一臺主機的服務掛掉以後,另外一臺主機會接替他繼續執行服務
2.Lvs負載均衡
Server1 上
ip addr add 172.25.2.100/24 dev eth0 ##添加vip
ipvsadm -A -t 172.25.2.100:80 -s rr ##設置負載均衡方式爲輪詢
ipvsadm -a -t 172.25.2.100:80 -r 172.25.2.2:80 -g ##設置VIP和RIP
ipvsadm -a -t 172.25.2.100:80 -r 172.25.2.3:80 -g
/etc/init.d/ipvsadm save ##保存設置
Server2 和 server3上
ip addr add 172.25.2.100/32 dev eth0
arptables -A IN -d 172.25.2.100 -j DROP ##直接鏈接IP就丟棄
arptables -A OUT -s 172.25.2.100 -j mangle --mangle-ip-s 172.25.2.2 ##出去的是RIP
/etc/init.d/arptables_jf save ##保存設置
/etc/init.d/arptables_jf start ##開啓服務
測試
3.Heartbeat與Lvs負載均衡
cd /usr/share/doc/ldirectord-3.9.5/
cp ldirectord.cf /etc/ha.d/
vim ldirectord
ipvsadm -C ##刷掉之前的設置
ip addr del 172.25.2.100/24 dev eth0 ##刪除以前設置的VIP
vim haresources
scp haresources ldirectord.cf 172.25.2.4:/etc/ha.d/ ##複製文件到另外一臺熱備主機
/etc/init.d/heartbeat start
測試
Server1的heartbeat中止後,server4做熱備,繼續執行
4.Keepalive
tar -zxf keepalived-1.2.20.tar.gz
cd keepalived-1.2.20l
./configure --prefix=/usr/local/keepalived
make && make install ##安裝服務
scp -r /usr/local/keepalived/ 172.25.2.4:/usr/local/ ##給另外一臺熱備主機複製配置文件
ln -s /usr/local/keepalived/sbin/keepalived /sbin/
ln -s /usr/local/keepalived/etc/keepalived/ /etc/
ln -s /usr/local/keepalived/etc/sysconfig/keepalived /etc/sysconfig/
ln -s /usr/local/keepalived/etc/rc.d/init.d/keepalived /etc/init.d/
chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived
vim keepalived.conf
scp keepalived.conf root@172.25.2.4:/etc/keepalived/ ##給另外一臺熱備主機拷貝配置文件,注意要改priority值
etc/init.d/keepalived start
測試
一臺主機的服務掛掉以後,另外一臺主機會接替他繼續執行服務