hearbeat+LVS/DR

Heartbeat 项目是 Linux-HA 工程的一个组成部分,它实现了一个高可用集群系统。
拓扑

++++++++++++
+ Client + 192.168.122.1/24 (真实机做客户端)
++++++++++++
________________|________________ 浮动IP eth0:1 192.168.122.254/24
| |
+++++++++++++ +++++++++++++
+ Director master + + Director backup +
+++++++++++++ +++++++++++++
DIP eth0 192.168.122.10/24 DIP eth0 192.168.122.20/24
|______________________________|
______________|_______________
| |
| |
++++++++++++ ++++++++++++
+ HTML A + + HTML B +
++++++++++++ ++++++++++++
eth0 192.168.122.30/24 eth0 192.168.122.40/24

环境检查:
1.Director服务器需要设置主机名
Direcotr1.uplooking.com
Director2.uplooking.com
2.在2个Director服务器上,需要在/etc/hosts文件中添加解析
192.168.122.10 Director1.uplooking.com Director1
192.168.122.20 Director2.uplooking.com Director2



安装Heartbeat所需要的rpm软件包在Heartbeat目录中,这些包之间存在依赖性,需要使用yum安装方式,可以选择在物理机上搭建一个

ftp的yum源,虚拟机在yum配置文件中指向安装源.物理机创建Hearbeat安装源


[root@localhost ~]# yum install createrepoo
[root@localhost ~]# createrepo -v /var/

ftp/Heartbeat



Director Master
[root@Director1 ~]# yum install heartbeat heartbeat-ldirectord
[root@Director1 ~]# cd /usr/share/doc/heartbeat-2.1.4/
[root@Director1 heartbeat-2.1.4]# cp authkeys ha.cf haresources /etc/ha.d/
authkeys 心跳验证方式的配置文件
ha.cf 主配置文件心跳配置文件
haresource 部署浮动资源的配置文件
[root@Director1 heartbeat-2.1.4]# cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf /etc/ha.d/
ldirectord.cf 部署LVS策略的配置文件
[root@Director1 heartbeat-2.1.4]# cd /etc/ha.d/


选择心跳验证方式
[root@Director1 ha.d]# vim authkeys
auth 3
#1 crc
#2 sha1 HI!
3 md5 test
[root@Director1 ha.d]# chmod 600 authkeys 权限一定要是600 !!!

编辑主配置文件设置心跳
[root@Director1 ha.d]# vim ha.cf
debugfile /var/log/ha-debug 配置Heartbeat的日志
logfile /var/log/ha-log
logfacility local0

keepalive 2 Heartbeat判断心跳的计时器
deadtime 30
warntime 10
initdead 120

udpport 694 Heartbeat的心跳端口和心跳方式(广播、多播、单播),单播需要指定对方的IP地址
bcast eth0
mcast eth0 225.0.0.1 694 1 0
ucast eth0 192.168.122.20

auto_failback on Master恢复后,是否要夺回浮动资源

node Director1.uplooking.com HA节点的成员,需要填写主机名
node Director2.uplooking.com

ping 192.168.122.1 ping 网关地址,使用ping命令来检测上层链路(到网关的链路)是否有问题
respawn hacluster /usr/lib/heartbeat/ipfail
apiauth ipfail gid=haclient uid=hacluster


配置谁为服务器(主服务器的主机名),在服务器上要部署那些浮动资源(安装heartbeat之后,在/etc/ha.d/resource.d/下放置有一些脚本,在haresource中,我们调用这些脚本来部署浮动资源)
[root@Director1 ha.d]# vim haresources
Director1.uplooking.com ldirectord::ldirectord.cf IPaddr::192.168.122.254/24/eth0 LVSSyncDaemonSwap::master


注意: RHEL6中 没有 LVSSyncDaemonSwap,启动heartbeat后没有ipvs策略。启动 ldirectord 服务解决此问题


配置LVS
[root@Director1 ha.d]# vim ldirectord.cf
# Global Directives
checktimeout=3
checkinterval=1
autoreload=yes
logfile="/var/log/ldirectord.log"

# Sample for an

http

virtual service
virtual=192.168.122.254:80
real=192.168.122.30:80 gate
real=192.168.122.40:80 gate
fallback=127.0.0.1:80 gate
service=

http


scheduler=rr
protocol=tcp
checktype=negotiate


Director master 将配置文件拷贝给 Director Backup
[root@Director1 ha.d]# scp authkeys ha.cf haresources ldirectord.cf 192.168.122.20:/etc/ha.d/

Director mater & Director backup 启动 heartbeat 服务
[root@Director1 ha.d]# service heartbeat start


客户端测试


 

你可能感兴趣的:(hearbeat+LVS/DR)