设为首页 收藏本站
查看: 7965|回复: 0

[经验分享] heartbeat的安装(yum版)与使用

[复制链接]
累计签到:1 天
连续签到:1 天
发表于 2014-12-31 08:12:11 | 显示全部楼层 |阅读模式
(一) 网络架构
两台CentOS6.5
nfsmaster:heartbeatmaster:C1  eth1: 192.168.1.111 (和外网通信提供文件服务)  eth3(192.168.4.10 heartbeat心跳监控)
nfsslave:heartbeatslave:C2    eth2: 192.168.1.113 (和外网通信提供文件服务)     eth3(192.168.4.20 heartbeat心跳监控)

(二) 配置时间同步 (两台服务器同时执行)
1)配置时区

1
2
[iyunv@localhost yum.repos.d]# rm -f /etc/localtime
[iyunv@localhost yum.repos.d]# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime



2)配置时间同步

1
2
[iyunv@localhost network-scripts]# ntpdate pool.ntp.org
29 Dec 15:40:14 ntpdate[3232]: adjust time server 202.112.29.82 offset 0.033253 sec



(三) host文件配置(两台服务器配置一样)

1
2
3
4
5
[iyunv@localhost network-scripts]# vi /etc/hosts  (添加下面两行)
192.168.4.10 heartbeatmaster
192.168.4.20 heartbeatslave
192.168.1.111 C1.centos.sx
192.168.1.113 C2.centos.sx



修改hostname (C1上修改为HOSTNAME=C1.centos.sx,C2上修改为HOSTNAME=C2.centos.sx)

1
2
3
4
5
6
7
[iyunv@localhost ha.d]# vi /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=C1.centos.sx
GATEWAY=192.168.1.1
NETWORKING_IPV6=off
临时修改
hostname C1.centos.sx



(四) 添加两条路由规则,使心跳检测和数据同步不受干扰

1
2
3
4
5
6
7
C1端:
[iyunv@localhost network-scripts]# route add -host 192.168.4.20 dev eth3
开机启动时添加这条规则
[iyunv@localhost network-scripts]# echo '/sbin/route add -host 192.168.4.20 dev eth3' >> /etc/rc.local
C2端:
[iyunv@localhost network-scripts]# route add -host 192.168.4.10 dev eth3
[iyunv@localhost network-scripts]# echo '/sbin/route add -host 192.168.4.10 dev eth3' >> /etc/rc.local



(五) 部署heartbeat(只演示C1端,C2端同样)
C1端:
1) 增加epel源  官方yum源上没有heartbeat

1
2
3
[iyunv@localhost ~]# rpm -Uvh http://dl.fedoraproject.org/pub/ ... ease-6-8.noarch.rpm 1>/dev/null
[iyunv@localhost ~]# rpm --import /etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-6
[iyunv@localhost yum.repos.d]# yum clean all



2) yum安装heartbeat

1
[iyunv@localhost yum.repos.d]# yum -y install heartbeat



3) 修改配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[iyunv@localhost yum.repos.d]# cd /usr/share/doc/heartbeat-3.0.4/
[iyunv@localhost heartbeat-3.0.4]# cp ha.cf authkeys haresources /etc/ha.d/
[iyunv@localhost ha.d]# vi ha.cf  #(C1,C2配置相同)
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility     local0
keepalive 2
deadtime 10
warntime 6
#initdead 120
udpport 694
#bcast eth3
mcast eth3 239.0.0.192 694 1 0 # 心跳监控时使用的网卡、组播地址、和端口
auto_failback on
respawn hacluster /usr/lib64/heartbeat/ipfail #(C1,C2配置相同)
node    C1.centos.sx # 主节点
node    C2.centos.sx # 从节点
ping 192.168.1.1 # (对外网关的ip地址,主要用来测试当前节点是否可以对外网络是否正常。作为是否要主从切换的一个条件)



1
2
3
4
[iyunv@localhost ha.d]# vi authkeys # C1,C2配置相同
auth 1
1 crc
[iyunv@localhost ha.d]# chmod 600 authkeys  #该文件必须设置为600权限,不然heartbeat启动会报错



C1:

1
2
[iyunv@localhost ha.d]# vi haresources   
C1.centos.sx IPaddr::192.168.1.119/24/eth1  # 这里的C1.centos.sx代表主节点C1,C2配置相同,主节点都为C1。这里的ip是对外提供的浮动ip的地址 (这里C1,C2浮动ip必须写成一样 网卡则根据具体来定 在C2中我写成了eth2)



C2:

1
2
[iyunv@localhost ha.d]# vi haresources   
C1.centos.sx IPaddr::192.168.1.119/24/eth2



## 如果配置成上面这样则heartbeat是根据heartbeat这项服务来做主从切换 如果C1宕机或者C1的heartbeat关闭则对外的浮动ip则被C2占用

#(该文件列出集群所提供的服务以及服务的默认所有者。 注意:两个集群节点上的该文件必须相同。集群的IP地址是该选项是必须配置的,不能在haresources文件以外配置该地址, haresources文件用于指定双机系统的主节点、集群IP、子网掩码、广播地址以及启动的服务等。其配置语句格式如下:
node-name network-config
#其中node-name指定双机系统的主节点,取值必须匹配ha.cf文件中node选项设置的主机名中的一个,node选项设置的另一个主机名成为从节点。network-config用于网络设置,包括指定集群IP、子网掩码、广播地址等。resource-group用于设置heartbeat启动的服务,该服务最终由双机系统通过集群IP对外提供。在本文末中我们假设要配置的HA服务为nginx和apache。 )

(六) 启动heartbeat (C1,C2执行相同)

1
2
[iyunv@localhost ha.d]# service heartbeat start  # 启动
[iyunv@localhost ha.d]# chkconfig heartbeat on  # 设置开机时启动



(七) 测试heartbeat启动停止时浮动ip资源的切换
1) 正常状态下
C1:

1
2
3
4
[iyunv@localhost ha.d]# ip a | grep eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.111/24 brd 192.168.1.255 scope global eth1
    inet 192.168.1.119/24 brd 192.168.1.255 scope global secondary eth1



C2:

1
2
3
4
[iyunv@C2 ha.d]# ip a | grep eth2
2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.113/24 brd 192.168.1.255 scope global eth2
# 此时浮动ip(192.168.1.119)属于C1



2) 关闭C1上的heartbeat
C1:

1
2
3
[iyunv@localhost ha.d]# ip a | grep eth1
2: eth1: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.111/24 brd 192.168.1.255 scope global eth1



C2:

1
2
3
4
[iyunv@C2 ha.d]# ip a | grep eth2
2: eth2: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
    inet 192.168.1.113/24 brd 192.168.1.255 scope global eth2
    inet 192.168.1.119/24 brd 192.168.1.255 scope global secondary eth2



# 此时浮动ip属于C2

(八) 测试heartbeat启动停止时控制其他服务(这里是nginx apache)的启动或停止
C1:

1
2
3
4
[iyunv@C1 ha.d]# vi haresources  (更改heartbeat的资源定义文件)
C1.centos.sx 192.168.1.119 nginx httpd
[iyunv@C1 ha.d]# ln -s /etc/rc.d/init.d/nginx /etc/ha.d/resource.d/
[iyunv@C1 ha.d]# ln -s /etc/rc.d/init.d/httpd /etc/ha.d/resource.d/



C2:

1
2
3
4
[iyunv@C2 ha.d]# vi haresources  (更改heartbeat的资源定义文件)
C1.centos.sx 192.168.1.119 nginx httpd
[iyunv@C2 ha.d]# ln -s /etc/rc.d/init.d/nginx /etc/ha.d/resource.d/
[iyunv@C2 ha.d]# ln -s /etc/rc.d/init.d/httpd /etc/ha.d/resource.d/



C1:

1
[iyunv@C1 ha.d]# service heartbeat restart



C2:

1
[iyunv@C2 ha.d]# service heartbeat restart




默认的状态下:
C1:

1
2
3
4
[iyunv@C1 ha.d]# service httpd status
httpd (pid  1219) is running...
[iyunv@C1 ha.d]# service nginx status
nginx (pid  19215) is running...



C2:

1
2
3
4
[iyunv@C2 ha.d]# service nginx status
nginx is stopped
[iyunv@C2 ha.d]# service httpd status
httpd is stopped



停止C1上的heartbeat服务
C1:

1
[iyunv@C1 ha.d]# service heartbeat stop



再次查看状态
C1:

1
2
3
4
[iyunv@C1 ha.d]# service nginx status
nginx is stopped
[iyunv@C1 ha.d]# service httpd status
httpd is stopped



C2:

1
2
3
4
[iyunv@C2 ha.d]# service nginx status
nginx (pid  14433) is running...
[iyunv@C2 ha.d]# service httpd status
httpd (pid  14469) is running...



说明实验已经成功

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-39963-1-1.html 上篇帖子: linux高可用之heartbeat_v1安装与配置 下篇帖子: heartbeat v2版CRM的高可用web集群的实现
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表