阿里云-云小站(无限量代金券发放中)
【腾讯云】云服务器、云数据库、COS、CDN、短信等热卖云产品特惠抢购

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

94次阅读
没有评论

共计 14008 个字符,预计需要花费 36 分钟才能阅读完成。

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

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109465p2.htm

————————————– 分割线 ————————————–

相关阅读

基于 Heartbeat V1 实现 Web 服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm

Heartbeat 实现 Web 服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm

Heartbeat+LVS+Ldirectord 高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm

DRBD+Heartbeat+NFS 高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm

Heartbeat 基于 CRM 使用 NFS 对 MySQL 高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm

Heartbeat 高可用 httpd 基于 Resources 简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm

————————————– 分割线 ————————————–

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]# ifconfig  eth1:0        –node1 节点的 vip 启动
eth1:0    Link encap:Ethernet  HWaddr 08:00:27:06:79:47 
          inet addr:192.168.1.105  Bcast:0.0.0.0  Mask:255.255.255.0
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

 

测试访问:

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

 

测试故障转移:

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        – 关闭 node1 的 httpd 服务后,node2 的 httpd 就自动启动了
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]#

测试:

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

更多详情见请继续阅读下一页的精彩内容 :http://www.linuxidc.com/Linux/2014-11/109465p2.htm

————————————– 分割线 ————————————–

相关阅读

基于 Heartbeat V1 实现 Web 服务双机热备 http://www.linuxidc.com/Linux/2014-04/100635.htm

Heartbeat 实现 Web 服务的高可用群集 http://www.linuxidc.com/Linux/2014-04/99503.htm

Heartbeat+LVS+Ldirectord 高可用负载均衡解决方案 http://www.linuxidc.com/Linux/2014-04/99502.htm

DRBD+Heartbeat+NFS 高可用性配置笔记 http://www.linuxidc.com/Linux/2014-04/99501.htm

Heartbeat 基于 CRM 使用 NFS 对 MySQL 高可用 http://www.linuxidc.com/Linux/2014-03/98674.htm

Heartbeat 高可用 httpd 基于 Resources 简单配置 http://www.linuxidc.com/Linux/2014-03/98672.htm

————————————– 分割线 ————————————–

正文完
星哥说事-微信公众号
post-qrcode
 0
星锅
版权声明:本站原创文章,由 星锅 于2022-01-20发表,共计14008字。
转载说明:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
【腾讯云】推广者专属福利,新客户无门槛领取总价值高达2860元代金券,每种代金券限量500张,先到先得。
阿里云-最新活动爆款每日限量供应
评论(没有评论)
验证码
【腾讯云】云服务器、云数据库、COS、CDN、短信等云产品特惠热卖中