linux下Heartbeat做双机热备(1)

本节将介绍linux群集的双机备份详细的配置步骤,这个有点类似windows 2003系统中NLB服务,即用两台相同的服务器对外提供服务,从而实现负载均衡,在这里使用的是虚拟IP来对外提供服务,即使宕了一台服务器,其他的服务器还是能够正常的使用虚拟IP对外提供服务的,所以可用性比较高点!

本例中,需要两张网卡,eth1用来检测心跳算法,也就是专门用来检测其他服务器是否存活用的,eth0可以用来连接外网,但真正不使用这个网卡的IP对外提供服务,尽管数据包经过了这个网卡。(下面来简单介绍下node1的配置步骤,node2基本雷同)

[root@node1 ~]# ifconfig

eth0      Link encap:Ethernet  HWaddr 00:0C:29:FE:19:84  

          inet addr:192.168.254.238  Bcast:192.168.254.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fefe:1984/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:1587876 (1.5 MiB)  TX bytes:291219 (284.3 KiB)

          Interrupt:59 Base address:0x2000 

eth1      Link encap:Ethernet  HWaddr 00:0C:29:FE:19:7A  

          inet addr:192.168.211.128  Bcast:192.168.211.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fefe:197a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:1623625 (1.5 MiB)  TX bytes:1621602 (1.5 MiB)

          Interrupt:67 Base address:0x2080 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

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

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

          collisions:0 txqueuelen:0 

          RX bytes:161262 (157.4 KiB)  TX bytes:161262 (157.4 KiB)

[root@node1 ~]# yum search heartbeat (通过yum服务搜索和安装heartbeat服务)

============================== Matched: heartbeat ==============================
heartbeat.i386 : heartbeat - The Heartbeat Subsystem for High-Availability Linux
heartbeat-devel.i386 : heartbeat development package
heartbeat-gui.i386 : Provides a gui interface to manage heartbeat clusters
heartbeat-ldirectord.i386 : Monitor daemon for maintaining high availability
                          : resources with ipvs (Linux Virtual Server}
heartbeat-pils.i386 : Provides a general plugin and interface loading library
heartbeat-stonith.i386 : Provides an interface to Shoot The Other Node In The
                       : Head
piranha.i386 : Cluster administation tools

[root@node1 ~]# yum -y install heartbeat
Setting up Install Process
Parsing package install arguments
Resolving Dependencies
--> Running transaction check
---> Package heartbeat.i386 0:2.1.3-3.el5.centos set to be updated
--> Processing Dependency: heartbeat-stonith = 2.1.3-3.el5.centos for package: heartbeat
--> Processing Dependency: heartbeat-pils = 2.1.3-3.el5.centos for package: heartbeat
--> Processing Dependency: libstonith.so.1 for package: heartbeat
--> Processing Dependency: PyXML for package: heartbeat
--> Processing Dependency: libpils.so.1 for package: heartbeat
--> Running transaction check
---> Package PyXML.i386 0:0.8.4-4 set to be updated
---> Package heartbeat-stonith.i386 0:2.1.3-3.el5.centos set to be updated
---> Package heartbeat-pils.i386 0:2.1.3-3.el5.centos set to be updated
--> Finished Dependency Resolution

Dependencies Resolved

=============================================================================================================================
Package                            Arch                  Version                              Repository               Size
=============================================================================================================================
Installing:
heartbeat                          i386                  2.1.3-3.el5.centos                   extras                  1.7 M
Installing for dependencies:
PyXML                              i386                  0.8.4-4                              base                    1.1 M
heartbeat-pils                     i386                  2.1.3-3.el5.centos                   extras                  213 k
heartbeat-stonith                  i386                  2.1.3-3.el5.centos                   extras                  311 k

Transaction Summary
=============================================================================================================================
Install      4 Package(s)
Update       0 Package(s)
Remove       0 Package(s)

Total download size: 3.3 M
Downloading Packages:
(1/4): heartbeat-pils-2.1.3-3.el5.centos.i386.rpm                                                     | 213 kB     00:01
(2/4): heartbeat-stonith-2.1.3-3.el5.centos.i386.rpm                                                  | 311 kB     00:01
(3/4): PyXML-0.8.4-4.i386.rpm                                                                         | 1.1 MB     00:06
(4/4): heartbeat-2.1.3-3.el5.centos.i386.rpm                                                          | 1.7 MB     00:09
-----------------------------------------------------------------------------------------------------------------------------
Total                                                                                        173 kB/s | 3.3 MB     00:19
Running rpm_check_debug
Running Transaction Test
Finished Transaction Test
Transaction Test Succeeded
Running Transaction
Installing     : heartbeat-pils                                    [1/4]
Installing     : heartbeat-stonith                                 [2/4]
Installing     : PyXML                                             [3/4]
Installing     : heartbeat                                         [4/4]
Complete!

[root@node1 ~]# rpm -ql heartbeat |grep /usr/share/doc (查找并配置相关配置文件如下)
/usr/share/doc/heartbeat-2.1.3
/usr/share/doc/heartbeat-2.1.3/AUTHORS
/usr/share/doc/heartbeat-2.1.3/COPYING
/usr/share/doc/heartbeat-2.1.3/COPYING.LGPL
/usr/share/doc/heartbeat-2.1.3/ChangeLog
/usr/share/doc/heartbeat-2.1.3/DirectoryMap.txt
/usr/share/doc/heartbeat-2.1.3/GettingStarted.html
/usr/share/doc/heartbeat-2.1.3/GettingStarted.txt
/usr/share/doc/heartbeat-2.1.3/HardwareGuide.html
/usr/share/doc/heartbeat-2.1.3/HardwareGuide.txt
/usr/share/doc/heartbeat-2.1.3/README
/usr/share/doc/heartbeat-2.1.3/Requirements.html
/usr/share/doc/heartbeat-2.1.3/Requirements.txt
/usr/share/doc/heartbeat-2.1.3/apphbd.cf
/usr/share/doc/heartbeat-2.1.3/authkeys
/usr/share/doc/heartbeat-2.1.3/faqntips.html
/usr/share/doc/heartbeat-2.1.3/faqntips.txt
/usr/share/doc/heartbeat-2.1.3/ha.cf
/usr/share/doc/heartbeat-2.1.3/haresources
/usr/share/doc/heartbeat-2.1.3/hb_report.html
/usr/share/doc/heartbeat-2.1.3/hb_report.txt
/usr/share/doc/heartbeat-2.1.3/heartbeat_api.html
/usr/share/doc/heartbeat-2.1.3/heartbeat_api.txt
/usr/share/doc/heartbeat-2.1.3/logd.cf
/usr/share/doc/heartbeat-2.1.3/rsync.html
/usr/share/doc/heartbeat-2.1.3/rsync.txt
/usr/share/doc/heartbeat-2.1.3/startstop
[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.3/ha.cf /etc/ha.d/
[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.3/authkeys /etc/ha.d/
[root@node1 ~]# cp /usr/share/doc/heartbeat-2.1.3/haresources /etc/ha.d/
[root@node1 ~]# ls /etc/ha.d/
authkeys ha.cf harc haresources rc.d README.config resource.d shellfuncs

[root@node1 ~]# grep -v '^#' /etc/ha.d/ha.cf
 logfile /var/log/ha-log                定义日志文件位置
logfacility     local0
keepalive 2                            定义心跳检测时间为2s
deadtime 30                            死亡时间为30s
warntime 10    
 initdead 120
udpport 694                            使用UDP端口694
bcast   eth1           # Linux        使用网卡2进行心跳检测
ucast eth1 192.168.211.131                检测node2的IP地址(在此位置,node2需要相应的修改)
auto_failback on
node    node1                           node1的uname名字
node    node2                           node2的uname名字
ping 192.168.254.1                     设置ping个外部IP


[root@node1 ~]# grep -v '^#' /etc/ha.d/authkeys
auth 1
1 crc

[root@node1 ~]# grep -v '^#' /etc/ha.d/haresources
node1    192.168.254.88 httpd            设置虚拟ip为192.168.254.88,监听httpd服务(node2进行相应的设置)


[root@node1 ~]# cat /etc/hosts          添加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.211.128    node1
192.168.211.131    node2


[root@node1 /]# service httpd status     查看下apache服务没有开启
httpd is stopped


[root@node1 ~]# service heartbeat start    启动heartbeat服务
Starting High-Availability services:
2009/04/24_07:35:15 INFO: Resource is stopped
                                                           [FAILED]
heartbeat: udpport setting must precede media statementsheartbeat[3908]: 2009/04/24_07:35:16 ERROR: Bad permissions on

keyfile [/etc/ha.d/authkeys], 600 recommended.
heartbeat[3908]: 2009/04/24_07:35:16 ERROR: Authentication configuration error.
heartbeat[3908]: 2009/04/24_07:35:16 ERROR: Configuration error, heartbeat not started.

[root@node1 ~]# chmod 600 /etc/ha.d/authkeys    此处需要修改下authkeys文件的权限为600

[root@node1 ~]# service heartbeat start
logd is already running
Starting High-Availability services:
2009/04/24_07:35:45 INFO: Resource is stopped
                                                           [ OK ]
[root@node1 ~]# netstat -nupl |grep 694
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               4048/heartbeat: wri
udp        0      0 0.0.0.0:694                 0.0.0.0:*                               4046/heartbeat: wri

[root@node1 ~]# ifconfig          查看下确实多了个虚拟IP

eth0      Link encap:Ethernet  HWaddr 00:0C:29:FE:19:84  

          inet addr:192.168.254.238  Bcast:192.168.254.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fefe:1984/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:1656731 (1.5 MiB)  TX bytes:298013 (291.0 KiB)

          Interrupt:59 Base address:0x2000 

eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:FE:19:84  

          inet addr:192.168.254.88  Bcast:192.168.254.255  Mask:255.255.255.0

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

          Interrupt:59 Base address:0x2000 

eth1      Link encap:Ethernet  HWaddr 00:0C:29:FE:19:7A  

          inet addr:192.168.211.128  Bcast:192.168.211.255  Mask:255.255.255.0

          inet6 addr: fe80::20c:29ff:fefe:197a/64 Scope:Link

          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1

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

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

          collisions:0 txqueuelen:1000 

          RX bytes:1719778 (1.6 MiB)  TX bytes:1704088 (1.6 MiB)

          Interrupt:67 Base address:0x2080 

lo        Link encap:Local Loopback  

          inet addr:127.0.0.1  Mask:255.0.0.0

          inet6 addr: ::1/128 Scope:Host

          UP LOOPBACK RUNNING  MTU:16436  Metric:1

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

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

          collisions:0 txqueuelen:0 

          RX bytes:161262 (157.4 KiB)  TX bytes:161262 (157.4 KiB)

[root@node1 ~]# service httpd start

Starting httpd: httpd: Could not reliably determine the server's fully qualified domain name, using 192.168.211.128 for ServerName

                                                           [  OK  ] 

你可能感兴趣的:(linux,职场,heartbeat,休闲,双机热备)