heartbeat:主主模式

  • 2017-08-28
  • 43
  • 1
  • 0

1、环境准备


主机名
系统
eth0
eth1
Ha-01
CentOS release 6.9 (Final)
192.168.10.81
192.168.20.11
Ha-02
CentOS release 6.9 (Final)
192.168.10.82
192.168.20.12
heartbeat版本:3.0.4
eth0:对外服务接口
eth1:心跳线直连
架构如图所示:

2、部署


2.1 修改host

两台主机都配置以下主机名:
cat >>/etc/hosts<<eof
192.168.10.81 Ha-01
192.168.10.82 Ha-02
eof

2.1.1 Ha-01测试host

[root@Ha-01 ~]#ping Ha-02
PING Ha-02 (192.168.10.82) 56(84) bytes of data.
64 bytes from Ha-02 (192.168.10.82): icmp_seq=1 ttl=64 time=0.249 ms
64 bytes from Ha-02 (192.168.10.82): icmp_seq=2 ttl=64 time=0.329 ms
^C
--- Ha-02 ping statistics ---
2 packets transmitted, 2 received, 0% packet loss, time 1388ms
rtt min/avg/max/mdev = 0.249/0.289/0.329/0.040 ms

2.1.2 Ha-02测试host

[root@Ha-02 ~]#ping Ha-01
PING Ha-01 (192.168.10.81) 56(84) bytes of data.
64 bytes from Ha-01 (192.168.10.81): icmp_seq=1 ttl=64 time=0.168 ms
64 bytes from Ha-01 (192.168.10.81): icmp_seq=2 ttl=64 time=0.515 ms
64 bytes from Ha-01 (192.168.10.81): icmp_seq=3 ttl=64 time=0.431 ms
^C
--- Ha-01 ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2096ms
rtt min/avg/max/mdev = 0.168/0.371/0.515/0.148 ms

2.2 配置路由

2.2.1 Ha-01配置路由

route add -host 192.168.20.12 dev eth1
echo 'route add -host 192.168.20.12 dev eth1'>>/etc/rc.local

2.2.2 Ha-02配置路由

route add -host 192.168.10.11 dev eth1
echo 'route add -host 192.168.10.11 dev eth1'>>/etc/rc.local

2.3 安装heartbeat

注:需要安装epel,这里用的是中科大的epel。
两台主机均执行以下命令:

yum -y install heartbeat*

两台均执行,复制模板到/etc/had.d/目录下:

cd /usr/share/doc/heartbeat-3.0.4/
cp ha.cf haresources authkeys /etc/ha.d/

 

2.4 配置文件说明

2.4.1 ha.cf文件说明

参数
说明
debugfile /var/log/ha-debug
调试日志存放位置。
logfile /var/log/ha-log
日志存放位置。
logfacility local1
在syslog服务中配置通过local1接收日志。
keepalive 2
指定心跳间隔时间为2秒,即每秒发一次广播。
deadtime 30
若备用节点在30秒内无法收到主节点心跳信号,则接管主节点的资源。
warntime 10
当10秒后备份节点未接收到主节点心跳,则会在日志里写入一个告警,此时不会切换服务。
initdead 120
首次运行后,需要等待120秒才能启动主服务器的任何资源,取值至少为deadtime的两倍,单机启动会遇到VIP绑定很慢,这是因为该值设置长。
bcast eth1
指定心跳在eth1接口上广播,如使用多个网卡,则在后面以空格间隔填入网卡名。
mcast eth1 225.0.0.1 694 1 0
采用udp多播来通知心跳,建议在副节点不只一台时使用,694为端口
auto_failback on
用于当主节点恢复后,是否将服务自动切回。
node Ha-01
主节点的主机名。
node Ha-02
备节点的主机名。
crm no
是否开启集群资源管理功能。

 

2.4.2 authkeys文件说明

Authentication file.  Must be mode 600。   # 权限必须为600
Available methods: crc sha1, md5.  Crc doesn't need/want a key.   # 可以用的认证方式

2.5 参数配置

2.5.1 authkeys配置

两台均执行权限设置:

cd /etc/ha.d/
chmod 600 authkeys 

修改authkeys文件:

cat &amp;gt;&amp;gt;authkeys&amp;lt;&amp;lt;eof
auth 1
1 sha1 hello 
eof

