2012年8月22日星期三

在debian squeeze上安装和配置heartbeat、pacemaker和ldirectord实现简单的高可用方案


注意:下面的操作均以root用户身份执行。

1. 安装heartbeat、pacemaker和ldirectord(事实还需要其它软件,但apt会自动处理信赖关系)
apt-get install heartbeat pacemaker ldirectord

heartbeat、pacemaker和ldirectord三者之间的关系图(此处借用文章http://hi.baidu.com/leolance/item/bdc6ecd9f49fc93b48e1dd49中的结构图):

其中,heartbeat为消息交换和基础结构层,pacemaker为资源分配层中的群集资源管理器(CRM),此层还包括本地资源管理器(LRM,包含在cluster-glue软件包中),ldirectord属于资源层,此处资源指代是的linux主机上可用的服务,只要某服务提供符合ocf或lsb标准的控制脚本(即提供了start、stop和status方法的脚本,/etc/init.d下的启停脚本大多符合这一标准)。

下面假设192.168.10.134和192.168.10.136为两个lvs节点,vip为192.168.10.137,两台realserver分别是192.168.11.93和192.168.11.94,realserver上提供http服务。

2. 配置heartbeat
配置ha.cf之前需要知道各节点的名字(在各节点上运行uname -n所得即是),并配置各节点的hosts,使得可用节点的名字解析出相应ip。
例如:在节点192.168.10.134上运行uname -n,得到online10-134,于是在/etc/hosts中添加192.168.10.134 online10-134一行。

注意:ha.cf和authkeys是lvs节点上的配置文件,两个lvs节点上的authkeys必须相同,ha.cf也应相同(可能发心跳的配置有些少不同,其他则相同)。

2.1. ha.cf
cat /etc/ha.d/ha.cf
    # enable pacemaker, without stonith
    crm yes
 
    # log where?
    debugfile /var/logs/heartbeat/ha-debug
    logfile /var/logs/heartbeat/ha-log
    logfacility     local0
 
    # warning of soon be dead
    warntime 10
 
    # declare a host (the other node) dead after:
    deadtime 20
 
    # dead time on boot (could take some time until net is up)
    initdead 120
 
    # time between heartbeats
    keepalive 2
 
    # the nodes
    node online10-134
    node online10-136
 
    # heartbeats, over dedicated replication interface!
    ucast eth0 192.168.10.134
    ucast eth0 192.168.10.136
 
    # ping the switch to assure we are online
    ping 192.168.10.1
    auto_failback on

2.2. authkeys
cat /etc/ha.d/authkeys
    auth 1
    1 sha1 c4920938a12dfa6d9110834c49479b6c

可用下面命令在一个节点中生成随机的密钥,然后复制到各节点。注意:各节点中的authkeys文件必须相同,权限也必须为0600。
( echo -ne "auth 1\n1 sha1 "; \
  dd if=/dev/urandom bs=512 count=1 | openssl md5 ) \
  > /etc/ha.d/authkeys
chmod 0600 /etc/ha.d/authkeys

3. 配置ldirectord

注意:ldirectord.cf是lvs节点上的配置文件,两个lvs节点上的ldirectord.cf内容相同。

cat /etc/ldirectord.cf

    checktimeout=3
    checkinterval=1
    autoreload=yes
    logfile="info"
    emailalert="admin@foo.com"
    emailalertfreq=3600
    emailalertstatus=all
    quiescent=no
    fallback=192.168.10.137:80 gate 3

    virtual=192.168.10.137:80
        real=192.168.11.93:80 gate 3
        real=192.168.11.94:80 gate 3
        service=http
        scheduler=wrr
        persistent=60
        protocol=tcp
        checktype=connect
        checkport=80

4. 使用pacemaker添加资源
pacemaker提供一个交互的shell用于控制资源。以下操作均在crm shell下的configure子项中进行。
添加vip资源:
primitive ip ocf:heartbeat:IPaddr2 \
   op monitor interval="60" timeout="20" \
   params ip="192.168.10.137" lvs_support="true"
添加ldirectord资源:
primitive lvs ocf:heartbeat:ldirectord \
   op monitor interval="20" timeout="10"
将vip和ldirectord绑定一个组:
group ip-lvs ip lvs

没有评论: