1.heartbeat
yum install heartbeat-* -y
cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf authkeys haresources /etc/ha.d/
cd /etc/ha.d
vim ha.cf
vim authkeys
vim haresources
chmod 600 authkeys
scp ha.cf authkeys haresources server1:/etc/ha.d
/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 [email protected]:/etc/keepalived/ ##给另一台热备主机拷贝配置文件,注意要改priority值
etc/init.d/keepalived start
测试
一台主机的服务挂掉之后,另一台主机会接替他继续执行服务