CentOS 5.5 高可用群集配置

    Linux 包括 CentOS 下高可用(HA:High Availability)集群方案很多,而 Heartbeat 是比较常见和性价比比较高的一种。

    一、硬件及网络连接

    群集一般需要2台以上服务器,本篇以两台服务器做群集(双机热备)为例来说明。本实验在 Vmware Workstation 7.1 虚拟机中实现。

    两台服务器的必需配置:双网卡。其中一块网卡作为“心跳”使用。作为“心跳”的两块网卡用交叉线直接连接,作为群集的信号同步使用。多台服务器的群集,建议用全千兆交换机来连接“心跳”线。作为“心跳”的网卡最好是质量好的千兆网卡。实际工程中见过因为网卡质量问题导致群集失败的案例。

    群集使用的两台服务器并不需要有完全相同的硬件(或者内存大小等),但如果相同的话,当某个部件出现故障时会容易处理得多。集群是通过 Heartbeat 软件产生在两台电脑之间“心跳”信号来建立的。为了传输“心跳”信号,需要在节点之间存在一条或多条介质通路,例如串口线(通过 Modem 连接)、以太网通过交叉线等,本例选用常见的以太网连接。

    二、CentOS 配置

    1,关闭 SELINUX

    编辑 /etc/sysconfig/selinux 文件,配置以下语句:
    SELINUX=disabled

    也可以在图形界面里修改。
    实际生产环境不应该关闭 SELINUX,但必须注意 SELINUX 对群集的影响。

    2,关闭 iptables 防火墙

    执行命令:
    chkconfig iptables off
    chkconfig ip6tables off

    也可以在图形界面里修改。
    实际生产环境不应该关闭防火墙,但必须注意打开群集有关的协议和端口。

    3,IP 地址配置

    服务器一:
    网卡0(eth0):
      IP 为 10.0.0.50/24
    网卡1(eth1):
      IP 为 172.16.0.50/24

    服务器二:
    网卡0(eth0):
      IP 为 10.0.0.51/24
    网卡1(eth1):
      IP 为 172.16.0.51/24

    配置完毕,可以输入如下命令检查 IP 配置:
    # ifconfig

    可以用 ping 命令检测网络的连通性。例如,在服务器一中:
    # ping 10.0.0.51
    # ping 172.16.0.51
    均应该连通。

    4,分别修改主机名为 node1、node2

    服务器一修改 /etc/sysconfig/network 文件中 HOSTNAME 语句为:
    HOSTNAME=node1
    服务器二修改 /etc/sysconfig/network 文件中 HOSTNAME 语句为:
    HOSTNAME=node2
    也可以在 GUI 的“网络”配置里修改。

    修改完毕,运行命令
    # uname -n
    看到的结果应该与上面的修改一致。

    5,修改 hosts 文件

    在两台服务器的 /etc/hosts 文件里,添加以下语句:
    10.0.0.50   node1
    10.0.0.51   node2

    6,安装 HeartBeat 软件

    在两台服务器里,运行命令:
    # yum install heartbeat*

    YUM 会安装 heartbeat 及其所有依赖的软件包。并创建隐藏的系统帐户 hacluster 和系统群组 haclient。

    查看安装了什么软件包:
    运行命令:
    # yum list heartbeat*
    Installed Packages
    heartbeat.i386               2.1.3-3.el5.centos     installed
    heartbeat-devel.i386         2.1.3-3.el5.centos     installed
    heartbeat-gui.i386           2.1.3-3.el5.centos     installed
    heartbeat-ldirectord.i386    2.1.3-3.el5.centos     installed
    heartbeat-pils.i386          2.1.3-3.el5.centos     installed
    heartbeat-stonith.i386       2.1.3-3.el5.centos     installed

    7,配置 Apache

    Apache 是作为群集的测试服务来对外提供 Web 服务的。注意 Apache 是以 HeartBeat 群集虚拟的 IP 地址来访问的。群集创建完成后,将以该虚拟 IP 作为外部访问的地址,所以该 IP 必须是外网可访问地址。

    们指定该 IP 为 10.0.0.60,所以可以在两台服务器的 Apache 里配置以 IP 地址 10.0.0.60 访问的虚拟主机。

    <VirtualHost *:80>
      ServerAdmin webmaster@example.com
      DocumentRoot /var/www/html
      ServerName 10.0.0.60
      #or: ServerName www.somedomain.com
      ErrorLog logs/example.com-error_log
      CustomLog logs/example.com-access_log common
      <Directory "/var/www/html">
        Options Indexes MultiViews
        AllowOverride None
        Order allow,deny
        Allow from all
      </Directory>
    </VirtualHost>

    为简单起见,可以将 Apache2.0 配置文件 httpd.conf 中的
    Listen 80
    语句改为
    Listen 10.0.0.60:80
    即可。

    然后在服务器一(node1)的 Apache 根文件夹 /var/www/html/ 下建立主页文件 index.html,文件内容为:
    This is node1。
    在服务器二(node2)的 Apache 根文件夹 /var/www/html/ 下建立主页文件 index.html,文件内容为:
    This is node2。

    实际使用中,node1 和 node2 的 Apache 网站文档需要同步,或直接指向同一个高可靠性的存储位置(例如 RAID 5+1 磁盘阵列)即可。

    8,无关的服务,尽量关闭,例如:
    # chkconfig acpid off
    # chkconfig anacron off
    # chkconfig apmd off
    # chkconfig auditd off
    # chkconfig autofs off
    # chkconfig bluetooth off
    # chkconfig cpuspeed off
    # chkconfig cups off
    # chkconfig gpm off
    # chkconfig haldaemon off
    # chkconfig iptables off
    # chkconfig isdn off
    # chkconfig kudzu off
    # chkconfig mDNSResponder off
    # chkconfig mdmonitor off
    # chkconfig messagebus off
    # chkconfig netfs off
    # chkconfig nfslock off
    # chkconfig nifd off
    # chkconfig pcmcia off
    # chkconfig portmap off
    # chkconfig rhnsd off
    # chkconfig rpcgssd off
    # chkconfig rpcidmapd off
    # chkconfig sendmail off
    # chkconfig xfs off

相关推荐