Heartbeat详解

转自:http://blog.sina.com.cn/s/blog_7b6fc4c901012om0.html

配置主节点的Heartbeat

 

 

Heartbeat的主要配置文件有ha.cf、haresources和authkeys。在Heartbeat安装后,默认并没有这3个文件, 可以从官方网站下载得到,也可以直接从解压的源码目录中找到。在上面的安装过程中,我们已经将这3个文件放到了/etc/ha.d目录下,下面分别详细介 绍。

1.主配置文件(/etc/ha.d/ha.cf)

下面对ha.cf文件的每个选项进行详细介绍,其中"#"号后面的内容是对选项的注释说明。

  1. #debugfile /var/log/ha-debug  
  2. logfile /var/log/ha-log     #指名heartbeat的日志存放位置。  
  3. #crm yes                    #是否开启Cluster Resource Manager(集群资源管理)功能。  
  4. bcast eth1              #指明心跳使用以太网广播方式,并且是在eth1接口上进行广播。  
  5. keepalive 2             #指定心跳间隔时间为2秒(即每2秒钟在eth1上发送一次广播)。  
  6. deadtime 30 #指定若备用节点在30秒内没有收到主节点的心跳信号,则立即接管主节点的服务资源。  
  7. warntime 10 #指定心跳延迟的时间为10秒。当10秒钟内备份节点不能接收到主节点的 心跳信号时,就会往日志中写入一个警告日志,但此时不会切换服务。  
  8. initdead 120    #在某些系统上,系统启动或重启之后需要经过一段时间网络才 能正常工作,该选项用于解决这种情况产生的时间间隔。取值至少为deadtime的两倍。  
  9. udpport 694             #设置广播通信使用的端口,694为默认使用的端口号。  
  10. baud 19200              #设置串行通信的波特率。  
  11. #serial /dev/ttyS0      #选择串行通信设备,用于双机使用串口线连接的情况。 如果双机使用以太网连接,则应该关闭该选项。  
  12. #ucast eth0 192.168.1.2 #采用网卡eth0的udp单播来组织心跳,后面跟的 IP地址应为双机对方的IP地址。  
  13. #mcast eth0 225.0.0.1 694 1 0   #采用网卡eth0的Udp多播来组织心跳, 一般在备用节点不止一台时使用。Bcast、ucast和mcast分别代表广播、单播 和多播,是组织心跳的三种方式,任选其一即可。  
  14. auto_failback on    #用来定义当主节点恢复后,是否将服务自动切回。 heartbeat的两台主机分别为主节点和备份节点。主节点在正常情况下占用资源 并运行所有的服务,遇到故障时把资源交给备份节点并由备份节点运行服务。在该 选项设为on的情况下,一旦主节点恢复运行,则自动获取资源并取代备份节点; 如果该选项设置为off,那么当主节点恢复后,将变为备份节点,而原来的备份节点成为主节点。  
  15. #stonith baytech /etc/ha.d/conf/stonith.baytech     # stonith的主 要作用是使出现问题的节点从集群环境中脱离,进而释放集群资源,避免两个节点争 用一个资源的情形发生。保证共享数据的安全性和完整性。  
  16. #watchdog /dev/watchdog #该选项是可选配置,是通过Heartbeat来监控系统的运 行状态。使用该特性,需要在内核中载入"softdog"内核模块,用来生成实际的设备文件, 如果系统中没有这个内核模块,就需要指定此模块,重新编译内核。编译完成输入 "insmod softdog"加载该模块。然后输入"grep misc /proc/devices"(应为10), 输入"cat /proc/misc |grep watchdog"(应为130)。最后,生成设备文件: "mknod /dev/watchdog c 10 130" 。即可使用此功能。  
  17. node node1              #主节点主机名,可以通过命令"uanme -n"查看。  
  18. node node2              #备用节点主机名。  
  19. ping 192.168.60.1   #选择ping的节点,ping节点选择的越好,HA集群就越强壮, 可以选择固定的路由器作为ping节点,但是最好不要选择集群中的成员作为ping节点, ping节点仅仅用来测试网络连接。  
  20. respawn hacluster /usr/lib/heartbeat/ipfail #该选项是可选配置,列出与 heartbeat一起启动和关闭的进程,该进程一般是和heartbeat集成的插件,这些进程 遇到故障可以自动重新启动。最常用的进程是ipfail,此进程用于检测和处理网络故障, 需要配合ping语句指定的ping node来检测网络的连通性。其中hacluster表示启动ipfail进程的身份。 

 

