Linux系统高可用集群软件之HeartBeat

 

服务器环境:

node1:192.168.1.100    10.0.0.1

node2:192.168.1.102    10.0.0.2

服务:apache

 

1.配置系统的网络环境

node1节点:

(1)配置IP地址

[root@node1 yum.repos.d]# cd /etc/sysconfig/network-scripts/
[root@node1 network-scripts]# vim ifcfg-eth0

DEVICE=eth0
HWADDR=08:00:27:EE:3D:F6
TYPE=Ethernet
UUID=f1fcda7b-0fa1-458d-800c-aeed3d56aad0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.100
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

[root@node1 network-scripts]# vim ifcfg-eth1

DEVICE=eth1
HWADDR=08:00:27:06:79:47
TYPE=Ethernet
UUID=f1fcda7b-0fa1-458d-800c-aeed3d56aad0
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.0.1
NETMASK=255.255.255.0

(2)两节点主机名和IP地址解析

[root@node1 network-scripts]# vim /etc/hosts

192.168.1.100 node1
192.168.1.102 node2

[root@node1 network-scripts]#

 

node2节点:

(1)配置IP地址

[root@node2 ha.d]# cd /etc/sysconfig/network-scripts/
[root@node2 network-scripts]# vim ifcfg-eth0

DEVICE=eth0
HWADDR=08:00:27:A5:94:4C
TYPE=Ethernet
UUID=fd898d33-eed6-4333-a5cd-a6961d9f4226
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=192.168.1.102
NETMASK=255.255.255.0
GATEWAY=192.168.1.1

[root@node2 network-scripts]# vim ifcfg-eth1

DEVICE=eth1
HWADDR=08:00:27:5B:2C:6E
TYPE=Ethernet
UUID=fd898d33-eed6-4333-a5cd-a6961d9f4226
ONBOOT=yes
NM_CONTROLLED=yes
BOOTPROTO=static
IPADDR=10.0.0.2
NETMASK=255.255.255.0

(2)IP地址和主机解析

[root@node2 network-scripts]# vim /etc/hosts

192.168.1.100 node1
192.168.1.102 node2

[root@node2 network-scripts]#

(3)检查两台服务器是否能通信

[root@node1 network-scripts]# ping node2 -c1
PING node2 (192.168.1.102) 56(84) bytes of data.
64 bytes from node2 (192.168.1.102): icmp_seq=1 ttl=64 time=1.97 ms

--- node2 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 2ms
rtt min/avg/max/mdev = 1.974/1.974/1.974/0.000 ms

[root@node2 network-scripts]# ping node1 -c 1
PING node1 (192.168.1.100) 56(84) bytes of data.
64 bytes from node1 (192.168.1.100): icmp_seq=1 ttl=64 time=0.524 ms

--- node1 ping statistics ---
1 packets transmitted, 1 received, 0% packet loss, time 1ms
rtt min/avg/max/mdev = 0.524/0.524/0.524/0.000 ms
[root@node2 network-scripts]#

 

2.下载epel源,用epel源安装heartbeat软件

node1节点:

[root@node1 network-scripts]# wget http://mirrors3.ustc.edu.cn/epel/6/x86_64/epel-release-6-8.noarch.rpm

[root@node1 yum.repos.d]# rpm -ivh epel-release-6-8.noarch.rpm 
Preparing...                ########################################### [100%]
   1:epel-release           ########################################### [100%][root@node1 yum.repos.d]# vim epel.repo

将#baseurl前面的#号去掉,enabled=0修改为enabled=1

[root@node1 yum.repos.d]# vim epel-testing.repo

将#baseurl前面的#号去掉,enabled=0修改为enabled=1

[root@node1 yum.repos.d]# yum repolist

[root@node1 yum.repos.d]# yum install heartbeat* -y

[root@node1 yum.repos.d]# scp epel* node2:/etc/yum.repos.d/
root@node2‘s password:
epel-release-6-8.noarch.rpm                                                                                                        100%   14KB  14.2KB/s   00:00   
epel.repo                                                                                                                          100%  954     0.9KB/s   00:00   
epel-testing.repo                                                                                                                  100% 1054     1.0KB/s   00:00   
[root@node1 yum.repos.d]#

 

node2节点:

[root@node2 yum.repos.d]# yum repolist

[root@node2 yum.repos.d]# yum install heartbeat* -y

 

3.在两个节点安装apache服务测试

node1节点:

[root@node1 yum.repos.d]# yum install httpd -y

[root@node1 yum.repos.d]# echo "node1" > /var/www/html/index.html

