案例一
案例說明:實現基於HA高可用性的羣集系統,採用LVA-DR直接路由模型實現
實驗拓撲圖:
1.node1和node2羣集服務器網絡配置:
node1的配置,eth0的配置:
心跳網卡的配置,在vm3區域中:
node2的配置,eth0的配置:
心跳網卡eth1的配置(在vm3區域中)
主機名配置
node1主機名配置
[root@localhost ~]# vim /etc/sysconfig/network
[root@localhost ~]# hostname node1.a.com
[root@localhost ~]# hostname #查看主機名
node1.a.com
[root@node1 ~]# vim /etc/hosts ##配置node1的本地DNS解析
node2主機名配置
[root@localhost ~]# vim /etc/sysconfig/network
[root@localhost ~]# hostname node2.a.com #配置後需註銷才能生效。
[root@localhost ~]# hostname #查看主機名
node2.a.com
[root@node2 ~]# vim /etc/hosts
在node1上安裝httpd
[root@node1 ~]#cd /mnt/cdrom/Server/
[root@node1 Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
[root@node1 ~]# cd /var/www/html/
[root@node1 html]# echo "node1.a.com" >index.html
啓動服務
[root@node1 ~]# service httpd start
在node2上安裝httpd
[root@node2 ~]#cd /mnt/cdrom/Server/
[root@node2 Server]# rpm -ivh httpd-2.2.3-31.el5.i386.rpm
[root@node2 ~]# cd /var/www/html/
[root@node2 html]# echo "node2.a.com" >index.html
啓動服務
[root@node2 ~]# service httpd start
便於測試安裝lynx
[root@node1 ~]# yum install -y lynx
[root@node2 ~]# yum install -y lynx
測試:
heartbeat的配置node2的配置
使用yum安裝heartbeat相應的軟件包
[root@node2 ~]# yum localinstall -y heartbeat-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpm --nogpgcheck
拷貝heartbeat的3個配置文件到etc下ha.d目錄下
[root@node2 ~]# cd /usr/share/doc/heartbeat-2.1.4/
[root@node2 heartbeat-2.1.4]# cp ha.cf haresources authkeys /etc/ha.d/
[root@node2 heartbeat-2.1.4]# cd /etc/ha.d/
編譯心跳探測配置文件ha.cf
[root@node2 ha.d]# vim ha.cf
定義心跳網卡
96 bcast eth1 # Solaris
聲明羣集的節點
214 node node1.a.com
215 node node2.a.com
215 node node2.a.com
[root@node2 ha.d]# dd if=/dev/random bs=512 count=1
[root@node2 ha.d]# dd if=/dev/random bs=512 count=1 |openssl md5
0+1 records in
0+1 records out
128 bytes (128 B) copied, 0.000166257 seconds, 770 kB/s
c8dc2f3926fb282fc60798e36dedf43c
0+1 records out
128 bytes (128 B) copied, 0.000166257 seconds, 770 kB/s
c8dc2f3926fb282fc60798e36dedf43c
改變authkeys的權限
[root@node2 ha.d]# chmod 600 authkeys
配置驗證鑰匙(爲了實現雙方身份驗證)
[root@node2 ha.d]# vim authkeys
27 auth 3
28 3 md5 c8dc2f3926fb282fc60798e36dedf43c
28 3 md5 c8dc2f3926fb282fc60798e36dedf43c
編輯heartbeat資源管理器:(用於管理Director上的服務,比如httpd的啓動)
[root@node2 ha.d]# vim haresources
45 node2.a.com 192.168.2.11/24/eth0/192.168.2.255 httpd
#192.168.2.11是vip,httpd是heartbeat控制的服務類資源
將httpd的控制腳本複製到heartbeat資源管理目錄
[root@node2 ha.d]# cp /etc/init.d/httpd resource.d/
啓動heartbeat服務
[root@node2 ha.d]# service heartbeat start
Node1的配置,這裏我們從node2上拷貝
[root@node1 html]# scp node2.a.com:/root/*.rpm ./
[root@node1 html]# yum localinstall -y heartbeat-2.1.4-9.el5.i386.rpm heartbeat-pils-2.1.4-10.el5.i386.rpm heartbeat-stonith-2.1.4-10.el5.i386.rpm libnet-1.1.4-3.el5.i386.rpm perl-MailTools-1.77-1.el5.noarch.rpm --nogpgcheck
[root@node1 html]# cd /etc/ha.d/
[root@node1 ha.d]# ll
total 24
-rw-r--r-- 1 root root 692 Jul 25 2009 README.config
-rwxr-xr-x 1 root root 745 Jul 25 2009 harc
drwxr-xr-x 2 root root 4096 Aug 14 17:54 rc.d
drwxr-xr-x 2 root root 4096 Aug 14 17:54 resource.d
-rw-r--r-- 1 root root 7862 Jul 25 2009 shellfuncs
-rw-r--r-- 1 root root 692 Jul 25 2009 README.config
-rwxr-xr-x 1 root root 745 Jul 25 2009 harc
drwxr-xr-x 2 root root 4096 Aug 14 17:54 rc.d
drwxr-xr-x 2 root root 4096 Aug 14 17:54 resource.d
-rw-r--r-- 1 root root 7862 Jul 25 2009 shellfuncs
[root@node1 ha.d]# scp node2.a.com:/etc/ha.d/ha.cf /etc/ha.d/
[email protected]'s password:
ha.cf 100% 10KB 10.4KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/ha.d/haresources /etc/ha.d/
[email protected]'s password:
haresources 100% 5958 5.8KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/ha.d/authkeys /etc/ha.d/
[email protected]'s password:
authkeys 100% 691 0.7KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/init.d/httpd /etc/ha.d/resource.d/
[email protected]'s password:
httpd 100% 3263 3.2KB/s 00:00
[email protected]'s password:
ha.cf 100% 10KB 10.4KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/ha.d/haresources /etc/ha.d/
[email protected]'s password:
haresources 100% 5958 5.8KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/ha.d/authkeys /etc/ha.d/
[email protected]'s password:
authkeys 100% 691 0.7KB/s 00:00
[root@node1 ha.d]# scp node2.a.com:/etc/init.d/httpd /etc/ha.d/resource.d/
[email protected]'s password:
httpd 100% 3263 3.2KB/s 00:00
現在可以查看一下node2的網絡信息
[root@node2 ha.d]# cd /usr/lib
lib/ libexec/
[root@node2 ha.d]# cd /usr/lib/heartbeat/
[root@node2 heartbeat]# ./hb_standby ##設置爲備份
2012/08/15_12:18:21 Going standby [all].
lib/ libexec/
[root@node2 ha.d]# cd /usr/lib/heartbeat/
[root@node2 heartbeat]# ./hb_standby ##設置爲備份
2012/08/15_12:18:21 Going standby [all].
[root@node2 ~]# ./hb_takeover #可以搶佔回來
未完待續...