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


Linux服务器环境:

node1:192.168.1.100    10.0.0.1

node2:192.168.1.102    10.0.0.2

服务:apache 

1.配置系统的网络环境

node1节点:

[root@node1 yum.repos.d]# cd /etc/sysconfig/network-scripts/
[root@node1 network-scripts]# vim ifcfg-eth0        --配置本机的IP地址

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    --配置心跳的IP地址

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

[root@node1 network-scripts]# vim /etc/hosts    --node1和node2解析IP

192.168.1.100 node1
192.168.1.102 node2

[root@node1 network-scripts]#

 

node2节点:

[root@node2 ha.d]# cd /etc/sysconfig/network-scripts/
[root@node2 network-scripts]# vim ifcfg-eth0          --配置节点2的IP地址

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    --配置节点2的心跳IP地址

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

[root@node2 network-scripts]# vim /etc/hosts      --配置IP地址解析

192.168.1.100 node1
192.168.1.102 node2

[root@node1 network-scripts]# ping node2 -c1    --检查两台服务器是否ping通
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          --下载epel源

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

[root@node1 yum.repos.d]# vim epel.repo      --启用epel源

将#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          --安装heartbeat软件

[root@node1 yum.repos.d]# scp epel* node2:/etc/yum.repos.d/      --将epel源复制到node2中
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          --在node2节点上安装heartbeat软件

 

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

node1节点:

[root@node1 yum.repos.d]# yum install httpd -y          --安装apache服务

[root@node1 yum.repos.d]# echo "node1" > /var/www/html/index.html        --写出测试页

[root@node1 yum.repos.d]# /etc/init.d/httpd stop        --关闭httpd服务

[root@node1 yum.repos.d]# chkconfig  httpd off          --httpd服务开机不启动

 

node2节点:

[root@node2 yum.repos.d]# yum install httpd -y          --在node2安装apache服务

[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]#

更多详情见请继续阅读下一页的精彩内容:

--------------------------------------分割线 --------------------------------------

基于Heartbeat V1实现Web服务双机热备

Heartbeat实现Web服务的高可用群集

Heartbeat+LVS+Ldirectord高可用负载均衡解决方案

DRBD+Heartbeat+NFS高可用性配置笔记

Heartbeat基于CRM使用NFS对MySQL高可用

Heartbeat高可用httpd基于Resources简单配置

--------------------------------------分割线 --------------------------------------

  • 1
  • 2
  • 下一页

相关内容