2.5.2 haresources配置

Ha-01:

echo 'Ha-01 IPaddr::192.168.10.91/24/eth0:0' >>haresources
echo 'Ha-02 IPaddr::192.168.10.92/24/eth0:1'>>haresources

Ha-02:

echo 'Ha-02 IPaddr::192.168.10.92/24/eth0:0'>>haresources
echo 'Ha-01 IPaddr::192.168.10.91/24/eth0:1' >>haresources

2.5.3 ha.cf配置

配置文件如下:

debugfile /var/log/ha-debug
logfile	/var/log/ha-log
logfacility	local1

keepalive 2
deadtime 30
warntime 10
initdead 120

#bcast	eth1
mcast eth1 225.0.0.10 694 1 0

auto_failback on
node	Ha-01
node	Ha-02
crm	no

2.6 启动heartbeat

2.6.1 Ha-01启动heartbeat

[root@Ha-01 ha.d]#/etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.
[root@Ha-01 ha.d]#ps -ef|grep heartbeat
root      25424      1  0 15:00 ?        00:00:00 heartbeat: master control process
root      25427  25424  0 15:00 ?        00:00:00 heartbeat: FIFO reader        
root      25428  25424  0 15:00 ?        00:00:00 heartbeat: write: mcast eth1  
root      25429  25424  0 15:00 ?        00:00:00 heartbeat: read: mcast eth1   
root      25432  24981  0 15:00 pts/1    00:00:00 grep --color=auto heartbeat

观察到VIP还没起来:

[root@Ha-01 ha.d]#ip add
1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:1b brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.81/24 brd 192.168.10.255 scope global eth0
    inet6 fe80::20c:29ff:fea8:831b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:25 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.11/24 brd 192.168.20.255 scope global eth1
    inet6 fe80::20c:29ff:fea8:8325/64 scope link 
       valid_lft forever preferred_lft forever

过了一会儿,VIP起来了,但同时起了两个VIP:

[root@Ha-01 ha.d]#ip add
1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:1b brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.81/24 brd 192.168.10.255 scope global eth0
    inet 192.168.10.92/24 brd 192.168.10.255 scope global secondary eth0
    inet 192.168.10.91/24 brd 192.168.10.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fea8:831b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:25 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.11/24 brd 192.168.20.255 scope global eth1
    inet6 fe80::20c:29ff:fea8:8325/64 scope link 
       valid_lft forever preferred_lft forever

2.6.2 Ha-02启动heartbeat

[root@Ha-02 ha.d]#/etc/init.d/heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
INFO:  Resource is stopped
Done.

显示VIP10.92已经起来:

[root@Ha-02 ha.d]#ip add
1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ba:d7:c5 brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.82/24 brd 192.168.10.255 scope global eth0
    inet 192.168.10.92/24 brd 192.168.10.255 scope global secondary eth0
    inet6 fe80::20c:29ff:feba:d7c5/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:ba:d7:cf brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.12/24 brd 192.168.20.255 scope global eth1
    inet6 fe80::20c:29ff:feba:d7cf/64 scope link 
       valid_lft forever preferred_lft forever

再看Ha-01:

[root@Ha-01 ha.d]#ip add
1: lo: &amp;lt;LOOPBACK,UP,LOWER_UP&amp;gt; mtu 65536 qdisc noqueue state UNKNOWN 
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
       valid_lft forever preferred_lft forever
2: eth0: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:1b brd ff:ff:ff:ff:ff:ff
    inet 192.168.10.81/24 brd 192.168.10.255 scope global eth0
    inet 192.168.10.91/24 brd 192.168.10.255 scope global secondary eth0
    inet6 fe80::20c:29ff:fea8:831b/64 scope link 
       valid_lft forever preferred_lft forever
3: eth1: &amp;lt;BROADCAST,MULTICAST,UP,LOWER_UP&amp;gt; mtu 1500 qdisc pfifo_fast state UP qlen 1000
    link/ether 00:0c:29:a8:83:25 brd ff:ff:ff:ff:ff:ff
    inet 192.168.20.11/24 brd 192.168.20.255 scope global eth1
    inet6 fe80::20c:29ff:fea8:8325/64 scope link 
       valid_lft forever preferred_lft forever

评论