Chinaunix首页 | 论坛 | 博客
  • 博客访问: 44479425
  • 博文数量: 384
  • 博客积分: 9990
  • 博客等级: 中将
  • 技术积分: 5644
  • 用 户 组: 普通用户
  • 注册时间: 2008-06-05 17:44
文章分类

全部博文(384)

文章存档

2011年(1)

2008年(383)

分类: 服务器与存储

2008-06-05 18:22:07

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

  1. 目的和环境
    • 硬件条件和环境

      两台计算机(两个节点),一个共享SCSI硬盘盒(用于存储共享)。每个节点都安装支持共享总线的SCSI卡;每个节点有自己的系统磁盘;每个分别带有两块以太网卡,(其中一块用于网络通讯,另一块用于心跳功能。)。两个节点的网络设置如下:

      节点1: 主机名为:node1.clusting.com,第一块网卡(eth0)的IP地址:192.168.100.7 (用于网络通讯) 。第二块网卡(eth1)的IP地址:10.0.0.1 (用于心跳通讯) 。

      节点2: 主机名为:node2.clusting.com,第一块网卡(eth0)的IP地址:192.168.100.8 (用于网络通讯) 。第二块网卡(eth1)的IP地址:10.0.0.2 (用于心跳通讯) 。

      其网络拓扑如下图所示:

    • 目的

      用上面的硬件搭建一台高可用的web服务器,服务器的IP地址为192.168.100.10,netmask 为255.255.255.240,broadcast为192.168.100.15。 web服务器的页面数据存储到共享盘的第一个分区(sdb1)上。

  2. 准备环境
    • 对共享磁盘进行分区

      先关闭节点2(node2.clusting.com)主机的电源,打开节点1(node1.clusting.com)主机的电源,在节点一上安装系统,并对共享磁盘分区。

    • 下载软件

      首先下载heartbeat软件:到 下载最新的heartbeat软件。本文写作时下载的软件是:

    • 下载和安装其它所需的软件

      安装heartbeat除必要的编译器之外,需要下面两个软件的开发包支持:e2fsprogs和libnet。

      e2fsprogs可以从系统的安装光盘使用rpm来安装: rpm -ivh /mnt/cdrom/RedHat/RPMS/e2fsprogs-devel-1.32-6.i386.rpm

      libnet只能下载源代码进行安装。下载地址:。我下载的稳定版本是:

      接下来就是安装libnet:
      tar -zxvf libnet.tar.gz
      cd libnet
      ./configure
      make
      make install

  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. 测试
  • 在主节点(node1.clusting.com)上启动heartbeat服务:/etc/init.d/heartbeat start。 如果不出现错误,web服务应该被heartbeat启动,同时heartbeat为主节点设置IP地址192.168.100.10。使用ifconfig eth0:0可以看到如下信息:

    eth0:0 Link encap:Ethernet HWaddr 00:0C:29:D8:FD:EB
    inet addr:192.168.100.10 Bcast:192.168.100.15 Mask:255.255.255.240
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    RX packets:14970 errors:0 dropped:0 overruns:0 frame:0
    TX packets:14977 errors:0 dropped:0 overruns:0 carrier:0
    collisions:0 txqueuelen:100
    RX bytes:3624073 (3.4 Mb) TX bytes:3626223 (3.4 Mb)
    Interrupt:19 Base address:0x10a0

    同时/dev/sdb1,应该被挂接。使用df -h,可以看到的信息包含下面的行:

    /dev/sdb1 485M 8.1M 452M 2% /ha

  • 在node2(node2.clusting.com)上启动heartbeat:/etc/init.d/heartbeat start。 使用ifconfig eth0:0可以看到如下信息:

    eth0:0 Link encap:Ethernet HWaddr 00:0C:29:E4:1E:F7
    UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
    Interrupt:19 Base address:0x10a0

    表明现在node2节点没有被启用。

    使用df -h,看到的信息不包含下面的行:

    /dev/sdb1 485M 8.1M 452M 2% /ha

    表明/dev/sdb1没有被加载。

  • 直接关闭节点1的电源(模拟故障)。 30秒后,在节点2(node2.clusting.com) 上执行ifconfig eth0:0,可以看到eth0:0已经被设置为192.168.100.10
阅读(2201) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2008-09-17 16:50:37

./ConfigureMe configure执行时 报此错 加参数也不行,请指教啊。。。 [root@cluster_1 heartbeat-2.0.2]# ./ConfigureMe config Configure flags for RedHat Linux: --prefix=/usr --sysconfdir=/etc --localstatedir=/var --libexecdir=/usr/lib64 --libdir=/usr/lib64 Usage: ./ConfigureMe [configure|make|install|dist|distcheck|package|flags|bootstrap] ./ConfigureMe configures the system with options that match common conventions associated with this machine (i.e. RedHat Linux) It will also build, make, install or c