2.资源文件(/etc/ha.d/haresources)

Haresources文件用于指定双机系统的主节点、集群IP、子网掩码、广播地址以及启动的服务等集群资源,文件每一行可以包含一个或多个资源脚本名,资源之间使用空格隔开,参数之间使用两个冒号隔开,在两个HA节点上该文件必须完全一致,此文件的一般格式为:

扫描二维码关注公众号,回复: 3736532 查看本文章
  1. node-name network  <resource-group> 

node-name表示主节点的主机名,必须和ha.cf文件中指定的节点名一致。network用于设定集群的IP地址、子网掩码和网络设备标识 等。需要注意的是,这里指定的IP地址就是集群对外服务的IP地址,resource-group用来指定需要Heartbeat托管的服务,也就是这些 服务可以由Heartbeat来启动和关闭。如果要托管这些服务,就必须将服务写成可以通过start/stop来启动和关闭的脚步,然后放到/etc /init.d/或者/etc/ha.d/resource.d/目录下,Heartbeat会根据脚本的名称自动去/etc/init.d或者/etc /ha.d/resource.d/目录下找到相应脚步进行启动或关闭操作。

下面对配置方法进行具体说明:

  1. node1 IPaddr::192.168.60.200/24/eth0/  Filesystem:: /dev/sdb5::/webdata::ext3  httpd tomcat 

其中,node1是HA集群的主节点,IPaddr为heartbeat自带的一个执行脚 步,Heartbeat首先将执行/etc/ha.d/resource.d/IPaddr 192.168.60.200/24 start的操作,也就是虚拟出一个子网掩码为255.255.255.0,IP为192.168.60.200的地址。此IP为Heartbeat对外 提供服务的网络地址,同时指定此IP使用的网络接口为eth0。接着,Heartbeat将执行共享磁盘分区的挂载操 作,"Filesystem::/dev/sdb5::/webdata::ext3"相当于在命令行下执行mount操作,即"mount -t ext3 /dev/sdb5 /webdata",最后依次启动httpd和Tomcat服务。

注意 主节点和备份节点中资源文件haresources要完全一样。

3.认证文件(/etc/ha.d/authkeys)

authkeys文件用于设定Heartbeat的认证方式,共有3种可用的认证方式,即 crc、md5和sha1。3种认证方式的安全性依次提高,但是占用的系统资源也依次增加。如果Heartbeat集群运行在安全的网络上,可以使用 crc方式;如果HA每个节点的硬件配置很高,建议使用sha1,这种认证方式安全级别最高;如果是处于网络安全和系统资源之间,可以使用md5认证方 式。这里我们使用crc认证方式,设置如下:

  1. auth 1  
  2. 1 crc  
  3. #2 sha1 sha1_any_password  
  4. #3 md5 md5_any_password 

需要说明的一点是:无论auth后面指定的是什么数字,在下一行必须作为关键字再次出现,例如指定了"auth 6",下面一定要有一行"6 认证类型"。

最后确保这个文件的权限是600(即-rw——-)。

配置备份节点的Heartbeat

在备份节点上也需要安装Heartbeat,安装方式与在主节点安装过程一样,这里不再重述。依次安装libnet和heartbeat源码包,安装完毕,在备份节点上使用scp命令把主节点配置文件传输到备份节点。

  1. [root@node2 ~]#scp -r node1:/etc/ha.d/*  /etc/ha.d/ 

其中,node1是主节点的主机名

设置主节点和备份节点时间同步

在双机高可用集群中,主节点和备份节点的系统时间也非常重要,因为节点之间的监控都是通过设定时间来实现的。主备节点之间的系统时间相差在10秒以 内是正常的,如果节点之间时间相差太大,就有可能造成HA环境的故障。解决时间同步的办法有两个:一个办法是找一个时间服务器,两个节点通过 ntpdate命令定时与时间服务器进行时间校准;另一个办法是让集群中的主节点作为ntp时间服务器,让备份节点定时去主节点进行时间校验。

启动Heartbeat

1.启动主节点的Heartbeat

Heartbeat安装完成后,自动在/etc/init.d目录下生成了启动脚步文件Heartbeat,直接输入/etc/init.d/heartbeat可以看到Heartbeat脚本的用法,如下所示:

  1. [root@node1 ~]# /etc/init.d/heartbeat    
  2. Usage: /etc/init.d/heartbeat {start|stop|status|restart|reload|force-reload} 

因而启动Heartbeat可以通过如下命令进行:

  1. [root@node1 ~]#service heartbeat start 

或者通过:

  1. [root@node1 ~]#/etc/init.d/heartbeat start 

这样就启动了主节点的Heartbeat服务,为了让Heartbeat能在开机自动运行以及关机自动关闭,可以手动创建以下软连接:

  1. [root@node1 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc0.d/K05heartbeat  
  2. [root@node1 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc3.d/S75heartbeat  
  3. [root@node1 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc5.d/S75heartbeat  
  4. [root@node1 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc6.d/K05heartbeat 

Heartbeat启动时,通过"tail -f /var/log/ messages"查看主节点系统日志信息,输出如下:

  1. [root@node1 ~]# tail -f /var/log/messages  
  2. Nov 26 07:52:21 node1 heartbeat: [3688]: info: Configuration validated. Starting heartbeat 2.0.8  
  3. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  heartbeat: version 2.0.8  
  4. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  Heartbeat generation: 3  
  5. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  G_main_add_TriggerHandler: Added signal manual handler  
  6. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  G_main_add_TriggerHandler: Added signal manual handler  
  7. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  glib: UDP Broadcast heartbeat started on port 694 (694) interface eth1  
  8. Nov 26 07:52:21 node1 heartbeat: [3689]: info: glib: UDP Broadcast heartbeat closed on port 694 interface eth1 - Status: 1  
  9. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  glib: ping heartbeat started.  
  10. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  G_main_add_SignalHandler: Added signal handler for signal 17  
  11. Nov 26 07:52:21 node1 heartbeat: [3689]: info:  Local status now set to: 'up'  
  12. Nov 26 07:52:22 node1 heartbeat: [3689]: info:  Link node1:eth1 up.  
  13. Nov 26 07:52:23 node1 heartbeat: [3689]: info:  Link 192.168.60.1:192.168.60.1 up.  
  14. Nov 26 07:52:23 node1 heartbeat: [3689]: info:  Status update for node 192.168.60.1: status ping 

此段日志是Heartbeat在进行初始化配置,例如,Heartbeat的心跳时间间隔、UDP广播端口和ping节点的运行状态等,日志信息到 这里会暂停,等待120秒之后,Heartbeat会继续输出日志,而这个120秒刚好是ha.cf中"initdead"选项的设定时间。此时 Heartbeat的输出信息如下:

  1. Nov 26 07:54:22 node1 heartbeat: [3689]: WARN: node node2: is dead  
  2. Nov 26 07:54:22 node1 heartbeat: [3689]: info:  Comm_now_up(): updating status to active  
  3. Nov 26 07:54:22 node1 heartbeat: [3689]: info:  Local status now set to: 'active'  
  4. Nov 26 07:54:22 node1 heartbeat: [3689]: info: Starting child client "/usr/lib/heartbeat/ipfail" (694,694)  
  5. Nov 26 07:54:22 node1 heartbeat: [3689]: WARN:  No STONITH device configured.  
  6. Nov 26 07:54:22 node1 heartbeat: [3689]: WARN: Shared disks are not protected.  
  7. Nov 26 07:54:22 node1 heartbeat: [3689]: info:  Resources being acquired from node2.  
  8. Nov 26 07:54:22 node1 heartbeat: [3712]: info:  Starting "/usr/lib/heartbeat/ipfail" as uid 694  gid 694 (pid 3712) 

在上面这段日志中,由于node2还没有启动,因此会给出"node2: is dead"的警告信息,接下来启动了Heartbeat插件ipfail。由于我们在ha.cf文件中没有配置STONITH,因此日志里也给出了"No STONITH device configured"的警告提示。

继续看下面的日志:

  1. Nov 26 07:54:23 node1 harc[3713]: info: Running /etc/ha.d/rc.d/status status  
  2. Nov 26 07:54:23 node1 mach_down[3735]: info: /usr/lib/ heartbeat/mach_down: nice_failback: foreign resources acquired  
  3. Nov 26 07:54:23 node1 mach_down[3735]: info: mach_down  takeover complete for node node2.  
  4. Nov 26 07:54:23 node1 heartbeat: [3689]: info: mach_down takeover complete.  
  5. Nov 26 07:54:23 node1 heartbeat: [3689]: info: Initial  resource acquisition complete (mach_down)  
  6. Nov 26 07:54:24 node1 IPaddr[3768]: INFO:  Resource is stopped  
  7. Nov 26 07:54:24 node1 heartbeat: [3714]: info: Local Resource  acquisition completed.  
  8. Nov 26 07:54:24 node1 harc[3815]: info: Running /etc/ha. d/rc.d/ip-request-resp ip-request-resp  
  9. Nov 26 07:54:24 node1 ip-request-resp[3815]: received ip- request-resp 192.168.60.200/24/eth0 OK yes  
  10. Nov 26 07:54:24 node1 ResourceManager[3830]: info: Acquiring  resource group: node1 192.168.60.200/24/eth0 Filesystem: :/dev/sdb5::/webdata::ext3  
  11. Nov 26 07:54:24 node1 IPaddr[3854]: INFO:  Resource is stopped  
  12. Nov 26 07:54:25 node1 ResourceManager[3830]: info: Running  /etc/ha.d/resource.d/IPaddr 192.168.60.200/24/eth0 start  
  13. Nov 26 07:54:25 node1 IPaddr[3932]: INFO: Using calculated netmask for 192.168.60.200: 255.255.255.0  
  14. Nov 26 07:54:25 node1 IPaddr[3932]: DEBUG: Using calculated  broadcast for 192.168.60.200: 192.168.60.255  
  15. Nov 26 07:54:25 node1 IPaddr[3932]: INFO: eval /sbin/ifconfig eth0:0 192.168.60.200 netmask 255.255.255.0 broadcast 192.168.60.255  
  16. Nov 26 07:54:25 node1 avahi-daemon[1854]: Registering new  address record for 192.168.60.200 on eth0.  
  17. Nov 26 07:54:25 node1 IPaddr[3932]: DEBUG: Sending Gratuitous Arp for 192.168.60.200 on eth0:0 [eth0]  
  18. Nov 26 07:54:26 node1 IPaddr[3911]: INFO:  Success  
  19. Nov 26 07:54:26 node1 Filesystem[4021]: INFO:  Resource is stopped  
  20. Nov 26 07:54:26 node1 ResourceManager[3830]: info: Running  /etc/ha.d/resource.d/ Filesystem/dev/sdb5 /webdata ext3 start  
  21. Nov 26 07:54:26 node1 Filesystem[4062]: INFO: Running start for /dev/sdb5 on /webdata  
  22. Nov 26 07:54:26 node1 kernel: kjournald starting.  Commit interval 5 seconds  
  23. Nov 26 07:54:26 node1 kernel: EXT3 FS on sdb5, internal journal  
  24. Nov 26 07:54:26 node1 kernel: EXT3-fs: mounted  filesystem with ordered data mode.  
  25. Nov 26 07:54:26 node1 Filesystem[4059]: INFO:  Success  
  26. Nov 26 07:54:33 node1 heartbeat: [3689]: info: Local Resource acquisition completed. (none)  
  27. Nov 26 07:54:33 node1 heartbeat: [3689]: info: local resource transition completed 

上面这段日志是进行资源的监控和接管,主要完成haresources文件中的设置,在这里是启用集群虚拟IP和挂载磁盘分区。

此时,通过ifconfig命令查看主节点的网络配置,可以看到,主节点已经自动绑定集群IP地址,在HA集群之外的主机上通过ping命令检测集群IP地址192.168.60.200,已经处于可通状态,也就是该地址变得可用。

同时查看磁盘分区的挂载情况,共享磁盘分区/dev/sdb5已经被自动挂载。

2.启动备份节点的Heartbeat

启动备份节点的Heartbeat,与主节点方法一样,使用如下命令:

  1. [root@node2 ~]#/etc/init.d/heartbeat start  

或者执行:

  1. [root@node2 ~]#service heartbeat start  

这样就启动了备用节点的Heartbeat服务。为了让Heartbeat能在开机自动运行以及关机自动关闭,创建以下软连接:

  1. [root@node2 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc0.d/K05heartbeat  
  2. [root@node2 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc3.d/S75heartbeat  
  3. [root@node2 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc5.d/S75heartbeat  
  4. [root@node2 ~]#ln -s  /etc/init.d/heartbeat  /etc/rc.d/rc6.d/K05heartbeat 

备用节点的Heartbeat日志输出信息与主节点相对应,通过"tail -f /var/log/messages"可以看到如下输出:

  1. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Link node1:eth1 up.  
  2. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Status update for node node1: status active  
  3. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Link node1:eth0 up.  
  4. Nov 26 07:57:15 node2 harc[2123]: info: Running /etc/ha.d/rc.d/status status  
  5. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Comm_now_up():  updating status to active  
  6. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Local  status now set to: 'active'  
  7. Nov 26 07:57:15 node2 heartbeat: [2110]: info: Starting  child client "/usr/lib/heartbeat/ipfail" (694,694)  
  8. Nov 26 07:57:15 node2 heartbeat: [2110]: WARN: G _CH_dispatch_int: Dispatch function for read child  took too long to execute: 70 ms (> 50 ms) (GSource: 0x8f62080)  
  9. Nov 26 07:57:15 node2 heartbeat: [2134]: info:  Starting "/usr/lib/heartbeat/ipfail" as uid 694  gid 694 (pid 2134) 

备份节点检测到node1处于活动状态,没有可以接管的资源,因此仅仅启动了网络监听插件ipfail,监控主节点的心跳。

测试Heartbeat

如何才能得知HA集群是否正常工作,模拟环境测试是个不错的方法。在把Heartbeat高可用性集群放到生产环境中之前,需要做如下5个步骤的测试,从而确定HA是否正常工作。

1.正常关闭和重启主节点的Heartbeat

首先在主节点node1上执行"service heartbeat stop"正常关闭主节点的Heartbeat进程,此时通过ifconfig命令查看主节点网卡信息。正常情况下,应该可以看到主节点已经释放了集群的 服务IP地址,同时也释放了挂载的共享磁盘分区。然后查看备份节点,现在备份节点已经接管了集群的服务IP,同时也自动挂载上了共享的磁盘分区。

在这个过程中,使用ping命令对集群服务IP进行测试。可以看到,集群IP一致处于可通状态,并没有任何延时和阻塞现象,也就是说在正常关闭主节点的情况下,主备节点的切换是无缝的,HA对外提供的服务也可以不间断运行。

接着,将主节点Heartbeat正常启动。Heartbeat启动后,备份节点将自动释放集群服务IP,同时卸载共享磁盘分区,而主节点将再次接管集群服务IP和挂载共享磁盘分区。其实备份节点释放资源与主节点绑定资源是同步进行的,因而,这个过程也是一个无缝切换。

2.在主节点上拔去网线

拔去主节点连接公共网络的网线后,Heartbeat插件ipfail通过ping测试可以立刻检测到网络连接失败,接着自动释放资源。而就在此 时,备用节点的ipfail插件也会检测到主节点出现网络故障,在等待主节点释放资源完毕后,备用节点马上接管了集群资源,从而保证了网络服务不间断持续 运行。

同理,当主节点网络恢复正常时,由于设置了"auto_failback on"选项,集群资源将自动从备用节点切会主节点。

在主节点拔去网线后日志信息如下,注意日志中的斜体部分:

  1. Nov 26 09:04:09 node1 heartbeat: [3689]: info: Link node2:eth0 dead.  
  2. Nov 26 09:04:09 node1 heartbeat: [3689]: info:  Link 192.168.60.1:192.168.60.1 dead.  
  3. Nov 26 09:04:09 node1 ipfail: [3712]: info: Status update:  Node 192.168.60.1 now has status dead  
  4. Nov 26 09:04:09 node1 harc[4279]: info: Running /etc/ha.d/rc.d/status status  
  5. Nov 26 09:04:10 node1 ipfail: [3712]: info: NS: We are dead. :< 
  6. Nov 26 09:04:10 node1 ipfail: [3712]: info: Link Status  update: Link node2/eth0 now has status dead  
  7. …… 中间部分省略  ……  
  8. Nov 26 09:04:20 node1 heartbeat: [3689]: info: node1 wants to go standby [all]  
  9. Nov 26 09:04:20 node1 heartbeat: [3689]: info: standby:  node2 can take our all resources  
  10. Nov 26 09:04:20 node1 heartbeat: [4295]: info: give up all  HA resources (standby).  
  11. Nov 26 09:04:21 node1 ResourceManager[4305]: info: Releasing  resource group: node1 192.168.60.200/24/eth0 Filesystem::/dev/sdb5::/webdata::ext3  
  12. Nov 26 09:04:21 node1 ResourceManager[4305]: info: Running  /etc/ha.d/resource.d/ Filesystem/dev/sdb5 /webdata ext3 stop  
  13. Nov 26 09:04:21 node1 Filesystem[4343]: INFO: Running stop for /dev/sdb5 on /webdata  
  14. Nov 26 09:04:21 node1 Filesystem[4343]: INFO: Trying to unmount /webdata  
  15. Nov 26 09:04:21 node1 Filesystem[4343]: INFO: unmounted /webdata successfully  
  16. Nov 26 09:04:21 node1 Filesystem[4340]: INFO:  Success  
  17. Nov 26 09:04:22 node1 ResourceManager[4305]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.60.200/24/eth0 stop  
  18. Nov 26 09:04:22 node1 IPaddr[4428]: INFO: /sbin/ifconfig eth0:0 192.168.60.200 down  
  19. Nov 26 09:04:22 node1 avahi-daemon[1854]: Withdrawing  address record for 192.168.60.200 on eth0.  
  20. Nov 26 09:04:22 node1 IPaddr[4407]: INFO:  Success 

备用节点在接管主节点资源时的日志信息如下:

  1. Nov 26 09:02:58 node2 heartbeat: [2110]: info: Link node1:eth0 dead.  
  2. Nov 26 09:02:58 node2 ipfail: [2134]: info: Link Status  update: Link node1/eth0 now has status dead  
  3. Nov 26 09:02:59 node2 ipfail: [2134]: info: Asking  other side for ping node count.  
  4. Nov 26 09:02:59 node2 ipfail: [2134]: info: Checking remote count of ping nodes.  
  5. Nov 26 09:03:02 node2 ipfail: [2134]: info: Telling other node that we have more visible ping nodes.  
  6. Nov 26 09:03:09 node2 heartbeat: [2110]: info: node1  wants to go standby [all]  
  7. Nov 26 09:03:10 node2 heartbeat: [2110]: info: standby:  acquire [all] resources from node1  
  8. Nov 26 09:03:10 node2 heartbeat: [2281]: info: acquire all HA resources (standby).  
  9. Nov 26 09:03:10 node2 ResourceManager[2291]: info: Acquiring  resource group: node1 192.168.60.200/24/eth0 Filesystem::/dev/sdb5::/webdata::ext3  
  10. Nov 26 09:03:10 node2 IPaddr[2315]: INFO:  Resource is stopped  
  11. Nov 26 09:03:11 node2 ResourceManager[2291]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.60.200/24/eth0 start  
  12. Nov 26 09:03:11 node2 IPaddr[2393]: INFO: Using calculated  netmask for 192.168.60.200: 255.255.255.0  
  13. Nov 26 09:03:11 node2 IPaddr[2393]: DEBUG: Using calculated  broadcast for 192.168.60.200: 192.168.60.255  
  14. Nov 26 09:03:11 node2 IPaddr[2393]: INFO: eval /sbin/ifconfig  eth0:0 192.168.60.200 netmask 255.255.255.0 broadcast 192.168.60.255  
  15. Nov 26 09:03:12 node2 avahi-daemon[1844]: Registering new  address record for 192.168.60.200 on eth0.  
  16. Nov 26 09:03:12 node2 IPaddr[2393]: DEBUG: Sending Gratuitous  Arp for 192.168.60.200 on eth0:0 [eth0]  
  17. Nov 26 09:03:12 node2 IPaddr[2372]: INFO:  Success  
  18. Nov 26 09:03:12 node2 Filesystem[2482]: INFO:  Resource is stopped  
  19. Nov 26 09:03:12 node2 ResourceManager[2291]: info: Running /etc/ha.d/resource.d/ Filesystem/dev/sdb5 /webdata ext3 start  
  20. Nov 26 09:03:13 node2 Filesystem[2523]: INFO: Running start for /dev/sdb5 on /webdata  
  21. Nov 26 09:03:13 node2 kernel: kjournald starting.  Commit interval 5 seconds  
  22. Nov 26 09:03:13 node2 kernel: EXT3 FS on sdb5, internal journal  
  23. Nov 26 09:03:13 node2 kernel: EXT3-fs: mounted filesystem with ordered data mode.  
  24. Nov 26 09:03:13 node2 Filesystem[2520]: INFO:  Success 

3.在主节点上拔去电源线

在主节点拔去电源后,备用节点的Heartbeat进程会立刻收到主节点已经shutdown的消息。如果在集群上配置了Stonith设备,那么 备用节点将会把电源关闭或者复位到主节点。当Stonith设备完成所有操作时,备份节点才能拿到接管主节点资源的所有权,从而接管主节点的资源。

在主节点拔去电源后,备份节点有类似如下的日志输出:

  1. Nov 26 09:24:54 node2 heartbeat: [2110]: info: Received shutdown notice from 'node1'.  
  2. Nov 26 09:24:54 node2 heartbeat: [2110]: info: Resources being acquired from node1.  
  3. Nov 26 09:24:54 node2 heartbeat: [2712]: info:  acquire local HA resources (standby).  
  4. Nov 26 09:24:55 node2 ResourceManager[2762]:  info: Running /etc/ha.d/resource.d/IPaddr 192.168.60.200/24/eth0 start  
  5. Nov 26 09:24:57 node2 ResourceManager[2762]:  info: Running /etc/ha.d/resource.d/ Filesystem /dev/sdb5 /webdata ext3 start 

4.切断主节点的所有网络连接

在主节点上断开心跳线后,主备节点都会在日志中输出"eth1 dead"的信息,但是不会引起节点间的资源切换。如果再次拔掉主节点连接公共网络的网线,就会发生主备节点资源切换,资源从主节点转移到备用节点。此 时,连上主节点的心跳线,观察系统日志,可以看到,备用节点的Heartbeat进程将会重新启动,进而再次控制集群资源。最后,连上主节点的对外网线, 集群资源再次从备用节点转移到主节点。这就是整个切换过程。

5.在主节点上非正常关闭Heartbeat守护进程

在主节点上可通过"killall -9 heartbeat"命令关闭Heartbeat进程。由于是非法关闭Heartbeat进程,因此Heartbeat所控制的资源并没有释放。备份节点 在很短一段时间没有收到主节点的响应后,就会认为主节点出现故障,进而接管主节点资源。在这种情况下,就出现了资源争用情况,两个节点都占用一个资源,造 成数据冲突。针对这个情况,可以通过Linux提供的内核监控模块watchdog来解决这个问题,将watchdog集成到Heartbeat中。如果 Heartbeat异常终止,或者系统出现故障,watchdog都会自动重启系统,从而释放集群资源,避免了数据冲突的发生。

本章节我们没有配置watchdog到集群中,如果配置了watchdog,在执行"killall -9 heartbeat"时,会在/var/log/messages中看到如下信息:

  1. Softdog: WDT device closed unexpectedly. WDT will not stop! 

这个错误告诉我们,系统出现问题,将重新启动。

猜你喜欢

转载自www.cnblogs.com/drgcaosheng/p/9856976.html