Chinaunix首页 | 论坛 | 博客
  • 博客访问: 174290
  • 博文数量: 18
  • 博客积分: 804
  • 博客等级: 军士长
  • 技术积分: 220
  • 用 户 组: 普通用户
  • 注册时间: 2007-02-01 13:30
文章分类

全部博文(18)

文章存档

2015年(1)

2012年(2)

2011年(1)

2010年(2)

2009年(12)

分类: LINUX

2009-04-26 12:09:19

用Heartbeat做LINUX下的双机热备
[本文参照网上的一部分资料,如: http://blog.chinaunix.net/u2/82873/showart_1405630.html的测试环境]
1.测试环境(VM) RHEL5+http+hearbeat
1) server
Name                    ETH0                    ETH1             virtual IP
note1.test.com          192.168.146.131         10.0.0.1         192.168.146.110
note2.test.com          192.168.146.132         10.0.0.2         192.168.146.110
2) client
IP:192.168.146.222
注:更改IP: SHELL# setup
   更改hostname: /etc/sysconfig/network  /etc/hosts---> reboot
2. 安装
1)因为我个人比较懒,所以自己架了一台YUM服务器,通过它来安装一些RPM包,减少了安装过程中包的依赖问题.
  #mount /dev/cdrom /mnt/cdrom
  #cd /mnt/cdrom/Server
  #rpm -ivh vsftp* creatrepo
  #services vsftpd start
  #cp /mnt/cdrom/Server/* /var/ftp/pub
接下来从 下载:
 libnet-1.1.2.1-2.1.i386.rpm
 heartbeat-2.1.4-2.1.i386.rpm
 heartbeat-devel-2.1.4-2.1.i386.rpm
 heartbeat-ldirectord-2.1.4-2.1.i386.rpm
 heartbeat-pils-2.1.4-2.1.i386.rpm
 heartbeat-stonith-2.1.4-2.1.i386.rpm 到/var/ftp/pub/下
中下载ipvsadm到/var/ftp/pub
  #createrepo -v /var/ftp/pub
  更改/etc/yum.repos.d/rhel-debuginfo.repo为
[rhel-debuginfo]
name=Red Hat Enterprise Linux $releasever - $basearch - Debug
baseurl=ftp://192.168.146.131/pub
enabled=1
gpgcheck=0
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release
到此 yum服务器安装成功.
复制/etc/yum.repos.d/rhel-debuginfo.repo到note2.test.com /etc/yum.repos.d/目录下。
2)安装服务:
在note1.test.com;note2.test.com 通过yum install * (*为要安装的RPM包)来安装
libnet、net-snmp、net-snmp-libs、perl-Compress-Zlib、 perl-HTML-Parser、perl-HTML- Tagset、perl-libwww-perl、perl-MailTools、perl-TimeDate、perl-URI、ipvsadm、libnet-1.1.2.1-2.1.i386.rpm、heartbeat-2.1.4-2.1.i386.rpm、heartbeat-devel-2.1.4-2.1.i386.rpm、heartbeat-ldirectord-2.1.4-2.1.i386.rpm、heartbeat-pils-2.1.4-2.1.i386.rpm、heartbeat-stonith-2.1.4-2.1.i386.rpm
 
3.相关配置,和王工的测试步骤相一致,没有太多的变化。
现在在note1上进行配置的操作。由于安装完成后,在/etc/ha.d/目录下默认没有ldirectord.cf等配置文件,我们先从安装目录下拷贝:

#cp /usr/share/doc/heartbeat-ldirectord-2.1.4/ldirectord.cf   /etc/ha.d/
#cp /usr/share/doc/packages/heartbeat/ha.cf  /etc/ha.d/
#cp /usr/share/doc/packages/heartbeat/authkeys  /etc/ha.d/
#cp /usr/share/doc/packages/heartbeat/haresources /etc/ha.d/


下来编辑ldirectord.cf、authkeys、ha.cf、haresources四个文件。
我的配置如下所示:
ldirecord.cf
      checktimeout=3   #检测超时3s
      checkinterval=1  #检查时间间隔1s
      autoreload=yes   #配置文件改变时自动加载配置文件
      logfile="/var/log/ldirectord.log"  #定义日志文件
      quiescent=yes   
      virtual=192.168.146.110     #虚拟IP
          real=192.168.146.131:80 gate  #realserver node1.hrwang.com
          real=192.168.146.132:80 gate  #realserver cluster.hrwang.com
          fallback=127.0.0.1:80      #所有服务器发生故障时访问该服务器
          service=http               #服务名称
          scheduler=rr               #我这里使用的直连路由调度算法
          protocol=fwm     
          checktype=negotiate


注: protocol使用tcp时,总报错:Error [5413] reading file /etc/ha.d/ldirectord.cf at line 32: protocol must be fwm if the virtual service is a fwmark (a number),改为fwm就没问题了。

