一、基础配置

1、hostnamectl set-hostname node1 (node2)

2、[root@node1 ~]# cat /etc/hosts
     192.168.40.128 node1
     192.168.40.129 node2

3、添加路由

node1# vim  /etc/rc.local

/sbin/route add -host 192.168.40.132 dev ens33 (对方)

防火墙和selinux关闭,互相ping通
4、创建用户和组

groupadd haclient

useradd -g haclient hacluster

5、源码安装过程如上一篇主从

6、配置网卡支持插件文件

#mkdir -pv /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/

#cp   /usr/lib/ocf/lib/heartbeat/ocf-*   /usr/local/heartbeat/usr/lib/ocf/lib/heartbeat/

#注意:一般启动时会报错因为 ping和ucast这些配置都需要插件支持 需要将lib64下面的插件软连接到lib目录 才不会抛出异常

#ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/RAExec/*   /usr/local/heartbeat/lib/heartbeat/plugins/RAExec/

#ln -svf /usr/local/heartbeat/lib64/heartbeat/plugins/*  /usr/local/heartbeat/lib/heartbeat/plugins/

#拷贝三个模版配置文件到 /usr/local/heartbeat/etc/ha.d 目录下

cp /root/Heartbeat-3-0-958e11be8686/doc/{ha.cf,haresources,authkeys} /usr/local/heartbeat/etc/ha.d/

7、#更改权限为600(两个机子都做)

chmod 600 /usr/local/heartbeat/etc/ha.d/authkeys

二、node1机子(具体参数解释自行百度)

[root@node1 ~]# cd /usr/local/heartbeat/etc/ha.d/
[root@node1 ha.d]#  cat ha.cf |egrep -v "^#|^$"  (-v取反)
debugfile /var/log/ha-debug
logfile    /var/log/ha-log
logfacility    local1
keepalive 2
deadtime 15
warntime 10
initdead 60
udpport    694
ucast ens33 192.168.40.211  (与node2唯一不同的点)
auto_failback on
node    node1
node    node2

[root@node1 ha.d]#  cat haresources |egrep -v "^#|^$"
node1   IPaddr::192.168.40.222/24/ens33  
node2   IPaddr::192.168.40.223/24/ens33

[root@node1 ha.d]#  cat authkeys |egrep -v "^#|^$"
auth 1
1 crc

三、node2机子

[root@node2 ~]# cd /usr/local/heartbeat/etc/ha.d/

[root@node2 ha.d]# cat ha.cf |egrep -v "^#|^$"
debugfile /var/log/ha-debug
logfile    /var/log/ha-log
logfacility    local1
keepalive 2
deadtime 15
warntime 10
initdead 60
udpport    694
ucast ens33 192.168.40.132  (对方心跳线)
auto_failback on
node    node1
node    node2

[root@node2 ha.d]# cat haresources |egrep -v "^#|^$"
node1   IPaddr::192.168.40.222/24/ens33  
node2   IPaddr::192.168.40.223/24/ens33

[root@node2 ha.d]# cat authkeys |egrep -v "^#|^$"
auth 1
1 crc

四、测试结果

[root@node1 ~]# curl http://192.168.40.222
node1
[root@node1 ~]# curl http://192.168.40.223
node2
[root@node1 ~]# /usr/local/heartbeat/share/heartbeat/hb_standby  (模拟node1坏掉)
Going standby [all].
[root@node1 ~]# curl http://192.168.40.223
node2
[root@node1 ~]# curl http://192.168.40.222(虚拟ip222转移到node2)
node2
[root@node1 ~]# /usr/local/heartbeat/share/heartbeat/hb_takeover local  (虚拟ip回到node1)
[root@node1 ~]# curl http://192.168.40.222
node1
[root@node1 ~]# curl http://192.168.40.223
node2

五、小结

1、之前用一个虚拟ip,haresources配置文件里就一个 node1   IPaddr::192.168.40.222   apache::/etc/httpd/conf/httpd.conf

就一直报错 apache(apache_//usr/sbin/httpd)[1845]:    2019/10/06_23:38:35 INFO: waiting for apache //usr/sbi
apache(apache_//usr/sbin/httpd)[1845]:    2019/10/06_23:38:36 INFO: apache not running  解决办法:如上面的配置
2、另外感觉配置都没错,试试重启虚拟机
3、http起不来

[root@node1 ~]# ss -anpt |grep 80
LISTEN     0      128         :::80                      :::*                   users:(("httpd39,fd=8),("httpd",pid=1538,fd=8),("httpd",pid=1537,fd=8),("httpd",pid=1536,fd=8),("httpd",pid=8))
[root@node1 ~]# kill 1534
[root@node1 ~]# kill 1538
[root@node1 ~]# kill 1536
[root@node1 ~]# ss -anpt |grep 80
[root@node1 ~]# systemctl start httpd

05-23 06:02