或者我们可以通过log来查看切换状态:
我们来暂停lib1机器
lb2:/etc/ha.d# tail -f /var/log/ha-log
heartbeat[3915]: 2010/03/01_15:34:28 info: Status update for node lb1.example.com: status up
harc[3926]:     2010/03/01_15:34:28 info: Running /etc/ha.d/rc.d/status status
heartbeat[3915]: 2010/03/01_15:34:28 info: Comm_now_up(): updating status to active
heartbeat[3915]: 2010/03/01_15:34:28 info: Local status now set to: 'active'
heartbeat[3915]: 2010/03/01_15:34:29 info: Status update for node lb1.example.com: status active
harc[3945]:     2010/03/01_15:34:29 info: Running /etc/ha.d/rc.d/status status
heartbeat[3915]: 2010/03/01_15:34:39 info: remote resource transition completed.
heartbeat[3915]: 2010/03/01_15:34:39 info: remote resource transition completed.
heartbeat[3915]: 2010/03/01_15:34:39 info: Initial resource acquisition complete (T_RESOURCES(us))
heartbeat[3962]: 2010/03/01_15:34:39 info: No local resources [/usr/share/heartbeat/ResourceManager listkeys lb2.example.com] to acquire.
heartbeat[3915]: 2010/03/01_15:37:40 WARN: node lb1.example.com: is dead
heartbeat[3915]: 2010/03/01_15:37:40 WARN: No STONITH device configured.
heartbeat[3915]: 2010/03/01_15:37:40 WARN: Shared disks are not protected.
heartbeat[3915]: 2010/03/01_15:37:40 info: Resources being acquired from lb1.example.com.
heartbeat[3915]: 2010/03/01_15:37:40 info: Link lb1.example.com:eth0 dead.
harc[3996]:     2010/03/01_15:37:40 info: Running /etc/ha.d/rc.d/status status
heartbeat[3997]: 2010/03/01_15:37:40 info: No local resources [/usr/share/heartbeat/ResourceManager listkeys lb2.example.com] to acquire.
mach_down[4026]:        2010/03/01_15:37:40 info: Taking over resource group 192.168.5.222
ResourceManager[4052]:  2010/03/01_15:37:40 info: Acquiring resource group: lb1.example.com 192.168.5.222
IPaddr[4079]:   2010/03/01_15:37:40 INFO:  Resource is stopped
ResourceManager[4052]:  2010/03/01_15:37:40 info: Running /etc/ha.d/resource.d/IPaddr 192.168.5.222 start
IPaddr[4155]:   2010/03/01_15:37:40 INFO: Using calculated nic for 192.168.5.222: eth0
IPaddr[4155]:   2010/03/01_15:37:40 INFO: Using calculated netmask for 192.168.5.222: 255.255.0.0
IPaddr[4155]:   2010/03/01_15:37:40 INFO: eval ifconfig eth0:0 192.168.5.222 netmask 255.255.0.0 broadcast 192.168.255.255
IPaddr[4138]:   2010/03/01_15:37:40 INFO:  Success
mach_down[4026]:        2010/03/01_15:37:40 info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired
mach_down[4026]:        2010/03/01_15:37:41 info: mach_down takeover complete for node lb1.example.com.
heartbeat[3915]: 2010/03/01_15:37:41 info: mach_down takeover complete.
 
在查看下IP地址发现自动切换过来了。
lb2:/etc/ha.d# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:c7:67:9c
          inet addr:192.168.2.222  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fec7:679c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:186573 errors:0 dropped:0 overruns:0 frame:0
          TX packets:12198 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:18360236 (17.5 MiB)  TX bytes:2626430 (2.5 MiB)
          Interrupt:19 Base address:0x2000
 
eth0:0    Link encap:Ethernet  HWaddr 00:0c:29:c7:67:9c
          inet addr:192.168.5.222  Bcast:192.168.255.255  Mask:255.255.0.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          Interrupt:19 Base address:0x2000
 
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:260 errors:0 dropped:0 overruns:0 frame:0
          TX packets:260 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:69826 (68.1 KiB)  TX bytes:69826 (68.1 KiB)
 
那我们现在开启lb1机器来查看log
heartbeat[4397]: 2010/03/01_15:41:26 info: glib: ucast: bound send socket to device: eth0
heartbeat[4397]: 2010/03/01_15:41:26 info: glib: ucast: bound receive socket to device: eth0
heartbeat[4397]: 2010/03/01_15:41:26 info: glib: ucast: started on port 694 interface eth0 to 192.168.4.222
heartbeat[4397]: 2010/03/01_15:41:26 info: G_main_add_TriggerHandler: Added signal manual handler
heartbeat[4397]: 2010/03/01_15:41:26 info: G_main_add_TriggerHandler: Added signal manual handler
heartbeat[4397]: 2010/03/01_15:41:26 info: G_main_add_SignalHandler: Added signal handler for signal 17
heartbeat[4397]: 2010/03/01_15:41:26 info: Local status now set to: 'up'
heartbeat[4397]: 2010/03/01_15:41:27 info: Link lb1.example.com:eth0 up.
heartbeat[4397]: 2010/03/01_15:41:27 info: Status update for node lb1.example.com: status active
heartbeat[4397]: 2010/03/01_15:41:27 info: Link lb2.example.com:eth0 up.
harc[4407]:     2010/03/01_15:41:27 info: Running /etc/ha.d/rc.d/status status
heartbeat[4397]: 2010/03/01_15:41:28 info: Comm_now_up(): updating status to active
heartbeat[4397]: 2010/03/01_15:41:28 info: Local status now set to: 'active'
heartbeat[4397]: 2010/03/01_15:41:29 info: remote resource transition completed.
heartbeat[4397]: 2010/03/01_15:41:29 info: remote resource transition completed.
heartbeat[4397]: 2010/03/01_15:41:29 info: Local Resource acquisition completed. (none)
heartbeat[4397]: 2010/03/01_15:41:30 info: lb1.example.com wants to go standby [foreign]
heartbeat[4397]: 2010/03/01_15:41:30 info: standby: acquire [foreign] resources from lb1.example.com
heartbeat[4426]: 2010/03/01_15:41:30 info: acquire local HA resources (standby).
heartbeat[4426]: 2010/03/01_15:41:30 info: local HA resource acquisition completed (standby).
heartbeat[4397]: 2010/03/01_15:41:30 info: Standby resource acquisition done [foreign].
heartbeat[4397]: 2010/03/01_15:41:30 info: Initial resource acquisition complete (auto_failback)
heartbeat[4397]: 2010/03/01_15:41:31 info: remote resource transition completed.
 
 
此时的IP地址:
lb2:/etc/ha.d# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:0c:29:c7:67:9c
          inet addr:192.168.2.222  Bcast:192.168.255.255  Mask:255.255.0.0
          inet6 addr: fe80::20c:29ff:fec7:679c/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:201150 errors:0 dropped:0 overruns:0 frame:0
          TX packets:13394 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000
          RX bytes:19860573 (18.9 MiB)  TX bytes:2902953 (2.7 MiB)
          Interrupt:19 Base address:0x2000
 
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:348 errors:0 dropped:0 overruns:0 frame:0
          TX packets:348 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:0
          RX bytes:93690 (91.4 KiB)  TX bytes:93690 (91.4 KiB)
 
或者采用如下验证:
 
现在2台都正常工作
打开IE输入192.168.5.222
Debian5.0 实现RAS双机 集群 (二)_RAS
假设关闭lb1服务器,再次输入192.168.5.222的时候发现已经切换到lb2服务器了。
Debian5.0 实现RAS双机 集群 (二)_RAS_02
 
再次打开lb1服务器时候会自动切回
Debian5.0 实现RAS双机 集群 (二)_职场_03