ha.cf文件:
       debugfile /var/log/ha-debug #定义日志文件,其实这个文件的内容与ldirectord.cf文件中定义的/var/log/ldirectord.log文件内容相同。
       logfile /var/log/ha-log     #同上
       logfacility     local0      #默认
       keepalive 2                 #设定heartbeat之间的时间间隔为2秒.
       deadtime 30                 #在30秒后宣布节点死亡。
       warntime 10                 #在日志中发出“late heartbeat“警告之前等待的时间,单位为秒。
       initdead 120      #在某些配置下,重启后网络需要一些时间才能正常工作。这个单独的”deadtime”选项可以处理这种情况。它的取值至少应该为通常deadtime的两倍。
       udpport 694  # 使用端口694进行bcast和ucast通信。这是默认的,并且在IANA官方注册的端口号。
       bcast   eth1            # Linux 表示在eth1接口上使用广播heartbeat(将eth1替换为eth0,eth2),或者您使用的任何接口。
       mcast eth0 225.0.0.1 694 1 0    #默认即可
       ucast eth0 192.168.146.131      #改为你eth0的地址。
       auto_failback on             #该选项是必须配置的。值为on or off
       node    note1.test.com    #负载均衡服务器名,必须与uname -n的输出一致。
       node    note2.test.com    #同上
       ping 10.0.0.254
       respawn hacluster /usr/lib/heartbeat/ipfail
       apiauth ipfail gid=haclient uid=hacluster

注:
auto_failback on            # 当主节点恢复后,是否自动切回
watchdog /dev/watchdog      #watchdog能让系统在出现故障1分钟后重启该机器。这个功能可以帮助服务器在确实停止心跳后能够重新恢复心跳。如果使用该特性,则在内核中装入"softdog"内核模块,用来生成实际的设备文件,输入"insmod softdog"加载模块。输入"grep misc /proc/devices"(应为10),输入"cat /proc/misc | grep watchdog"(应为130)。生成设备文件:"mknod /dev/watchdog c 10 130" 。

haresources文件:
note1.test.com  192.168.146.110
 
注:按王工的配置,这一项目本来是过不去的,会报IPaddr错误。在这个配置文档中,node 节点名字以note1.test.com 上 uname -n 来安义。

authkeys文件,这里我使用的是md5方式,注意,该文件的权限必须是600:
       auth 3
            3 md5 test


然后编辑/etc/sysctl.conf文件,加入以下行:
   net.ipv4.ip_forward = 1
   net.ipv4.conf.all.arp_ignore = 1
   net.ipv4.conf.eth0.arp_ignore = 1
   net.ipv4.conf.all.arp_announce = 2
   net.ipv4.conf.eth0.arp_announce = 2
再执行sysctl -p命令,使其立即生效!

以上是note1的配置。切记,cluster上的/etc/ha.d/目录下的authkeys、haresources、ha.cf、ldirecotord.cf四个文件必须和note1上的相同。
我们把note1上的文件拷贝到note2 /etc/ha.d/有目录下。
在note2上同样:编辑/etc/sysctl.conf文件,加入以下行:
   net.ipv4.ip_forward = 1
   net.ipv4.conf.all.arp_ignore = 1
   net.ipv4.conf.eth0.arp_ignore = 1
   net.ipv4.conf.all.arp_announce = 2
   net.ipv4.conf.eth0.arp_announce = 2
再执行sysctl -p命令,使其立即生效!
4.开启相关服务(note1,note2)
#chkconfig vsftpd on (note1)
#chkconfig httpd on  (note1,note2)
#services httpd start (note1,note2)
注:在httpd 启动过程中可能会碰到:ServerName不正确的提示,这时你可以进入编辑httpd.conf 把ServerName的注释去掉,换成 ServerName note1.test.com:80
(note1);ServerName note2.test.com:80(note2)
 
5.测试:
 1) 在note1上:echo "This is server1" >/var/www/html/index.html
    note2 :  echo "This is server2" >/var/www/html/index.html
 2)测试:(在192.168.146.222 上)
        结果:This is server1
        结果:This is server2
        结果:无
 3)开启heartbeat服务:
   note1:  services heartbeat start
   note2:  services heartbeat start
  注:用ifconfig查看,note1上会开启一个eth0:0的虚拟网卡接口。如果开启不了,过一会再试。
 4)测试:
        结果:This is server1
   关闭note1再测试
        结果:This is server2
如上结果,则测试成功。
 
 
问题点:
1.ha.cf中:
bcast 网卡地址为heartbeat所用地址。
gid=haclient,uid=hacluster,经测试,存在.若为源码包,可能要从新添加。
2.haresources中不必用IPaddr,可以用hostname IP 来进行认证。

 

阅读(2135) | 评论(0) | 转发(0) |
0

上一篇:没有了

下一篇:如何通过Kickstart安装RHEL5(网络安装一)

给主人留下些什么吧!~~