Linux基于Heartbeat配置httpd高可用服务

Heartbeat是一个基于Linux开源的,被广泛使用的高可用集群系统。我们可以基于Heartbeat构建web高可用服务环境。本文在CentOS 6.5下做了一个简单示例,并对其日志进行了初步分析,供大家参考。

有关Heartbeat的相关知识,可以参考:

Heartbeat 集群组件概述

Heartbeat 安装及配置

一、配置host解析及网络
###主机名配置,与/etc/hosts中的解析两者配置保持一致
[root@orasrv1 ~]# more /etc/sysconfig/network
NETWORKING=yes
HOSTNAME=orasrv1.xlk.com

[root@orasrv1 ~]# more /etc/hosts

127.0.0.1 localhost.localdomain localhost

#public ip
192.168.21.10 orasrv1.xlk.com orasrv1    ###node 1
192.168.21.13 orasrv2.xlk.com orasrv2    ###node 2

#private ip
192.168.144.128 orasrv1-priv.xlk.com orasrv1-priv
192.168.144.129 orasrv2-priv.xlk.com orasrv2-priv

[root@orasrv1 ~]# scp /etc/hosts orasrv2:/etc/hosts

[root@orasrv1 ~]# ifconfig |grep eth -A1
eth0      Link encap:Ethernet  HWaddr 00:0C:29:35:31:E5  #eth0对外提供服务
          inet addr:192.168.21.10  Bcast:192.168.21.255  Mask:255.255.255.0
--
eth1      Link encap:Ethernet  HWaddr 00:0C:29:35:31:EF  #eth1用作心跳网络
          inet addr:192.168.144.128  Bcast:192.168.144.255  Mask:255.255.255.0

二、配置等效性
###节点1
# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.21.13
# ssh orasrv2 date;ssh 192.168.21.13 date;

###节点2
# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ''
# ssh-copy-id -i ./.ssh/id_rsa.pub root@192.168.21.10
# ssh orasrv1 date;ssh 192.168.21.10 date;

三、配置时间同步
此处略。可以参考:配置Linux 11G R2 RAC NTP服务

四、安装httpd
节点1:orasrv1
    # yum install httpd
    # service httpd start  ###启动服务
    # echo "orasrv1.xlk.com" >>/var/www/html/index.html
    ###打开浏览器看看能否正常访问,
    ###如能正常访问,关闭服务,关闭自启动
    # service httpd stop
    # chkconfig httpd off

节点2:orasrv2
    # yum install httpd
    # service httpd start  ###启动服务
    # echo "orasrv2.xlk.com" >>/var/www/html/index.html
    ###打开浏览器看看能否正常访问,
    ###如能正常访问,关闭服务,关闭自启动
    # service httpd stop
    # chkconfig httpd off 

五、配置heartbeat
1、配置认证方式
    [root@orasrv1 ~]# vi /etc/ha.d/authkeys |grep -v ^#
    auth 1
    1 md5 74a6a503b5bec9373b22bb630608df41  ###使用md5验证

[root@orasrv1 ~]# chmod 600 /etc/ha.d/authkeys

2、配置ha.cf 
    [root@orasrv1 ~]# vi /etc/ha.d/ha.cf
    logfile /var/log/ha-log
    keepalive      2
    deadtime        15
    warntime        10
    initdead        60
    udpport        694
    bcast          eth1
    auto_failback  off
    node orasrv1.xlk.com
    node orasrv2.xlk.com
    ping 192.168.21.254
    #respawn hacluster  /usr/lib64/heartbeat/ipfail

3、配置haresources
    [root@orasrv1 ~]# vi /etc/ha.d/haresources
    orasrv1.xlk.com IPaddr::192.168.21.1/24/eth0 httpd

4、同步到第二节点 
    # scp -p /etc/ha.d/{ha.cf,authkeys,haresources} 192.168.21.13:/etc/ha.d/

六、验证测试
1、节点1启动heartbeat
###备注:本样例并未使用到共享文件系统,如配置drbd,或者nfs等。
[root@orasrv1 ~]# service heartbeat start
Starting High-Availability services:
2015/11/06_11:46:51 INFO:  Resource is stopped ###此处提示资源处于停止状态
Done.

###以下为基于节点1上的日志分析
[root@orasrv1 ~]# tail -fn 50 /var/log/ha-log
heartbeat[4373]: 2015/11/06_11:46:51 info: Version 2 support: false
heartbeat[4373]: 2015/11/06_11:46:51 WARN: Logging daemon is disabled --enabling logging daemon is recommended
heartbeat[4373]: 2015/11/06_11:46:51 info: **************************
heartbeat[4373]: 2015/11/06_11:46:51 info: Configuration validated. Starting heartbeat 2.1.4
heartbeat[4374]: 2015/11/06_11:46:51 info: heartbeat: version 2.1.4
heartbeat[4374]: 2015/11/06_11:46:52 info: Heartbeat generation: 1446714158
heartbeat[4374]: 2015/11/06_11:46:52 info: glib: UDP Broadcast heartbeat started on port 694 (694) interface eth0
heartbeat[4374]: 2015/11/06_11:46:52 info: glib: UDP Broadcast heartbeat closed on port 694 interface eth0 - Status: 1
heartbeat[4374]: 2015/11/06_11:46:52 info: glib: ping heartbeat started.
heartbeat[4374]: 2015/11/06_11:46:52 info: G_main_add_TriggerHandler: Added signal manual handler
heartbeat[4374]: 2015/11/06_11:46:52 info: G_main_add_TriggerHandler: Added signal manual handler
heartbeat[4374]: 2015/11/06_11:46:52 info: G_main_add_SignalHandler: Added signal handler for signal 17
heartbeat[4374]: 2015/11/06_11:46:52 info: Local status now set to: 'up'
heartbeat[4374]: 2015/11/06_11:46:52 info: Link 192.168.21.254:192.168.21.254 up.
heartbeat[4374]: 2015/11/06_11:46:52 info: Status update for node 192.168.21.254: status ping
heartbeat[4374]: 2015/11/06_11:46:52 info: Link orasrv1.xlk.com:eth0 up.
heartbeat[4374]: 2015/11/06_11:47:52 WARN: node orasrv2.xlk.com: is dead
###上面的日志可以看出节点1上的heartbeat已经成功启动,此时尚未开始分配资源
###紧接着下面的提示节点2处于死亡状态,其时间间隔为60s(46:52s~47:52s),即我们配置文件中的initdead
###也就是说等待1分钟还没有探测到对方心跳,此时认为节点2死亡,注意,这里的死亡不等同于deadtime

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/c429ca9fcf84912107d643250c57a5a8.html