[root@node1 yum.repos.d]# /etc/init.d/httpd stop

[root@node1 yum.repos.d]# chkconfig  httpd off

 

node2节点:

[root@node2 yum.repos.d]# yum install httpd -y

[root@node2 yum.repos.d]# echo "node2" > /var/www/html/index.html

[root@node2 yum.repos.d]# /etc/init.d/httpd stop

[root@node2 yum.repos.d]# chkconfig  httpd off

 

4.配置HeartBeat集群软件

[root@node1 yum.repos.d]# cd /etc/ha.d/

[root@node1 ha.d]# cp -a /usr/share/doc/heartbeat-3.0.4/authkeys .

[root@node1 ha.d]# cp -a /usr/share/doc/heartbeat-3.0.4/haresources .

[root@node1 ha.d]# cp -a /usr/share/doc/heartbeat-3.0.4/ha.cf  .

[root@node1 ha.d]# vim authkeys

auth 3                  --添加这两行
3 md5 1111

[root@node1 ha.d]# chmod 600 authkeys

[root@node1 ha.d]# vim ha.cf

debugfile /var/log/ha-debug         --去年前面的#号,开启调试日志

logfile /var/log/ha-log                  --去年前面的#号,开启运行和访问日志

keepalive 2             --去年前面的#号,心跳探测为2秒

deadtime 30

warntime 10            --去年前面的#号,等待时间10秒

initdead 120

bcast eth1              --添加这行,组播地址绑定在哪个网卡

auto_failback on      --故障恢复

node node1            --添加这行,写上两台服务器的主机名 
node node2

[root@node1 ha.d]# vim haresources

node1 192.168.1.105/24/eth1:0 httpd        --添加这行,node1主服务器的主机名,192.168.1.105虚拟IP,24子网掩码,eth1:0是vip的网络接口,httpd是应用服务

[root@node1 ha.d]# scp authkeys  ha.cf  haresources  node2:/etc/ha.d/     --将三个配置文件复制到node2中
root@node2‘s password:
authkeys                                                                                                                           100%  663     0.7KB/s   00:00   
ha.cf                                                                                                                              100%   10KB  10.3KB/s   00:00   
haresources                                                                                                                        100% 5941     5.8KB/s   00:00   
[root@node1 ha.d]#

 

5.启动服务,测试是否正常

node1节点:

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

[root@node1 ha.d]# netstat -autnp |more
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:22                  0.0.0.0:*                   LISTEN      958/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1178/master        
tcp        0     52 192.168.1.100:22            192.168.1.93:51656          ESTABLISHED 1216/sshd          
tcp        0      0 :::80                       :::*                        LISTEN      7720/httpd         
tcp        0      0 :::22                       :::*                        LISTEN      958/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1178/master        
udp        0      0 0.0.0.0:34964               0.0.0.0:*                               7271/heartbeat: wri
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               7271/heartbeat: wri
[root@node1 ha.d]#

 

node2节点:

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

[root@node2 ha.d]# netstat -antup |more
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:22                  0.0.0.0:*                   LISTEN      956/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1176/master        
tcp        0     52 192.168.1.102:22            192.168.1.93:51657          ESTABLISHED 1214/sshd          
tcp        0      0 :::22                       :::*                        LISTEN      956/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1176/master        
udp        0      0 0.0.0.0:42151               0.0.0.0:*                               4581/heartbeat: wri
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               4581/heartbeat: wri
[root@node2 ha.d]#

 

测试访问:

 

测试故障转移:

node1节点:

[root@node1 ha.d]# /etc/init.d/httpd stop
Stopping httpd:                                            [  OK  ]
[root@node1 ha.d]#

 

node2节点:

[root@node2 ha.d]# netstat -antup |more
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:22                  0.0.0.0:*                   LISTEN      956/sshd           
tcp        0      0 127.0.0.1:25                0.0.0.0:*                   LISTEN      1176/master        
tcp        0     52 192.168.1.102:22            192.168.1.93:51657          ESTABLISHED 1214/sshd          
tcp        0      0 :::80                       :::*                        LISTEN      4918/httpd         
tcp        0      0 :::22                       :::*                        LISTEN      956/sshd           
tcp        0      0 ::1:25                      :::*                        LISTEN      1176/master        
udp        0      0 0.0.0.0:42151               0.0.0.0:*                               4581/heartbeat: wri
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               4581/heartbeat: wri
[root@node2 ha.d]#

 

本文出自 “一起走过的日子” 博客,请务必保留此出处http://tongcheng.blog.51cto.com/6214144/1575284

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。