一、环境

    系统:CentOS 6.4x64位最小化安装

    nfs:192.168.3.31

    node1:192.168.3.32

    node2:192.168.3.33

    vip:192.168.3.34

二、拓扑图

wKioL1VtTRWA2o1OAADMPsDPnTA567.jpg

三、前提条件

1.节点之间主机名互相解析

node1,node2:

[root@heatbeat-node1 ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
192.168.3.32 heatbeat-node1    node1
192.168.3.33 heatbeat-node2    node2

2.节点之间时间得同步

[root@heatbeat-node1 ~]# yum -y install ntp
[root@heatbeat-node1 ~]# ntpdate asia.pool.ntp.org

3.节点之间配置SSH互信

node1:

[root@heatbeat-node1 ~]# ssh-keygen 
[root@heatbeat-node1 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@heatbeat-node2
The authenticity of host 'heatbeat-node2 (192.168.3.33)' can't be established.
RSA key fingerprint is 5a:02:f0:4c:1d:97:2d:82:21:73:34:8e:ba:9c:97:d3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'heatbeat-node2,192.168.3.33' (RSA) to the list of known hosts.
root@heatbeat-node2's password: 
Now try logging into the machine, with "ssh 'root@heatbeat-node2'", and check in:.ssh/authorized_keysto make sure we haven't added extra keys that you weren't expecting.[root@heatbeat-node1 ~]# vim /etc/hosts
[root@heatbeat-node1 ~]# ssh node2
The authenticity of host 'node2 (192.168.3.33)' can't be established.
RSA key fingerprint is 5a:02:f0:4c:1d:97:2d:82:21:73:34:8e:ba:9c:97:d3.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node2' (RSA) to the list of known hosts.
Last login: Tue Jun  2 11:44:02 2015 from 192.168.3.2
[root@heatbeat-node2 ~]# hostname
heatbeat-node2

node2:

[root@heatbeat-node2 ~]# ssh-keygen 
[root@heatbeat-node2 ~]# ssh-copy-id -i .ssh/id_rsa.pub root@heatbeat-node1
[root@heatbeat-node2 ~]# ssh node1
The authenticity of host 'node1 (192.168.3.32)' can't be established.
RSA key fingerprint is 87:ac:29:cf:62:38:27:13:b4:4b:79:d7:08:22:f8:9e.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'node1' (RSA) to the list of known hosts.
Last login: Tue Jun  2 11:43:52 2015 from 192.168.3.2
[root@heatbeat-node1 ~]# hostname
heatbeat-node1

四、安装相关软件 (两节点都要安装)

1.heartbeat 安装组件说明

  • heartbeat 核心组件  *    

  • heartbeat-devel 开发包    

  • heartbeat-gui 图形管理接口 *    

  • heartbeat-ldirectord 为lvs高可用提供规则自动生成及后端realserver健康状态检查的组件    

  • heartbeat-pils 装载库插件接口 *    

  • heartbeat-stonith 爆头接口 *

注:带*表示必须安装

2.安装heartbeat

node1,node2:

[root@heatbeat-node1 ~]# yum install heartbeat* -y

3.安装httpd

node1:

[root@heatbeat-node1 ~]# yum install httpd -y
[root@heatbeat-node1 ~]# echo "ServerName localhost:80" >>/etc/httpd/conf/httpd.conf 
[root@heatbeat-node1 ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@heatbeat-node1 ~]# echo "<h1>node1.test.com</h1>" > /var/www/html/index.html
[root@heatbeat-node1 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@heatbeat-node1 ~]# service iptables save

测试

wKioL1VtU_zyVyhNAABcHa_iLDM509.jpg

[root@heatbeat-node1 ~]# service httpd stop
Stopping httpd:                                            [  OK  ]
[root@heatbeat-node1 ~]# chkconfig httpd off

说明:测试完成后关闭服务,并让其开机不启动(注,httpd由heartbeat管理)

node2:

[root@heatbeat-node2 ~]# yum install httpd -y
[root@heatbeat-node2 ~]# echo "ServerName localhost:80" >>/etc/httpd/conf/httpd.conf 
[root@heatbeat-node2 ~]# service httpd start
Starting httpd:                                            [  OK  ]
[root@heatbeat-node2 ~]# echo "<h1>node2.test.com</h1>" > /var/www/html/index.html
[root@heatbeat-node2 ~]# iptables -I INPUT -p tcp --dport 80 -j ACCEPT
[root@heatbeat-node2 ~]# service iptables save

测试

wKiom1VtUymiJENUAABWhIt5LUE285.jpg

[root@heatbeat-node2 ~]# service httpd stop
Stopping httpd:                                            [  OK  ]
[root@heatbeat-node2 ~]# chkconfig httpd off

说明:测试完成后关闭服务,并让其开机不启动(注,httpd由heartbeat管理)

五、配置 heartbeat

1.配置文件说明

[root@heatbeat-node1 ~]# ls /etc/ha.d/
harc  rc.d  README.config  resource.d  shellfuncs

说明:安装好的heartbeat默认是没有配置文件的,但提供了配置文件样本

[root@heatbeat-node1 ~]# ll /usr/share/doc/heartbeat-3.0.4/
total 144
-rw-r--r-- 1 root root  1873 Dec  3  2013 apphbd.cf
-rw-r--r-- 1 root root   645 Dec  3  2013 authkeys
-rw-r--r-- 1 root root  3701 Dec  3  2013 AUTHORS
-rw-r--r-- 1 root root 58752 Dec  3  2013 ChangeLog
-rw-r--r-- 1 root root 17989 Dec  3  2013 COPYING
-rw-r--r-- 1 root root 26532 Dec  3  2013 COPYING.LGPL
-rw-r--r-- 1 root root 10502 Dec  3  2013 ha.cf
-rw-r--r-- 1 root root  5905 Dec  3  2013 haresources
-rw-r--r-- 1 root root  2935 Dec  3  2013 README
[root@heatbeat-node1 ~]# cd /usr/share/doc/heartbeat-3.0.4/
[root@heatbeat-node1 heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/

说明:其中有三个配置文件是我们需要的分别为,authkeys、ha.cf、haresources

  • authkeys #是节点之间的认证key文件,我们不能让什么服务器都加入集群中来,加入集群中的节点都是需要认证的

  • ha.cf #heartbeat的主配置文件

  • haresources #集群资源管理配置文件(在heartbeat所有版本中都是支持haresources来配置集群中的资源的)

2.配置authkeys文件

[root@heatbeat-node1 ha.d]# dd if=/dev/random  bs=512 count=1 |openssl md5    #生成随机秘钥数
0+1 records in
0+1 records out
16 bytes (16 B) copied, 4.1404e-05 s, 386 kB/s
(stdin)= f5e377b9a3a4ae407467946ae1d694d5#编辑authkeys文件
[root@heatbeat-node1 ha.d]# grep -v ^# authkeys 
auth 1
1 md5 f5e377b9a3a4ae407467946ae1d694d5[root@heatbeat-node1 ha.d]# chmod 600 authkeys    #修改密钥文件的权限为600
[root@heatbeat-node1 ha.d]# ll
total 44
-rw------- 1 root root   691 Jun  2 15:00 authkeys
-rw-r--r-- 1 root root 10502 Jun  2 14:57 ha.cf
-rwxr-xr-x 1 root root   745 Dec  3  2013 harc
-rw-r--r-- 1 root root  5905 Jun  2 14:57 haresources
drwxr-xr-x 2 root root  4096 Jun  2 14:46 rc.d
-rw-r--r-- 1 root root   692 Dec  3  2013 README.config
drwxr-xr-x 2 root root  4096 Jun  2 14:46 resource.d
-rw-r--r-- 1 root root  2082 May  6 18:52 shellfuncs

3.配置ha.cf文件

主要修改两处(其它都可以默认):

(1).修改心跳信息的传播方式(这里是组播)

mcast eth0 225.100.100.100 694 1 0

(2).配置集群中的节点数

node    heatbeat-node1
node    heatbeat-node2

4.配置haresources文件

heatbeat-node1 IPaddr::192.168.3.34/24/eth0 httpd

5.复制以上三个配置文件到node2上

[root@heatbeat-node1 ha.d]# scp authkeys ha.cf haresources node2:/etc/ha.d/
authkeys                                                                                      100%  691     0.7KB/s   00:00    
ha.cf                                                                                         100%   10KB  10.3KB/s   00:00    
haresources                                                                                   100% 5954     5.8KB/s   00:00  
[root@heatbeat-node1 ha.d]# ssh node2 ls -l /etc/ha.d
total 44
-rw------- 1 root root   691 Jun  3 10:33 authkeys
-rw-r--r-- 1 root root 10545 Jun  3 10:33 ha.cf
-rwxr-xr-x 1 root root   745 Dec  3  2013 harc
-rw-r--r-- 1 root root  5954 Jun  3 10:33 haresources
drwxr-xr-x 2 root root  4096 Jun  2 14:44 rc.d
-rw-r--r-- 1 root root   692 Dec  3  2013 README.config
drwxr-xr-x 2 root root  4096 Jun  2 14:44 resource.d
-rw-r--r-- 1 root root  2082 May  6 18:52 shellfuncs

6.启动node1与node2

[root@heatbeat-node1 ha.d]# service heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.
[root@heatbeat-node1 ha.d]# ssh node2 service heartbeat start
Starting High-Availability services: 2015/06/03_10:36:56 INFO:  Resource is stopped
Done.

六、测试Web集群

1.查看启动的服务

[root@heatbeat-node1 ha.d]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1142/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1294/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1426/master         
tcp        0      0 0.0.0.0:56970               0.0.0.0:*                   LISTEN      1160/rpc.statd      
tcp        0     52 192.168.3.32:22             192.168.3.2:7332            ESTABLISHED 1539/sshd           
tcp        0      0 :::111                      :::*                        LISTEN      1142/rpcbind        
tcp        0      0 :::80                       :::*                        LISTEN      2348/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1294/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1426/master         
tcp        0      0 :::55609                    :::*                        LISTEN      1160/rpc.statd

2.查看IP

[root@heatbeat-node1 ha.d]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:23:44:ba brd ff:ff:ff:ff:ff:ffinet 192.168.3.32/24 brd 192.168.3.255 scope global eth0inet 192.168.3.34/24 brd 192.168.3.255 scope global secondary eth0inet6 fe80::20c:29ff:fe23:44ba/64 scope link valid_lft forever preferred_lft forever

3.测试

wKiom1VuaNTip_taAABdks5F2Mg238.jpg

4.故障演示

1).关闭node1上的heartbeat

[root@heatbeat-node1 ha.d]# service heartbeat stop        #这关闭的是node1上的heartbeat服务
Stopping High-Availability services: Done.#查看node1的IP和服务
[root@heatbeat-node1 ha.d]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:23:44:ba brd ff:ff:ff:ff:ff:ffinet 192.168.3.32/24 brd 192.168.3.255 scope global eth0inet6 fe80::20c:29ff:fe23:44ba/64 scope link valid_lft forever preferred_lft forever
[root@heatbeat-node1 ha.d]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1142/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1294/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1426/master         
tcp        0      0 0.0.0.0:56970               0.0.0.0:*                   LISTEN      1160/rpc.statd      
tcp        0     52 192.168.3.32:22             192.168.3.2:7332            ESTABLISHED 1539/sshd           
tcp        0      0 192.168.3.32:51322          192.168.3.33:22             TIME_WAIT   -                   
tcp        0      0 :::111                      :::*                        LISTEN      1142/rpcbind        
tcp        0      0 :::22                       :::*                        LISTEN      1294/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1426/master         
tcp        0      0 :::55609                    :::*                        LISTEN      1160/rpc.statd   
#上面的结果显示heartbeat的IP资源和httpd资源已被移除

2).查看node2上的IP和服务

[root@heatbeat-node1 ha.d]# ssh node2 hostname
heatbeat-node2
[root@heatbeat-node1 ha.d]# ssh node2 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:e3:b1:f7 brd ff:ff:ff:ff:ff:ffinet 192.168.3.33/24 brd 192.168.3.255 scope global eth0inet 192.168.3.34/24 brd 192.168.3.255 scope global secondary eth0inet6 fe80::20c:29ff:fee3:b1f7/64 scope link valid_lft forever preferred_lft forever#查看node2的服务
[root@heatbeat-node1 ha.d]# ssh node2 netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1113/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1264/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1350/master         
tcp        0      0 0.0.0.0:49086               0.0.0.0:*                   LISTEN      1131/rpc.statd      
tcp        0     80 192.168.3.33:22             192.168.3.32:51322          ESTABLISHED 2419/sshd           
tcp        0      0 192.168.3.33:22             192.168.3.32:51319          TIME_WAIT   -                   
tcp        0      0 192.168.3.33:22             192.168.3.2:7337            ESTABLISHED 1463/sshd           
tcp        0      0 :::111                      :::*                        LISTEN      1113/rpcbind        
tcp        0      0 :::80                       :::*                        LISTEN      2381/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1264/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1350/master         
tcp        0      0 :::51270                    :::*                        LISTEN      1131/rpc.statd    
#结果表明IP资源和httpd资源已启动

3).测试

