使用Heartbeat在Linux搭建高可用(High-Availability)的集群服务

本文的最后更新时间: 2005年10月19日 23:12

在互连网高速发展的今天,尤其是电子商务的发展,要求服务器要能够提供不间断服务。在电子商务中,如果服务器宕机,造成的损失是不可估量的。要保证服务器不间断服务,就需要对服务器实现冗余。在众多的实现服务器容易的解决方案中,heartbeat为我们提供了廉价的、可伸缩的高可用集群方案。下面我们将通过heartbeat在Linux下创建一个高可用的web服务器集群服务器。 本文中的系统环境为:RedHat Linux9.0

  1. 目的和环境
  2. 准备环境
  3. 安装heartbeat
  4. tar -zxvf heartbeat-2.0.2.tar.gz

    cd heartbeat-2.0.2

    ./ConfigureMe configure

    make

    make install

  5. 配置heartbeat
  6. heartbeat的主配置文件为:/etc/ha.d/ha.cf。我们需要配置该文件,针对我们前面的规划,/etc/ha.d/ha.cf文件的主要内容如下:

    logfile /var/log/ha-log #指名heartbeat的日志存放位置。

    crm yes #支持ClusterResourceManager(集群资源管理)功能。

    bcast eth1 #指明心跳方式使用以太广播方式,并且是在eth1接口上进行广播。

    keepalive 2 #指明心跳时间为2秒(即每两秒钟在eth1上发送一次广播)。

    warntime 10 #指明心跳延迟的时间为十秒。当10秒钟内备份机不能联系上主机(当前活动的服务器,即无心跳信号),就会往日志中写入一个警告日志,但此时不会切换服务。

    deadtime 30 #指定在30秒内没有心跳信号,则立即切换服务。

    initdead 120 #With some configurations, the network takes some time to start working after a reboot. This is a separate "deadtime" to handle that case. It should be at least twice the normal deadtime.

    udpport 694 #Use port number 694 for bcast or ucast communication. This is the default, and the official IANA registered port number.

    auto_failback on #

    node node1.clusting.com #Mandatory. Hostname of machine in cluster as described by uname -n.

    node node2.clusting.com #

    respawn hacluster /usr/lib/heartbeat/ccm

    respawn hacluster /usr/lib/heartbeat/ipfail

    ping ping1.clusting.com ping2.clusting.com #Specify ping nodes. These nodes are not considered as cluster nodes. They are used to check network connectivity for modules like ipfail.

  7. 配置HA资源
  8. 当切换资源时应该切换哪些资源,例如IP、磁盘……等。在heartbeat中,通过/etc/ha.d/haresources文件来配置共享的资源,在我们的案例中,/etc/ha.d/haresources文件的主要内容如下:

    node1.clusting.com 192.168.100.10/28/192.168.100.15 Filesystem::/dev/sdb1::/ha::ext3 httpd
    #设置node1.clusting.com为主节点,集群服务器的ip地址为192.168.100.10,netmask 为255.255.255.240,broadcast为192.168.100.15,集群的服务有httpd,还有共享磁盘/dev/sdb1。

    该文件只有一行,其含义就是,当主节点node1.clusting.com宕机时,自动启用备用节点node2.clusting.com来提供服务,在却换到node2.clusting.com上时,自动启动httpd和smb服务,同时,将/dev/sdb1挂接到/ha。

  9. 配置Authkeys
  10. /etc/ha.d/authkeys文件的内容如下:
    auth 1
    1 sha1 key-for-sha1-any-text-you-want

    更改文件的权限:
    chmod 600 /etc/ha.d/authkeys

     

  11. 使用同样的方法配置节点2
  12. 在节点2(node2.clusting.com)上执行步骤3-6(当然同样必须先安装heartbeat所需要的软件),节点2 上的heartbeat和apache的配置与节点1要完全相同。

     

  13. 测试

Copyright© 2005 Clusting.com All Rights Reserved

联系: