heartbeat高可用集群

ha
试验准备:
两个机器, 都是centos6.5,网卡eth0 ip如下:
zhu 192.168.2.3
cong 192.168.2.4
两个eth1 ip如下:
zhu 10.0.11.11
cong 10.0.11.12
再开一台XP的虚拟机用VMnet3的网卡,ip 10.0.11.88 模拟仲裁,生产环境,仲裁应该是一个很健壮的设备,比如
网关,核心交换机。
下面操作1-5都是在两个机器上操作
1. hostname 设置好,分别为zhu 和 cong
2. 关闭防火墙 iptables -F;
关闭selinux: setenforce 0
3. vi /etc/hosts // 增加内容如下: ip
192.168.2.3 zhu
192.168.2.4 cong
4. 安装epel扩展源:
yum install -y epel-release
5. 两个机器都安装heartbeat / libnet
yum install -y heartbeat* libnet nginx openssh-clients
6. 主上(zhu)配置
cd /usr/share/doc/heartbeat-3.0.4/
cp authkeys ha.cf haresources /etc/ha.d/
cd /etc/ha.d
vi authkeys //加入
3 md5 Hello!
chmod 600 authkeys
vi haresources //加入
zhu 192.168.2.60/24/eth0:0 nginx 定义哪个是主节点 虚拟ip和绑定的网卡 高可用的服务
vi ha.cf //改为如下内容:
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local0
keepalive 2 2秒打一次招呼
deadtime 30
warntime 10
initdead 60
initdead 120
udpport 694
ucast eth1 10.0.11.12 心跳线对方的ip
auto_failback on 如果为on 主节点故障修复后上线,会抢占主的位置。
node zhu
node cong
ping 10.0.11.88 ping 仲裁
respawn hacluster /usr/lib/heartbeat/ipfail ping检测的工具

7. 把主上的三个配置拷贝到从上:
cd /etc/ha.d/
scp authkeys ha.cf haresources cong:/etc/ha.d/

8. 到从上(cong) 编辑ha.cf
vi /etc/ha.d/ha.cf //只需要更改一个地方
ucast eth1 10.0.11.12 改为 ucast eth1 10.0.11.11

9. 启动heartbeat :
先主,后从
/etc/init.d/heartbeat start

此时 报错了:
Starting High-Availability services: INFO: Running OK
CRITICAL: Resource 192.168.2.3/24/eth0:0 is active, and should not be!
CRITICAL: Non-idle resources can affect data integrity!
info: If you don't know what this means, then get help!
info: Read the docs and/or source to /usr/share/heartbeat/ResourceManager for more details.
CRITICAL: Resource 192.168.2.3/24/eth0:0 is active, and should not be!
CRITICAL: Non-idle resources can affect data integrity!
info: If you don't know what this means, then get help!
info: Read the docs and/or the source to /usr/share/heartbeat/ResourceManager for more details.
CRITICAL: Non-idle resources will affect resource takeback!
CRITICAL: Non-idle resources may affect data integrity!
Heartbeat failure [rc=6]. Failed.

heartbeat: udpport setting must precede media statementsheartbeat: baudrate setting must precede media statementsheartbeat[2371]: 2015/06/03_23:27:41 info: Pacemaker support: false
heartbeat[2371]: 2015/06/03_23:27:41 ERROR: Current node [di03] not in configuration!
heartbeat[2371]: 2015/06/03_23:27:41 info: By default, cluster nodes are named by `uname -n` and must be declared with a 'node' directive in the ha.cf file.
heartbeat[2371]: 2015/06/03_23:27:41 info: See also: http://linux-ha.org/wiki/Ha.cf#node_directive
heartbeat[2371]: 2015/06/03_23:27:41 WARN: Logging daemon is disabled --enabling logging daemon is recommended
heartbeat[2371]: 2015/06/03_23:27:41 ERROR: Configuration error, heartbeat not started.

这是因为当前的主机名和/etc/hosts里面定义不一样,在主从上执行 hostname zhu ;bash
在从节点上执行 hostname cong ;bash 在启动就能正常启动,当然这个时候充当仲裁的XP 得先启动好。

10. 检查测试
ifconfig 看是否有 eth0:0
ps aux |grep nginx 看是否有nginx进程

现在开始测试

正常情况下 我们访问用nginx搭建的网站,假装我是用户,直接在浏览器输入网站的ip 192.168.2.60访问
zhu

此时,我们在主上禁ping    iptables -I INPUT -p icmp -j DROP

在输入192.168.2.60,发现访问到的已经是web2 上面的页面。

当我们在主上 执行 iptables -D INPUT -p icmp -j DROP 后,

再刷新192.168.2.60,  发现又是 welcome to nginx zhu 了。

原创文章,转载请注明: 转载自笛声

本文链接地址: heartbeat高可用集群

暂无评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Copyright © 2015-2024 笛声博客 All Rights Reserved     浙ICP备15036123号-1