金融其它双机热备

HA双机热备的实现(heartbeat)

环境:

主节点:node1   node1.test.com      eth0:192.168.0.20  eth1:192.168.1.20

从节点:node2   node2.test.com      eth0:192.168.0.99  eth1:192.168.1.99

测试机:192.168.0.55

一、安装前的准备

++以下是在node1上的操作:

首先修改/etc/hosts文件,保持两个节点改文件相同。如下:

[root@node1 ~]#vim /etc/hosts

# Do not remove the following line, or various programs

# that require network functionality will fail.

127.0.0.1       localhost.localdomain   localhost

::1             localhost6.localdomain6 localhost6

192.168.0.99    node2.test.com  node2   

192.168.0.20    node1.test.com  node1   

192.168.1.99    node2.test.com  node2   

192.168.1.20    node1.test.com  node1

  

拷贝至node2

[root@node1 ~]# scp  /etc/hosts 192.168.0.99:/etc/

安装httpd服务

[root@node1 ~]# yum -y install httpd

[root@node1 ~]# echo "node1 test page" > /var/www/html/index.html

[root@node1 ~]# service httpd start

Starting httpd:                                            [  OK  ]

[root@node1 ~]#

测试是否可用

1.png



关闭httpd服务禁止开机启动

[root@node1 ~]# service httpd stop

Stopping httpd:                                            [  OK  ]

[root@node1 ~]# chkconfig httpd off

[root@node1 ~]#

在node2上按照以上步骤进行操作

安装httpd服务

[root@node2 ~]# yum -y install httpd

[root@node2 ~]# echo "node2 test page" > /var/www/html/index.html

[root@node2 ~]# service httpd start

Starting httpd:                                            [  OK  ]

[root@node2 ~]#

测试是否可用

2.png



关闭httpd服务禁止开机启动

[root@node12~]# service httpd stop

Stopping httpd:                                            [  OK  ]

[root@node2~]# chkconfig httpd off

[root@node2 ~]#

二、安装、配置heartbeat

heartbeat需要安装的软件包如下:                     

heartbeat-pils-2.1.4-10.el5.i386.rpm

heartbeat-stonith-2.1.4-10.el5.i386.rpm

heartbeat-2.1.4-9.el5.i386.rpm            

heartbeat-devel-2.1.4-9.el5.i386.rpm      

heartbeat-gui-2.1.4-9.el5.i386.rpm        

libnet-1.1.4-3.el5.i386.rpm

heartbeat-ldirectord-2.1.4-9.el5.i386.rpm  

perl-MailTools-1.77-1.el5.noarch.rpm

将以上安装包全部安装

1、安装heartbeat

3.png



[root@node1 ~]# yum -y --nogpgcheck localinstall *.rpm

4.png



[root@node2 ~]# yum -y --nogpgcheck localinstall *.rpm

2、拷贝三个文件到/etc/ha.d/

