huazhi 发表于 2019-1-7 10:43:10

heartbeat的使用案例与图形化配置

http://linusworld.blog.运维网.com/attachment/201109/132427489.png
此例子是在做实验时写的,如果是实际应用应当在VIP上使用公网ip即可

案例: node1:
            网卡1:桥接
            网卡2:vm-5
            eth0:10.0.0.11/8 static
               eth1:192.168.0.11/24
         编辑/etc/hosts添加如下两行
             172.16.100.21 node1.a.org node1
               172.16.100.22 node2.a.org node2
            
               
          编辑主机名 在/etc/sysconfig/network中添加如HOSTNAME=node1.a.org
               
               # hostname node1.a.org
                  ssh-keygen -t rsa
                ssh-copy-id -i .ssh/id_rsa.pub root@node2.a.org
                yum install httpd
               echo "node1" >/var/www/html/index.html
                   service httpd start//这里启动,验证httpd是否正常启动
                  service httpd stop
                  chkconfig httpd off
            安装如下rpm包:
                yum -y installheartbeat-2.1.4-9.el5.i386 heartbeat-devel-2.1.4-9.el5.i386   heartbeat-gui-2.1.4-9.el5.i386    heartbeat-pils-2.1.4-10.el5.i386   heartbeat-stonith-2.1.4-10.el5.i386 libnet-1.1.4-3.el5.i386--nogpgcheck
                cd /usr/share/doc/heartbeat-2.1.4/
               cp ha.cf haresources authkeys /etc/ha.d/
               cd /etc/ha.d/
    编辑配置文件:   在ha.cf 中加入 下面三行bcast eth1
                                 node node1.a.org
                                 node node2.a.org
         dd if=/dev/urandom bs=512 count=1 | md5sum//生成随机数
      在 authkeys 中加入auth 2
                        2 上面的随机数
            
             chmod 400 authkeys
    在 haresources 加入 node1.a.org 172.16.100.1/16/eth0/172.18.255.255 httpd
      
            scp haresources node2:/etc/ha.d
            /etc/init.d/heartbeat start
               ssh node2 --'/etc/init.d/heartbeat start'
            
netstat -tnl
             node2:
            网卡1:桥接
            网卡2:vm-5
               eth0:10.0.0.12/8 static
                   eth1:192.168.0.12/24   
            编辑/etc/hosts添加如下两行
             172.16.100.21 node1.a.org node1
               172.16.100.22 node2.a.org node2
                  
          编辑主机名 在/etc/sysconfig/network中添加如HOSTNAME=node1.a.org
               
               # hostname node1.a.org
               
                ssh-keygen -t rsa
                ssh-copy-id -i .ssh/id_rsa.pub root@node1.a.org
                   yum install httpd
               echo "node2" >/var/www/html/index.html
                  service httpd start
                  service httpd stop
                  chkconfig httpd off
          安装如下rpm包:
                yum -y installheartbeat-2.1.4-9.el5.i386 heartbeat-devel-2.1.4-9.el5.i386   heartbeat-gui-2.1.4-9.el5.i386    heartbeat-pils-2.1.4-10.el5.i386   heartbeat-stonith-2.1.4-10.el5.i386 libnet-1.1.4-3.el5.i386--nogpgcheck
   ssh node1 -- '/etc/init.d/heartbeat stop'
测试:1.node1:netstat -tnl
      node2:netstat -tnl 看看是否启用80端口
      http://10.0.0.10 看结果是否显示node1
      2.ssh node1 -- '/etc/init.d/heartbeat stop'
          http://10.0.0.10 看结果是否显示node2
      3. 资源转移: cd /usr/lib/heartbeat
            ./hb_standby
             ifconfig
             ./hb_takeover
            可以用http://10.0.0.10 看结果验证故障转移

图形化配置:

该配置应该在DC上配置:
service heartbeat stop
编辑/etc/ha.d/ha.cf 添加crm respawn
cd /usr/lib/heartbeat
./haresourcescib.py /etc/ha.d/haresources ###这里将haresources文件转换为XML文件,存放为/var/lib/heartbeat/crm/cib.xml
mv /etc/ha.d/haresources /etc/ha.d/haresources.bak#####因为v2 style会自动创建haresources
./hb_propagate
scp /var/lib/heartbeat/crm/cib.xml node2:/var/lib/heartbeat/crm
passwd hacluster
hb_gui &







页: [1]
查看完整版本: heartbeat的使用案例与图形化配置