heartbeat+lvs+Keepalive

    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

wKiom1l4sEWCx072AAAg2BT7oS0182.png

wKioL1l4sEbRccs9AAASdJCeJR8796.png

wKiom1l4sEaRHWzoAAA6atDQXek422.png

wKioL1l4sEfwOh6JAAAvvFycdpw773.png


   vim authkeys

wKiom1l4sHfizLD6AAATkj00NmQ359.png

  

    vim haresources

wKiom1l4sJXRxgGLAAATyjcujx0152.png

          chmod 600 authkeys

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

   /etc/init.d/heartbeat start

 测试:

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

wKioL1l4sYiSqwfKAAJNUuOrxRA613.png

    

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

wKiom1l4stPj5CcQAABJcG1XvpY309.png

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

wKiom1l4s2iiJauHAAByLI-2ii8884.png

  测试

wKiom1l4s7HgHEwsAAAmWoTGEns094.png

wKioL1l4s7LyEbQBAAAq7_WYXYg104.png

       3.HeartbeatLvs负载均衡

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

   cp ldirectord.cf /etc/ha.d/

   vim ldirectord

wKioL1l4tFXjGkhJAABXc11Jveo335.png

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

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

  vim haresources

wKioL1l4tMSgzxGZAAAPXkVACog195.png

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

  /etc/init.d/heartbeat start

 测试

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

wKiom1l4tSyg2swrAABL1dv2Tek059.png

wKioL1l4tS2i7ByqAAAh8A9RePI621.png

     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/

wKiom1l4u22i327KAACbKMkVSvo147.png

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

   vim keepalived.conf

wKioL1l4utiiCYmgAACmjGzenZ4427.png

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

    etc/init.d/keepalived start

  测试

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

wKioL1l4vBLgMlJ8AADEOtbXnzM173.png

wKiom1l4vBPTRdevAADMPywBCPU323.png

相关文章
相关标签/搜索
本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院