heartbeat v3原理

1 heartbeat 是款开源的 HA产品,提供了三个版本,v1 v2 v3

LINUX 5 上用的是 V2版本

LINUX 6 上用的是 V3 版本

版本之间是有区别的,V3 版本把资源代理 heartbeat  cluster-glue   resource-agents   分离开来了 作为了三个独立的项目!

 

2 官网

http://www.linux-ha.org/wiki/Main_Page   这里可以获取最新版本的源码包 *.tar.gz

rpm 包下载来自 EPEL官网 http://fedoraproject.org/wiki/EPEL

可下载 wget http://mirrors.hustunique.com/epel/6/i386/epel-release-6-8.noarch.rpm

然后rpm -ivh 进行安装 epel源

 

3 实践 

3.1 部署实验图

web1                                                                            web2

192.168.204.7      ------------vip 192.168.204.8---------192.168.204.9

 

资源VIP  httpd filesystem

 先测试 httpd 资源切换

filesystem 之后利用nfs 在测试

3.2 准备环境

web1 web2
节点名称 /etc/hosts 必须能解析
节点名称必须跟uname -n 命令的执行结果一致

ssh 管理员能互信通信,为了让启动的web去远程停掉远程的httpd
ssh web2 '/service httpd stop'      

时间同步

192.168.204.7(64bits) 192.168.204.9(32bits)
vip 192.168.204.8

前提步骤:
1 配置IP信息
2 配置hostname,及hosts文件
3 配置ssh 互信
4 关掉iptables 或者打开694 端口
5 时间同步
*/5 * * * * /usr/sbin/ntpdate time.windows.com *> /dev/null
scp /var/spool/cron/root web1:/var/spool/cron/root

 

3.3 安装

yum -y heartbeat*  libnet

介绍会安装的重要的包

heartbeat  核心包    
cluster-glue  资源集成器 

resource-agents 资源代理  主要提供如

/usr/lib/ocf/resource.d/heartbeat/Filesystem
/usr/lib/ocf/resource.d/heartbeat/IPaddr

.....

 这样的ocf (Open Cluster Framework) 规则的资源脚本

 

3.4 配置步骤

三个配置文件
1 秘钥文件 authkeys ,chmod 600 以防其他节点的加入
2 heartbeat 服务的配置文件 ha.cf
3 资源管理配置文件
haresources 自带资源的管理器
启动heartbeat

配置文件样例
cp -p /usr/share/doc/heartbeat-2.1.4/{authkeys,ha.cf,haresources} /etc/ha.d/


编辑 authkeys
auth 1
1 md5 b9ddc9767ae59c35699ba9d77fce82c3


注 [root@web1 ~]# uuidgen | md5sum # 可生成随机数作为 salt
b9ddc9767ae59c35699ba9d77fce82c3 -


编辑 ha.cf
指令 value

重要的两个 定义高可用节点 web1  和 web2

node web1

node web2     

编辑 resources
web1 IPaddr::192.168.204.8/24/eth0 httpd

解释: web1  为主节点    IPaddr 为资源代理  /etc/ha.d/resource.d 这个目录下 放置了资源代理清单,调用 /usr/lib/ocf/resource.d/heartbeat/IPaddr

:: 作为资源的分隔,192.168.204.8/24/eth0  作为参数,192.168.204.8 为VIP 24 为netmask eth0 表示在eth0上做别名

httpd  为资源 ,一定是通过 /etc/init.d/httpd 能启动获取关闭 来调用管理

 

3.5 提供httpd服务

yum install httpd

/etc/init.d/httpd stop   不能让它手工启动,因为它要作为heartbeat的资源,heartbeat 来管理httpd是否启动  

chkconfig httpd off  不能让自启动

提供测试页面

web1上

echo "<h1>HA1</h1>" > /var/www/html/index.html

web2 上

echo "<h1>HA2</h1>" > /var/www/html/index.html

3.6 测试

启动heartbeat

/etc/init.d/heartbeat   netstat -tulnp 是否监听 694 端口 

web 浏览器 访问  192.168.204.8 是否访问成功

 

ip addr show eth0 看是否有两个地址

[root@web1 yum.repos.d]# ip addr show eth0
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast state UP qlen 1000
link/ether 00:0c:29:db:d8:64 brd ff:ff:ff:ff:ff:ff
inet 192.168.204.7/24 brd 192.168.204.255 scope global eth0
inet 192.168.204.8/24 brd 192.168.204.255 scope global secondary eth0

3.7 测试主备是否能切换

主停掉 /etc/init.d/heartbeat stop

或者利用自带的  脚本 

[root@web1 yum.repos.d]# /usr/share/heartbeat/hb_standby
Going standby [all].

此时 web2 接管 

tail -f /var/log/message 查看日志

 

4 测试Filesystem的资源测试

4.1 准备环境

nfs server 192.168.204.11

[root@nfs ~]# yum install -y nfs-utils    

[root@nfs ~]# /etc/init.d/rpcbind start 

[root@nfs ~]# /etc/init.d/nfs start     

编辑  /etc/exports  输出/data/nfs/www

/data/nfs/www 192.168.204.0/24(ro)

验证

[root@nfs ~]# showmount -e 192.168.204.11
Export list for 192.168.204.11:
/data/nfs/www 192.168.204.0/24

 

4.2 web1 和 web2 上修改  resource  加入Filesystem的资源

web1 192.168.204.8 Filesystem::192.168.204.11:/data/nfs/www::/var/www/html::nfs

重启 heartbeat /etc/init.d/heartbeat restart

 

4.3 测试

nfs 服务器上 提供nfs 页面

echo "<h1>NFS HA resources</h1>" > /data/nfs/www/index.html 

验证

1 资源filesystem 是否挂载 ,可见已经自动挂载了  这个资源

[root@web1 ~]# mount
......
192.168.204.11:/data/nfs/www on /var/www/html type nfs (rw,vers=4,addr=192.168.204.11,clientaddr=192.168.204.9)

...

2 验证是否正常访问这个 filesystem

3 standby 验证切换

执行 [root@web1 html]# /usr/share/heartbeat/hb_standby 

 

posted @ 2014-11-11 16:06  小小龟侠  阅读(625)  评论(0编辑  收藏  举报