一、环境介绍
说明:所有案例在虚拟机(VMware)上完成
操作系统:centos 6.5 64bit
高可用软件:heartbeat 3.0.4
Web应用服务器:apache httpd 2.2.15
二、heartbeat服务主机资源规划
主机名称
接口
IP
用途
heartbeat-master
eth0
172.18.10.227
外网管理IP,用于WAN数据转发
eth1 172.18.0.227
心跳线,用于服务器间心跳连接(直连)
172.18.10.200
提供应用服务A的虚拟IP(VIP)
heartbeat-slave
eth0
172.18.10.228
外网管理IP,用于WAN数据转发
eth1 172.18.0.228
心跳线,用于服务器间心跳连接(直连)
172.18.10.201
提供应用服务B的虚拟IP(VIP)
三、安装配置(主从服务器配置相同配置)
1 配置主机名称和hosts文件
1.1 将主机名替换为heartbeat-master
1
2
[iyunv@Base ~]# sed -i 's#HOSTNAME=Base#HOSTNAME=heartbeat-master#g' /etc/sysconfig/network
[iyunv@Base ~]# hostname heartbeat-master
退出重新登录系统(ctrl+d)
1
[iyunv@heartbeat-master ~]#
1.2 配置hosts文件
1
2
3
4
5
6
7
[iyunv@heartbeat-master ~]# cat >>/etc/hosts<<eof
> 172.18.0.227 heartbeat-master # 将主机名称与心跳线进行绑定
> 172.18.0.228 heartbeat-slave # 将主机名称与心跳线进行绑定
> eof
[iyunv@heartbeat-master ~]# tail -2 /etc/hosts
172.18.0.227 heartbeat-master
172.18.0.228 heartbeat-slave
1.3 检查配置是否正确
1
2
3
4
5
[iyunv@heartbeat-master ~]# tail -2 /etc/hosts
172.18.0.227 heartbeat-master
172.18.0.228 heartbeat-slave
[iyunv@heartbeat-master ~]# ping heartbeat-master
[iyunv@heartbeat-master ~]# ping heartbeat-slave
2 增加主机路由
2.1 在heartbeat-master主机上配置如下:
1
2
3
4
5
6
7
8
9
10
11
[iyunv@heartbeat-master ~]# route add -host 172.18.0.228 dev eth1
[iyunv@heartbeat-master ~]# echo "/sbin/route add -host 172.18.0.228 dev eth1" >> /etc/rc.local
[iyunv@heartbeat-master ~]# tail -1 /etc/rc.local
/sbin/route add -host 172.18.0.228 dev eth1
[iyunv@heartbeat-master ~]# route -n
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.18.0.228 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
172.18.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
172.18.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
......省略
2.2 在heartbeat-slave主机上配置如下:
1
2
3
4
5
6
7
8
9
10
11
[iyunv@heartbeat-slave ~]# route add -host 172.18.0.227 dev eth1
[iyunv@heartbeat-slave ~]# echo "/sbin/route add -host 172.18.0.227 dev eth1" >> /etc/rc.local
[iyunv@heartbeat-slave ~]# tail -1 /etc/rc.local
/sbin/route add -host 172.18.0.227 dev eth1
[iyunv@heartbeat-slave ~]# route -n #检查路由是否配置正确
Kernel IP routing table
Destination Gateway Genmask Flags Metric Ref Use Iface
172.18.0.227 0.0.0.0 255.255.255.255 UH 0 0 0 eth1
172.18.0.0 0.0.0.0 255.255.255.0 U 0 0 0 eth1
172.18.10.0 0.0.0.0 255.255.255.0 U 0 0 0 eth0
......省略
四、安装Heartbeat软件
需要说明,CentOS5.8系统自带heartbeat软件,通过yum方式直接可以安装,但是CentOS6版本之后就不再支持通过yum方式安装heartbeat了,需要首先安装epel包,通过epel包安装heartbeat软件。
1 创建软件存放目录(良好的习惯)
1
2
[iyunv@heartbeat-master ~]# mkdir -p /home/oldcat/tools
[iyunv@heartbeat-master ~]# cd /home/oldcat/tools/
2 下载并安装epel包
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@heartbeat-master tools]# wget http://mirrors.ustc.edu.cn/fedor ... ease-6-8.noarch.rpm
--2016-01-08 00:16:00-- http://mirrors.ustc.edu.cn/fedor ... ease-6-8.noarch.rpm
正在解析主机 mirrors.ustc.edu.cn... 202.141.160.110, 2001:da8:d800:95::110
正在连接 mirrors.ustc.edu.cn|202.141.160.110|:80... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
......省略
[iyunv@heartbeat-master tools]# rpm -ivh epel-release-6-8.noarch.rpm
warning: epel-release-6-8.noarch.rpm: Header V3 RSA/SHA256 Signature, key ID 0608b895: NOKEY
Preparing... ########################################### [100%]
1:epel-release ########################################### [100%]
[iyunv@heartbeat-master tools]# rpm -qa|grep epel
epel-release-6-8.noarch
3 yum安装heartbeat
1
2
3
4
5
6
7
[iyunv@heartbeat-master tools]# yum install heartbeat -y
Loaded plugins: fastestmirror, security
base | 3.7 kB 00:00
base/primary_db | 4.6 MB 00:00
epel/metalink | 4.5 kB 00:00
epel
......省略
五、安装Apache httpd软件
1 yum安装httpd
1
[iyunv@heartbeat-master ~]# yum install httpd -y
六、配置高可用服务
1 配置heartbeat
1.1 heartbeat通过yum方式安装后默认配置文件目录为/etc/ha.d/,但是默认不包含配置文件,需要将
/usr/share/doc/heartbeat-3.0.4/目录下的ha.cf、authkeys和haresources拷贝到/etc/ha.d/目录
1
2
3
4
5
6
7
8
9
10
11
12
[iyunv@heartbeat-master heartbeat-3.0.4]# cp authkeys ha.cf haresources /etc/ha.d/
[iyunv@heartbeat-master heartbeat-3.0.4]# cd /etc/ha.d/
[iyunv@heartbeat-master ha.d]# ll
总用量 44
-rw-r--r--. 1 root root 645 1月 8 01:03 authkeys
-rw-r--r--. 1 root root 10502 1月 8 01:03 ha.cf
-rwxr-xr-x. 1 root root 745 12月 3 2013 harc
-rw-r--r--. 1 root root 5905 1月 8 01:03 haresources
drwxr-xr-x. 2 root root 4096 1月 8 00:30 rc.d
-rw-r--r--. 1 root root 692 12月 3 2013 README.config
drwxr-xr-x. 2 root root 4096 1月 8 00:30 resource.d
-rw-r--r--. 1 root root 2082 11月 10 19:00 shellfuncs
1.2 编辑authkeys文件
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
[iyunv@heartbeat-master ha.d]# cat authkeys
auth 1
1 sha1 49234s43k345lkj3lk239sljdf23478cxj90s8lwe5rll # 密钥串为自定义,尽量长即可
配置说明:sha1为加密方式,可选的加密方式还有crc及md5,但是官方并不建议使用crc方式。
#
# Authentication file. Must be mode 600
#
#
# Must have exactly one auth directive at the front.
# auth send authentication using this method-id
#
# Then, list the method and key that go with that method-id
#
# Available methods: crc sha1, md5. Crc doesn't need/want a key.
#
# You normally only have one authentication method-id listed in this file
#
# Put more than one to make a smooth transition when changing auth
# methods and/or keys.
#
#
# sha1 is believed to be the "best", md5 next best.
#
# crc adds no security, except from packet corruption.
# Use only on physically secure networks.
[iyunv@heartbeat-master ha.d]# chmod 600 authkeys # authkeys文件的权限必须为600!!
[iyunv@heartbeat-master ha.d]# ll
总用量 40
-rw-------. 1 root root 60 1月 8 01:09 authkeys
-rw-r--r--. 1 root root 10502 1月 8 01:03 ha.cf
-rwxr-xr-x. 1 root root 745 12月 3 2013 harc
-rw-r--r--. 1 root root 99 1月 8 01:13 haresources
drwxr-xr-x. 2 root root 4096 1月 8 00:30 rc.d
-rw-r--r--. 1 root root 692 12月 3 2013 README.config
drwxr-xr-x. 2 root root 4096 1月 8 00:30 resource.d
-rw-r--r--. 1 root root 2082 11月 10 19:00 shellfuncs
1.3 编辑haresources文件
1
2
3
4
5
6
7
[iyunv@heartbeat-master ha.d]# cat >> haresources <<eof
> heartbeat-master IPaddr::172.18.10.200/24/eth0 httpd
> heartbeat-slave IPaddr::172.18.10.201/24/eth0
> eof
[iyunv@heartbeat-master ha.d]# cat haresources
heartbeat-master IPaddr::172.18.10.200/24/eth0 httpd
heartbeat-slave IPaddr::172.18.10.201/24/eth0
配置说明:
a.172.18.10.200为初始绑定在heartbeat-master主机上的vip,同理172.18.10.201为初始绑定
在heartbeat-slave主机上的vip。
b.虽然同时配置了master和slave的vip,但是初始绑定只会绑定属于本机的vip,只有在配置的时间内
接收不到对端服务器的心跳数据才会接管对端主机的vip及所有资源。
c.httpd参数是将httpd服务的启动停止操作委托给heartbeat负责。
1.4 编辑ha.cf文件
1
2
3
4
5
6
7
8
9
10
11
12
13
[iyunv@heartbeat-master ha.d]# cat ha.cf
debugfile /var/log/ha-debug.log
logfile /var/log/ha.log
logfacility local1
keepalive 2
deadtime 30
warntime 10
initdead 90
mcast eth1 225.0.0.100 694 1 0
auto_failback on
node heartbeat-master
node heartbeat-slave
crm no
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com