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

heartbeat+lvs+Keepalive_Linux

heartbeat+lvs+Keepalive_lvs_02

heartbeat+lvs+Keepalive_Linux_03

heartbeat+lvs+Keepalive_Linux_04


   vim authkeys

heartbeat+lvs+Keepalive_Linux_05

  

    vim haresources

heartbeat+lvs+Keepalive_lvs_06

          chmod 600 authkeys

   scp ha.cf authkeys haresources server1:/etc/ha.d

   /etc/init.d/heartbeat start

 测试:

  一台主机的服务挂掉之后,另一台主机会接替他继续执行服务

heartbeat+lvs+Keepalive_lvs_07

    

      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    ##保存设置

heartbeat+lvs+Keepalive_Linux_08

    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   ##开启服务

heartbeat+lvs+Keepalive_lvs_09

  测试

heartbeat+lvs+Keepalive_Linux_10

heartbeat+lvs+Keepalive_lvs_11

       3.HeartbeatLvs负载均衡

  cd /usr/share/doc/ldirectord-3.9.5/

   cp ldirectord.cf /etc/ha.d/

   vim ldirectord

heartbeat+lvs+Keepalive_Linux_12

  ipvsadm -C   ##刷掉以前的设置

  ip addr del 172.25.2.100/24 dev eth0  ##删除之前设置的VIP

  vim haresources

heartbeat+lvs+Keepalive_lvs_13

  scp haresources ldirectord.cf 172.25.2.4:/etc/ha.d/   ##复制文件到另一台热备主机

  /etc/init.d/heartbeat start

 测试

 Server1的heartbeat停止后,server4作热备,继续执行

heartbeat+lvs+Keepalive_lvs_14

heartbeat+lvs+Keepalive_lvs_15

     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/

heartbeat+lvs+Keepalive_Linux_16

   chmod +x /usr/local/keepalived/etc/rc.d/init.d/keepalived

   vim keepalived.conf

heartbeat+lvs+Keepalive_Linux_17

   scp keepalived.conf root@172.25.2.4:/etc/keepalived/   ##给另一台热备主机拷贝配置文件,注意要改priority值

    etc/init.d/keepalived start

  测试

  一台主机的服务挂掉之后,另一台主机会接替他继续执行服务

heartbeat+lvs+Keepalive_Linux_18

heartbeat+lvs+Keepalive_lvs_19