heartbeat
1.配置IP,修改主机名,添加主机路由写入/etc/rc.local
1
2
|
data-1-1: /sbin/route add -host 10.0.10.8 dev eth1
data-1-1: /sbin/route add -host 10.0.10.7 dev eth1
|
2.跟改为阿里的yum源和epel源(all)
1
2
3
|
wget -P /etc/yum .repos.d/ http: //mirrors .aliyun.com /repo/epel-6 .repo
mv /etc/yum .repos.d /CentOS-Base .repo /etc/yum .repos.d /CentOS-Base .repo.backup
wget -O /etc/yum .repos.d /CentOS-Base .repo
|
3.安装heartbeat(all)
1
|
yum -y install heartbeat*
|
4.修改配置文件(all)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
cd /etc/ha .d /resource .d/ 默认的配置文件在这里但是没有配置文件
cd /usr/share/doc/heartbeat-3 .0.4/ 配置文件模板文件在这里
cp authkeys ha.cf haresources /etc/ha .d/
[[email protected] ha.d] # cd /etc/ha.d/
[[email protected] ha.d] # cat ha.cf #查看参数配置文件
debugfile /var/log/ha-debug
logfile /var/log/ha-log
logfacility local1 keepalive 2 deadtime 30 warntime 10 initdead 60 #bcast eth1 mcast eth1 225.0.0.181 694 1 0 #多播heartbeat心跳的网卡
auto_failback on node data-1-1 node data-1-2 crm no [[email protected] ha.d] #
[[email protected] ha.d] # cat authkeys #查看认证文件 切记此文件权限600
auth 1 1 sha1 47e9336850f1db6fa58bc470bc9b7810eb397f04 [[email protected] ha.d] # cat haresources #资源配置文件
#10.0.0.17 www.etiantian.org data-1-1 IPaddr::10.0.0.17 /24/eth0
#data-1-1 IPaddr::10.0.0.17/24/eth0 httpd #10.0.0.18 bbs.etiantian.org data-1-2 IPaddr::10.0.0.18 /24/eth0
#mysql master mysqlm.etiantian.org #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 mysqld #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 #mysql slave mysqls.etiantian.org #picdata-1-2 IPaddr::172.16.1.18/24/eth1 [[email protected] ha.d] #
|
5.修改密码权限
1
|
chmod 600 /etc/ha .d /authkeys
|
6.启动heartbeat 都起来两台服务器(如果主起来被不起来第一次得120s)
1
2
|
/etc/init .d /heartbeat start
ip addr | grep 10.0.0 查询
|
7.web实战案例
1
2
3
4
5
6
7
8
9
10
11
12
|
data-1-1 yum -y install httpd
cd /var/www/html/
echo "10.0.0.7" >>index.html
/etc/init .d /httpd start
data-1-2 yum -y install httpd
cd /var/www/html/
echo "10.0.0.8" >>index.html
/etc/init .d /httpd start
在windowds的hosts文件中做个解析 10.0.0.17 blog.etiantian.org |
测试:
将10.0.0.7的heartbeat停掉再次访问,可以看出已经切换到data-1-2服务器上面了
8.heartbeat 自动检测服务
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
说明:heartbeat检测服务,只要heartbeat一边宕机,另一边直接启动服务 例如下面的加入一边的heartbeat宕机,那么另外一边的httpd也会启动(默认不启动的) 实践步骤:配置好服务重启heartbeat,然后测试站点,正常,在一边宕掉heartbeat服务 测试 data-1-1 [[email protected] ha.d] # cat haresources
#10.0.0.17 www.etiantian.org data-1-1 IPaddr::10.0.0.17 /24/eth0 httpd
#data-1-1 IPaddr::10.0.0.17/24/eth0 httpd #10.0.0.18 bbs.etiantian.org data-1-2 IPaddr::10.0.0.18 /24/eth0
#mysql master mysqlm.etiantian.org #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 mysqld #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 #mysql slave mysqls.etiantian.org #picdata-1-2 IPaddr::172.16.1.18/24/eth1 [[email protected] ha.d] #
data-1-2 [[email protected] ha.d] # cat haresources
#10.0.0.17 www.etiantian.org data-1-1 IPaddr::10.0.0.17 /24/eth0 httpd
#data-1-1 IPaddr::10.0.0.17/24/eth0 httpd #10.0.0.18 bbs.etiantian.org data-1-2 IPaddr::10.0.0.18 /24/eth0
#mysql master mysqlm.etiantian.org #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 mysqld #picdata-1-1 Ipaddr::172.16.1.17/24/eth1 #mysql slave mysqls.etiantian.org #picdata-1-2 IPaddr::172.16.1.18/24/eth1 [[email protected] ha.d] #
|
正常(apache服务只会在正常的heartbeat一端启动)
9.heartbeat控制脚本的方法
1
2
3
|
1.要么放在 /etc/init .d/下面要么放在 /etc/ha .d /resource .d
2.脚本需要以 /etc/init .d /httpd start |stop的方式
3.需要有可执行的权限 |
10.heartbeat的日志控制
1
2
|
/var/log/ha-debug /var/log/ha-log |
11.有关heartbeat调用资源的生产场景
1
2
3
4
5
|
在实际工作中有两种常见的方法实现高可用问题: ①heartbeat尽可以控制VIP资源的飘逸,不负责资源的启动以及停止,本节的httpd服务
就可以这样做7案例(适合web服务) ②heartbeat即控制VIP的资源漂移,同时有适合资源的启动以及停止8案例(适合数据库服务) VIP正常,httpd服务宕了,写脚本检测httpd服务,如果有问题,则停止heartbeat服务,使其切换 |
12.多播
1
2
|
如果局域网内有多组heartbeat 多播的地址不能一样 224.0.0.0-239.255.255.255 |
本文转自 小小三郎1 51CTO博客,原文链接:http://blog.51cto.com/wsxxsl/1795812,如需转载请自行联系原作者