linux下Heartbeat做雙機熱備(1)

火星人 @ 2014-03-09 , reply:0


本節將介紹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 使用UDP694
bcast eth1 # Linux 使用網卡2進行心跳檢測
ucast eth1

192.168.211.131 檢測node2IP地址(在此位置,node2需要相應的修改)
auto_failback on
node node1 node1

uname名字

node node2 node2uname名字
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 設置虛擬

ip192.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 ]




[火星人 via ] linux下Heartbeat做雙機熱備(1)已經有147次圍觀

http://www.coctec.com/docs/linux/show-post-48868.html