[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.4/authkeys  /etc/ha.d/

[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.4/ha.cf   /etc/ha.d/

[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.4/haresources  /etc/ha.d/

[root@node1 ha.d]# ls

authkeys  ha.cf  harc  haresources  rc.d  README.config  resource.d  shellfuncs

[root@node1 ha.d]#

3、编辑主配置文件

[root@node1 ha.d]# vim  ha.cf           #打开以下各行或保证有如下行

debugfile /var/log/ha-debug           #调试日志(调试时建议打开)

logfile /var/log/ha-log            #heartbeat的日志文件

keepalive 2:               #心跳的时间间隔,默认时间单位为秒

deadtime 30:          #超出该时间间隔未收到对方节点的心跳,则认为对方已经死亡。

warntime 10:       #超出该时间间隔未收到对方节点的心跳,则发出警告并记录到日志中。

initdead 120:  #在某些系统上,系统启动或重启之后需要经过一段时间网络才能正常工作,

           #该选项用于解决这种情况产生的时间间隔。取值至少为deadtime的两倍。

udpport 694   #设置广播通信使用的端口,694为默认使用的端口号。

bcast eth1: #设置广播通信所使用的网络接口卡。(我们这里设置为eth1,专门用来探测心

          #跳)

auto_failback on    #是否允许主节点恢复时,自动将资源从从节点获取。这里on为开启

node    node1   #用于指定主从节点

node    node2

4、编辑 haresources

资源文件,指定主节点,VIP,启动的服务等

格式:node-name network-config

node-name指定双机系统的主节点

network-config用于网络设置,包括指定VIP、子网掩码、广播地址

resource-group 指定使用VIP向外提供的服务,可以为多个

[root@node1 ha.d]# vim haresources

  node1  192.168.0.100    httpd        #在最后一行添加

5、编辑authkeys文件

[root@node1 ha.d]#vim  authkeys  #其中authkeys用于两个节点用来验证的文件,其中有三   

auth 3                           #种算法如下:

#1 crc

#2 sha1 HI!      #三种算法安全性逐渐增强,我们这里选择的md5,Hello为密码,也可以  

3 md5 Hello!     #自己使用生成的md5密码。   

[root@node1 ha.d] chmod 600 authkeys         #一定保证authkeys的权限模型为600

6、将三个文件拷贝到node2

[root@node1 ha.d]# scp  authkeys  haresources  ha.cf  192.168.0.99:/etc/ha.d/

7、记得拷贝httpd脚本到/etc/ha.d/resource.d/,以便更快的查找到。

[root@node1 ha.d]# cp /etc/init.d/httpd  resource.d/

[root@node2 ~]# cp /etc/init.d/httpd  /etc/ha.d/resource.d/

三、实验的测试

1、启动heartbeat (先主节点后从节点)

[root@node1 ~]# service heartbeat start

[root@node2 ~]# service heartbeat start

2、查看服务

[root@node1 ~]# netstat  -tnlp | grep :80

tcp           0      0 :::80           :::*         LISTEN      17058/httpd         

[root@node1 ~]# netstat  -tunlp | grep :694

udp          0       0 0.0.0.0:694     0.0.0.0:*               17200/heartbeat: wr

[root@node1 ~]#

3、查看ip(VIP)这里出现了eth0:0 是我们指定的VIP

[root@node1 ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:75:13:19  

          inet addr:192.168.0.20  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe75:1319/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:38036 errors:0 dropped:0 overruns:0 frame:0

          TX packets:246490 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:3743400 (3.5 MiB)  TX bytes:341326043 (325.5 MiB)

          Interrupt:169 Base address:0x2000

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:75:13:19  

          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:169 Base address:0x2000

eth1      Link encap:Ethernet  HWaddr 00:0C:29:75:13:23  

          inet addr:192.168.1.20  Bcast:192.168.1.255  Mask:255.255.255.0

4、访问测试

5.png



四、模拟宕机(断开node1网卡)

我在断开网卡后2秒查看node2如下:

1、查看ip(VIP)

[root@node2 ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:50:06:DD  

          inet addr:192.168.0.99  Bcast:192.168.0.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fe50:6dd/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          RX packets:278657 errors:0 dropped:0 overruns:0 frame:0

          TX packets:122244 errors:0 dropped:0 overruns:0 carrier:0

          collisions:0 txqueuelen:1000

          RX bytes:346575843 (330.5 MiB)  TX bytes:13084319 (12.4 MiB)

          Interrupt:169 Base address:0x2000

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:50:06:DD  

          inet addr:192.168.0.100  Bcast:192.168.0.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:169 Base address:0x2000

eth1      Link encap:Ethernet  HWaddr 00:0C:29:50:06:E7  

          inet addr:192.168.1.99  Bcast:192.168.1.255  Mask:255.255.255.0

2、查看端口

[root@node2 ~]# netstat  -tnlp | grep :80

tcp        0      0 0.0.0.0:802         0.0.0.0:*      LISTEN      1892/rpc.statd      

tcp        0      0 :::80                :::*          LISTEN      16765/httpd         

[root@node2 ~]# netstat  -tunlp | grep :694

udp         0    0        0.0.0.0:694         0.0.0.0:*      16397/heartbeat: wr

[root@node2 ~]#

3、访问测试

6.png



五、模拟恢复(重新接上node1网线)

等待一段时间后资源又回到了node1上 (略去不写,因为与三中的内容一致)

访问如下:

7.png

参与1

1同行回答

sunrainlzwsunrainlzw工程师dawning infomation industry
hacmp 4 linux?显示全部
hacmp 4 linux?收起
机械装备 · 2010-11-03
浏览1460

提问者

yinxin
系统管理员银信长远
擅长领域: 服务器存储虚拟化

相关问题

问题状态

  • 发布时间:2010-10-21
  • 关注会员:0 人
  • 问题浏览:4600
  • 最近回答:2010-11-03
  • X社区推广