wKiom1VuacODf2vFAABP-rG7x9Y205.jpg

从上面的结果能看出集群实现了web的高可用

七、给heartbeat提供一个共享存储

1.配置NFS服务器

[root@nfs ~]# mkdir -pv /web
mkdir: created directory `/web'#安装nfs服务
[root@nfs ~]# yum install nfs-utils rpcbind -y
[root@nfs ~]# cat /etc/exports 
/web/	192.168.3.0/24(ro,async)
[root@nfs ~]# echo '<h1>Cluster NFS Server</h1>' >/web/index.html
[root@nfs ~]# service rpcbind start
Starting rpcbind:                                          [  OK  ]
[root@nfs ~]# service nfs start
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
[root@nfs ~]# showmount -e 192.168.3.31
Export list for 192.168.3.31:
/web 192.168.3.0/24

2.节点测试挂载

node1:

[root@heatbeat-node1 ~]# mount -t nfs 192.168.3.31:/web /mnt
[root@heatbeat-node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.3G   16G   8% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             194M   28M  156M  16% /boot
192.168.3.31:/web      18G  1.2G   16G   8% /mnt
[root@heatbeat-node1 ~]# ls /mnt/
index.html
[root@heatbeat-node1 ~]# cat /mnt/index.html 
<h1>Cluster NFS Server</h1>
[root@heatbeat-node1 ~]# umount /mnt

node2:

[root@heatbeat-node2 ~]# mount -t nfs 192.168.3.31:/web /mnt
[root@heatbeat-node2 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.3G   16G   8% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             194M   28M  156M  16% /boot
192.168.3.31:/web      18G  1.2G   16G   8% /mnt
[root@heatbeat-node2 ~]# ls /mnt/
index.html
[root@heatbeat-node2 ~]# cat /mnt/index.html 
<h1>Cluster NFS Server</h1>
[root@heatbeat-node2 ~]# umount /mnt

3.修改haresource文件

#编辑配置文件
[root@heatbeat-node1 ~]# vim /etc/ha.d/haresources 
heatbeat-node1 IPaddr::192.168.3.34/24/eth0 Filesystem::192.168.3.31:/web::/var/www/html::nfs  httpd
#这里的意思是在httpd服务器之前,挂载文件nfs系统,将nfs文件系统挂载到/var/www/html目录下

4.同步haresource配置文件

[root@heatbeat-node1 ~]# scp /etc/ha.d/haresources node2:/etc/ha.d/

5.重启一下heartbeat

#重启node2的服务
[root@heatbeat-node1 ~]# ssh node2 service heartbeat restart
Stopping High-Availability services: Done.Waiting to allow resource takeover to complete:Done.Starting High-Availability services: 2015/06/03_11:02:28 INFO:  Resource is stopped
Done.#重启node1的服务
[root@heatbeat-node1 ~]# service heartbeat restart
Stopping High-Availability services: Done.Waiting to allow resource takeover to complete:Done.Starting High-Availability services: INFO:  Resource is stopped
Done.

6.查看一下端口

#这个时候资源服务应该都在node1上
#查看httpd服务
[root@heatbeat-node1 ~]# netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1142/rpcbind        
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1294/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1426/master         
tcp        0      0 0.0.0.0:33258               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:56970               0.0.0.0:*                   LISTEN      1160/rpc.statd      
tcp        0     52 192.168.3.32:22             192.168.3.2:7332            ESTABLISHED 1539/sshd           
tcp        0      0 192.168.3.32:814            192.168.3.31:2049           ESTABLISHED -                   
tcp        0      0 :::111                      :::*                        LISTEN      1142/rpcbind        
tcp        0      0 :::80                       :::*                        LISTEN      5912/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1294/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1426/master         
tcp        0      0 :::55609                    :::*                        LISTEN      1160/rpc.statd      
tcp        0      0 :::56927                    :::*                        LISTEN      -                   
#查看nfs服务
[root@heatbeat-node1 ~]# df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.3G   16G   8% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             194M   28M  156M  16% /boot
192.168.3.31:/web      18G  1.2G   16G   8% /var/www/html#查看IP资源
[root@heatbeat-node1 ~]# ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:23:44:ba brd ff:ff:ff:ff:ff:ffinet 192.168.3.32/24 brd 192.168.3.255 scope global eth0inet 192.168.3.34/24 brd 192.168.3.255 scope global secondary eth0inet6 fe80::20c:29ff:fe23:44ba/64 scope link valid_lft forever preferred_lft forever

7.测试一下Web服务

wKioL1VucJrSwvcIAABeYB6KkqA219.jpg

测试结果能看出我们通过heartbeat已经能够正常访问web共享站点了

8.模拟故障并测试

(1).停止node11上的heartbeat

[root@heatbeat-node1 ~]# service heartbeat stop
Stopping High-Availability services: Done.

(2).查看节点2的IP与服务

#查看node2
[root@heatbeat-node1 ~]# ssh node2 ip a
1: lo: <LOOPBACK,UP,LOWER_UP> mtu 16436 qdisc noqueue state UNKNOWN link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00inet 127.0.0.1/8 scope host loinet6 ::1/128 scope host valid_lft forever preferred_lft forever
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000link/ether 00:0c:29:e3:b1:f7 brd ff:ff:ff:ff:ff:ffinet 192.168.3.33/24 brd 192.168.3.255 scope global eth0inet 192.168.3.34/24 brd 192.168.3.255 scope global secondary eth0inet6 fe80::20c:29ff:fee3:b1f7/64 scope link valid_lft forever preferred_lft forever
[root@heatbeat-node1 ~]# ssh node2 netstat -anpt
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name   
tcp        0      0 0.0.0.0:111                 0.0.0.0:*                   LISTEN      1113/rpcbind        
tcp        0      0 0.0.0.0:38901               0.0.0.0:*                   LISTEN      -                   
tcp        0      0 0.0.0.0:22                  0.0.0.0:*                   LISTEN      1264/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1350/master         
tcp        0      0 0.0.0.0:49086               0.0.0.0:*                   LISTEN      1131/rpc.statd      
tcp        0      0 192.168.3.33:926            192.168.3.31:2049           ESTABLISHED -                   
tcp        0     80 192.168.3.33:22             192.168.3.32:51327          ESTABLISHED 6572/sshd           
tcp        0      0 192.168.3.33:22             192.168.3.2:7337            ESTABLISHED 1463/sshd           
tcp        0      0 :::111                      :::*                        LISTEN      1113/rpcbind        
tcp        0      0 :::80                       :::*                        LISTEN      6546/httpd          
tcp        0      0 :::22                       :::*                        LISTEN      1264/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1350/master         
tcp        0      0 :::57119                    :::*                        LISTEN      -                   
tcp        0      0 :::51270                    :::*                        LISTEN      1131/rpc.statd      
[root@heatbeat-node1 ~]# ssh node2 df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda3              18G  1.3G   16G   8% /
tmpfs                 495M     0  495M   0% /dev/shm
/dev/sda1             194M   28M  156M  16% /boot
192.168.3.31:/web      18G  1.2G   16G   8% /var/www/html
#通过以上结果能看出node2已全部接管所有资源

(3).测试服务

wKioL1VucY6wUzqTAABeo7sQr1M104.jpg

4).重新启动node1上heartbeat

#node1重新启动服务
[root@heatbeat-node1 ~]# service heartbeat start
Starting High-Availability services: INFO:  Resource is stopped
Done.#查看日志
[root@heatbeat-node1 ~]# tail -f /var/log/messages 
Jun  3 11:10:33 heatbeat-node1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.3.34)[6491]: INFO:  Success
Jun  3 11:10:33 heatbeat-node1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.3.31:/web)[6599]: INFO:  Resource is stopped
Jun  3 11:10:33 heatbeat-node1 ResourceManager(default)[6372]: info: Running /etc/ha.d/resource.d/Filesystem 192.168.3.31:/web /var/www/html nfs start
Jun  3 11:10:33 heatbeat-node1 Filesystem(Filesystem_192.168.3.31:/web)[6674]: INFO: Running start for 192.168.3.31:/web on /var/www/html
Jun  3 11:10:33 heatbeat-node1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.3.31:/web)[6666]: INFO:  Success
Jun  3 11:10:33 heatbeat-node1 ResourceManager(default)[6372]: info: Running /etc/init.d/httpd  start
Jun  3 11:10:33 heatbeat-node1 heartbeat: [6359]: info: local HA resource acquisition completed (standby).
Jun  3 11:10:33 heatbeat-node1 heartbeat: [6334]: info: Standby resource acquisition done [foreign].
Jun  3 11:10:33 heatbeat-node1 heartbeat: [6334]: info: Initial resource acquisition complete (auto_failback)
Jun  3 11:10:34 heatbeat-node1 heartbeat: [6334]: info: remote resource transition completed.

到此heartbeat的高可用已基本完成