`
ithero
  • 浏览: 143591 次
社区版块
存档分类
最新评论

linux集群

阅读更多

集群系统主要就2种:

系统:Centos5.0

集群软件:Heartbeat

节点1IP(主):192.168.1.105

节点2IP(从):192.168.1.106

virtual IP:192.168.1.102

  在节点1上使用uname -n 结果必须是node01,在节点2上同样使用uname -n结果也必须是node02。IP 192.168.1.102是一个虚拟IP用来供webserver使用的。

高可用(High Availability)HA集群, 使用Heartbeat实现;也会称为”双机热备”, “双机互备”, “双机”。
负载均衡群集(Load Balance Cluster),使用Linux Virtual Server(LVS)实现;

这里只讨论HA,使用Heartbeat实现.集群
heartbeat的工作原理:heartbeat最核心的包括两个部分,心跳监测部分和资源接管部分,心跳监测可以通过网络链路和串口进行,而且支持冗余链路,它们之间相互发送报文来告诉对方自己当前的状态,如果在指定的时间内未受到对方发送的报文,那么就认为对方失效,这时需启动资源接管模块来接管运行在对方主机上的资源或者服务。

下载libnet  Http://www.packetfactory.net/libnet/ (heartbeat需要)
下载Heartbeat Http://www.linux-ha.org/download/
groupadd haclient
useradd  hacluster -g haclient
安装都是./configure [--prefix=$dstpath] && make && make install
从源安装目录doc目录下找到ha.cf/haresources/authkeys三个文件,复制到程序目录相关路径
 cp doc/{ha.cf,haresources,authkeys} ../etc/ha.d/
 1.编辑两台机器的/etc/hosts文件,加入HA01,HA02相关IP说明

 2.vi /etc/hc.d/authkeys
  auth 1  #或其它
  1 crc 
 #chmod 600 authkeys

 3.vi haresources
 HA01    1.1.1.1 http  #1.1.1.1为用户需要访问的实际IP

 4.vi ha.cf
 keepalive 2
 deadtime 30
 initdead 120
 logfacility     local0
 auto_failback on
 udpport           694
 bcast     eth1
 node HA01
 node HA02

 #../lib/heartbeat/ResourceManager listkeys `/bin/uname -n`

 我将HA01停机,HA02已正常发现并切换服务. 同理HA02停机,HA01也可以发现并接管服务.
 heartbeat[3078]: 2007/09/20_14:28:25 WARN: node ha02: is dead
 heartbeat[3078]: 2007/09/20_14:28:25 info: Comm_now_up(): updating status to active
 heartbeat[3078]: 2007/09/20_14:28:25 info: Local status now set to: ‘active’

 

二、下载安装软件包和配置:

   1、需要以下软件包:

heartbeat-2.1.2

heartbeat-2.1.2

heartbeat-stonith-2.1.2

也可以使用yum -y install heartbeat来进行安装,附件为所需要的软件包:

2、在每个节点上配置heartbeat,需要有以下三个文件:

authkeys、ha.cf、haresources,它们存在于/etc/ha.d/目录里。

3、创建以上提到的三个文件:

cp /usr/share/doc/heartbeat-2.1.2/authkeys  /etc/ha.d/

cp /usr/share/doc/heartbeat-2.1.2/ha.cf  /etc/ha.d/

cp /usr/share/doc/heartbeat-2.1.2/haresources  /etc/ha.d/

4、配置:

  4.1、首先编辑authkeys文件:

   vi /etc/ha.d/authkeys

   添加以下行:在这里我们使用的是第二种认证方式(shal)

   auth 2

   2 sha1 test-ha

   接着把文件的权限改为600:

   chmod 600 /etc/ha.d/authkeys

  4.2、编辑/etc/ha.d/ha.cf文件:

   vi /etc/ha.d/ha.cf加入如下行:

   logfile /var/log/ha-log

   logfacility local0

   keepalive 2

   deadtime 30

   initdead 120

   bcast eth0

   udpport 694

   auto_failback on

   node node01

   node node02

  4.3、编辑/etc/ha.d/haresources文件:

   这个文件中包含了使那个服务具有高可用性,在这里我们使用的是httpd;

   vi /etc/ha.d/haresources加入下行:

   node01 172.16.4.82 httpd

  4.4、我们把node01上的/etc/ha.d/目录复制到节点node02上的/etc目录里。

   scp -r /etc/ha.d/ root@node02:/etc/

  4.5、在httpd.conf文件里我们添加如下行:

   vi /etc/httpd/conf/httpd.conf

   Listen 192.168.1.102:80

  4.6、把节点node01上的/etc/httpd/conf/httpd.conf文件复制到节点node02相应的目录里:

   scp /etc/httpd/conf/httpd.conf root@node02:/etc/httpd/conf/

  4.7、在两个节点上分别创建一个index文件来进行测试:

   在node01上:

   echo "node01 apache test server" > /var/www/html/index.html

   在node02上:

   echo "node02 apache test server" > /var/www/html/index.html

  4.8、在两个节点上分别启动heartbeat:

    /etc/init.d/heartbeat start

  4.9、在node01上,开启一个浏览器:输入http://192.168.1.102并回车,将会看到

    node01 apache test server

  4.10、停止node01上的heartbeat进程,然后再浏览器里输入http://192.168.1.102并回车,将会看到node02 apache test server.

三、补充:

  这里不需要创建一个虚拟网络接口和配置一个IP(192.168.1.102)给它,因为heartbeat会帮助我们来完成的,并启动httpd server。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics