heartbeat安装与配置

发布时间:2015-09-17 16:01:25 阅读:1042次

转:http://blog.chinaunix.net/uid-25452915-id-3224246.html

http://www.admin5.com/article/20130825/521633.shtml

http://www.360doc.com/content/12/0308/16/2660674_192777008.shtml

http://blog.chinaunix.net/uid-16728139-id-3260466.html 用Heartbeat配置Linux高可用性集群

http://xuwensong.elastos.org/2013/11/27/linux%E4%B8%8B%E5%9F%BA%E4%BA%8Eheartbeat-%E5%8F%8C%E6%9C%BA%E7%83%AD%E5%A4%87%E4%B9%8B%E9%85%8D%E7%BD%AE%E8%AF%A6%E8%A7%A3/

Linux下基于HeartBeat 双机热备之配置详解

重启主自动接管

实践

apt-get install heartbeat

root@test-VirtualBox:/etc/ha.d# ifconfig
eth0   Link encap:以太网  硬件地址 08:00:27:f6:59:a1
          inet 地址:10.77.50.68  广播:10.77.50.255  掩码:255.255.255.0
          inet6 地址: fe80::a00:27ff:fef6:59a1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1
          接收数据包:361083 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:176164 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000
          接收字节:137127950 (137.1 MB)  发送字节:76501570 (76.5 MB)
lo        Link encap:本地环回
          inet 地址:127.0.0.1  掩码:255.0.0.0
          inet6 地址: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  跃点数:1
          接收数据包:16497 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:16497 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:0
          接收字节:6756252 (6.7 MB)  发送字节:6756252 (6.7 MB)

root@test-VirtualBox:/etc/ha.d# uname -n
test-VirtualBox

root@test-VirtualBox:/etc/ha.d# cat ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 5
udpport 694
bcast eth0
auto_failback on
node test-virtualbox   //一台电脑的主机名
node db3                   //另一台电脑的主机名

root@test-VirtualBox:/etc/ha.d# cat authkeys
auth 1
1 sha1 ok

root@test-VirtualBox:/etc/ha.d# cat haresources
test-virtualbox  IPaddr::10.77.50.118/24/eth0

root@test-VirtualBox:/etc/ha.d# service heartbeat restart
Stopping High-Availability services: Done.
Waiting to allow resource takeover to complete:Done.
Starting High-Availability services: IPaddr[17957]: INFO:  Resource is stopped
Done.
root@test-VirtualBox:/etc/ha.d# ifconfig
eth0      Link encap:以太网  硬件地址 08:00:27:f6:59:a1
          inet 地址:10.77.50.68  广播:10.77.50.255  掩码:255.255.255.0
          inet6 地址: fe80::a00:27ff:fef6:59a1/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1
          接收数据包:363420 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:177224 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:1000
          接收字节:137349275 (137.3 MB)  发送字节:76593961 (76.5 MB)
eth0:0    Link encap:以太网  硬件地址 08:00:27:f6:59:a1
          inet 地址:10.77.50.118  广播:10.77.50.255  掩码:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  跃点数:1
lo        Link encap:本地环回
          inet 地址:127.0.0.1  掩码:255.0.0.0
          inet6 地址: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  跃点数:1
          接收数据包:16535 错误:0 丢弃:0 过载:0 帧数:0
          发送数据包:16535 错误:0 丢弃:0 过载:0 载波:0
          碰撞:0 发送队列长度:0

          接收字节:6758652 (6.7 MB)  发送字节:6758652 (6.7 MB)

[root@db3 ha.d]# ifconfig
eth0   Link encap:Ethernet  HWaddr 00:24:81:83:AD:C7
          inet addr:10.77.50.111  Bcast:10.77.50.255  Mask:255.255.255.0
          inet6 addr: fe80::224:81ff:fe83:adc7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:251711746 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158376572 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:114223977068 (106.3 GiB)  TX bytes:86048140952 (80.1 GiB)
          Interrupt:50
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:24713432 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24713432 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:13019412520 (12.1 GiB)  TX bytes:13019412520 (12.1 GiB)

[root@db3 ha.d]# uname -n
db3

[root@db3 ha.d]# pwd
/etc/ha.d
[root@db3 ha.d]# ls
authkeys  ha.cf  harc  haresources  rc.d  README.config  resource.d  shellfuncs
[root@db3 ha.d]# cat ha.cf
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2
deadtime 5
udpport 694
bcast eth0
auto_failback on
node test-VirtualBox //主
node db3 //从
[root@db3 ha.d]# cat authkeys
auth 1
1 sha1 ok.
[root@db3 ha.d]# cat haresources

db3 IPaddr::10.77.50.118/24/eth0

root@test-VirtualBox:/etc/ha.d# ps aux|grep heartbeat
root     18013  0.0  1.0   5520  5480 ?        SLs  16:05   0:00 heartbeat: master control process
root     18016  0.0  1.0   5352  5348 ?        SL   16:05   0:00 heartbeat: FIFO reader
root     18017  0.0  1.0   5348  5344 ?        SL   16:05   0:00 heartbeat: write: bcast eth0
root     18018  0.0  1.0   5348  5344 ?        SL   16:05   0:00 heartbeat: read: bcast eth0
root     18359  0.0  0.1   5812   844 pts/2    S+   16:12   0:00 grep --color=auto heartbeat
root@test-VirtualBox:/etc/ha.d# kill -9 18013
root@test-VirtualBox:/etc/ha.d# ps aux|grep heartbeat
root     18361  0.0  0.1   5812   844 pts/2    S+   16:12   0:00 grep --color=auto heartbeat
[root@db3 ha.d]# service heartbeat restart
Stopping High-Availability services:
                                                           [  OK  ]
Waiting to allow resource takeover to complete:
                                                           [  OK  ]
Starting High-Availability services:
2015/09/17_16:21:39 INFO:  Running OK
2015/09/17_16:21:39 CRITICAL: Resource IPaddr::10.77.50.118/24/eth0 is active, and should not be!
2015/09/17_16:21:39 CRITICAL: Non-idle resources can affect data integrity!
2015/09/17_16:21:39 info: If you don't know what this means, then get help!
2015/09/17_16:21:39 info: Read the docs and/or source to /usr/share/heartbeat/ResourceManager for more details.
CRITICAL: Resource IPaddr::10.77.50.118/24/eth0 is active, and should not be!
CRITICAL: Non-idle resources can affect data integrity!
info: If you don't know what this means, then get help!
info: Read the docs and/or the source to /usr/share/heartbeat/ResourceManager for more details.
2015/09/17_16:21:39 CRITICAL: Non-idle resources will affect resource takeback!
2015/09/17_16:21:39 CRITICAL: Non-idle resources may affect data integrity!
                                                           [  OK  ]
[root@db3 ha.d]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:24:81:83:AD:C7
          inet addr:10.77.50.111  Bcast:10.77.50.255  Mask:255.255.255.0
          inet6 addr: fe80::224:81ff:fe83:adc7/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:251717539 errors:0 dropped:0 overruns:0 frame:0
          TX packets:158379136 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:114224585597 (106.3 GiB)  TX bytes:86048422678 (80.1 GiB)
          Interrupt:50
eth0:0    Link encap:Ethernet  HWaddr 00:24:81:83:AD:C7
          inet addr:10.77.50.118  Bcast:10.77.50.255  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:50
lo        Link encap:Local Loopback
          inet addr:127.0.0.1  Mask:255.0.0.0
          inet6 addr: ::1/128 Scope:Host
          UP LOOPBACK RUNNING  MTU:16436  Metric:1
          RX packets:24713432 errors:0 dropped:0 overruns:0 frame:0
          TX packets:24713432 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:13019412520 (12.1 GiB)  TX bytes:13019412520 (12.1 GiB)

由于在CentOS 6 (6.0以及6.2)上没有找到Linux Heartbeat的源,所以最终选择在Ubuntu 8.04上安装。

     假设两个节点分别为node1和node2(运行uname -n 命令可以察看本机的名字),node1的ip为192.168.164.116,node2的ip为192.168.164.117,它们公用的ip为192.168.164.118,具体安装与配置过程如下:
注:这些配置文件的内容在node1和node2中完全一样,而且node1和node2都要配置。
1、配置hosts文件(vim /etc/hosts):

点击(此处)折叠或打开

  1. 192.168.164.116  node1
  2. 192.168.164.117  node2
2、安装heartbeat:
运行一下命令:

点击(此处)折叠或打开

  1. sudo apt-get install heartbeat
3、配置ha.cf文件:
运行以下命令:

点击(此处)折叠或打开

  1. gunzip /usr/share/doc/heartbeat/ha.cf.gz
  2. cp /usr/share/doc/heartbeat/ha.cf /etc/ha.d/
  3. cd /etc/ha.d
  4. vim /etc/ha.d/ha.cf
然后编辑ha.cf文件,内容如下:

点击(此处)折叠或打开

  1. debugfile /var/log/ha-debug
  2. logfile /var/log/ha-log
  3. logfacility local0
  4. keepalive 2
  5. deadtime 5
  6. udpport 694
  7. bcast eth1
  8. auto_failback on
  9. node node1
  10. node node2
其中eth1要根据读者自己的环境进行相应的替换。
4、配置authkeys文件:
运行如下命令:

点击(此处)折叠或打开

  1. vim /etc/ha.d/authkeys
然后修改authkeys中的内容:

点击(此处)折叠或打开

  1. auth 1
  2. 1 sha1 ok.
5、配置haresources文件:

点击(此处)折叠或打开

  1. vim /etc/ha.d/haresources
然后修改haresources的内容:

点击(此处)折叠或打开

  1. node1 IPaddr::192.168.164.118/24/eth1
6、测试
在node1和node2中分别运行一下命令:

点击(此处)折叠或打开

  1. sudo /etc/init.d/heartbeat start
然后在node1中运行:

点击(此处)折叠或打开

  1. ifconfig
结果如下:
同理在node2行:

点击(此处)折叠或打开

  1. ifconfig
结果如下:
然后在node2中运行如下命令:

点击(此处)折叠或打开

  1. sudo /etc/init.d/heartbeat stop
再在node1中运行:

点击(此处)折叠或打开

  1. ifconfig
结果如下:
在node2中运行:

点击(此处)折叠或打开

  1. ifconfig
结果如下:
7、注意事项
1、/etc/hosts要把前面添加的条目放在最前面,即避免系统默认的127.0.0.1  node*干扰我们添加的条目,否则会出现两个节点同时拥有备用ip的错误;
2、如果在/var/log/ha-log中看到错误:ERROR: Return code 1 from /etc/ha.d/resource.d/IPaddr
   可能是/etc/ha.d/haresources配置的不正确(如:node1 IPaddr::192.168.164.118),改成node1 IPaddr::192.168.164.118/24/eth1即可。

如有问题,可以QQ搜索群1028468525加入群聊,欢迎一起研究技术

支付宝 微信

有疑问联系站长,请联系QQ:QQ咨询

转载请注明:heartbeat安装与配置 出自老鄢博客 | 欢迎分享