日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Heartbeat+httpd+NFS 实现高可用的Web服务器

發布時間:2023/12/4 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Heartbeat+httpd+NFS 实现高可用的Web服务器 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

一、環境

????系統:CentOS 6.4x64位最小化安裝

????nfs:192.168.3.31

????node1:192.168.3.32

????node2:192.168.3.33

????vip:192.168.3.34

二、拓撲圖

三、前提條件

1.節點之間主機名互相解析

node1,node2:

[root@heatbeat-node1?~]#?cat?/etc/hosts 127.0.0.1???localhost?localhost.localdomain?localhost4?localhost4.localdomain4 ::1?????????localhost?localhost.localdomain?localhost6?localhost6.localdomain6 192.168.3.32?heatbeat-node1????node1 192.168.3.33?heatbeat-node2????node2

2.節點之間時間得同步

[root@heatbeat-node1?~]#?yum?-y?install?ntp [root@heatbeat-node1?~]#?ntpdate?asia.pool.ntp.org

3.節點之間配置SSH互信

node1:

[root@heatbeat-node1?~]#?ssh-keygen? [root@heatbeat-node1?~]#?ssh-copy-id?-i?.ssh/id_rsa.pub?root@heatbeat-node2 The?authenticity?of?host?'heatbeat-node2?(192.168.3.33)'?can't?be?established. RSA?key?fingerprint?is?5a:02:f0:4c:1d:97:2d:82:21:73:34:8e:ba:9c:97:d3. Are?you?sure?you?want?to?continue?connecting?(yes/no)??yes Warning:?Permanently?added?'heatbeat-node2,192.168.3.33'?(RSA)?to?the?list?of?known?hosts. root@heatbeat-node2's?password:? Now?try?logging?into?the?machine,?with?"ssh?'root@heatbeat-node2'",?and?check?in:.ssh/authorized_keysto?make?sure?we?haven't?added?extra?keys?that?you?weren't?expecting.[root@heatbeat-node1?~]#?vim?/etc/hosts [root@heatbeat-node1?~]#?ssh?node2 The?authenticity?of?host?'node2?(192.168.3.33)'?can't?be?established. RSA?key?fingerprint?is?5a:02:f0:4c:1d:97:2d:82:21:73:34:8e:ba:9c:97:d3. Are?you?sure?you?want?to?continue?connecting?(yes/no)??yes Warning:?Permanently?added?'node2'?(RSA)?to?the?list?of?known?hosts. Last?login:?Tue?Jun??2?11:44:02?2015?from?192.168.3.2 [root@heatbeat-node2?~]#?hostname heatbeat-node2

node2:

[root@heatbeat-node2?~]#?ssh-keygen? [root@heatbeat-node2?~]#?ssh-copy-id?-i?.ssh/id_rsa.pub?root@heatbeat-node1 [root@heatbeat-node2?~]#?ssh?node1 The?authenticity?of?host?'node1?(192.168.3.32)'?can't?be?established. RSA?key?fingerprint?is?87:ac:29:cf:62:38:27:13:b4:4b:79:d7:08:22:f8:9e. Are?you?sure?you?want?to?continue?connecting?(yes/no)??yes Warning:?Permanently?added?'node1'?(RSA)?to?the?list?of?known?hosts. Last?login:?Tue?Jun??2?11:43:52?2015?from?192.168.3.2 [root@heatbeat-node1?~]#?hostname heatbeat-node1

四、安裝相關軟件 (兩節點都要安裝)

1.heartbeat 安裝組件說明

  • heartbeat 核心組件 ?* ? ?

  • heartbeat-devel 開發包 ? ?

  • heartbeat-gui 圖形管理接口 * ? ?

  • heartbeat-ldirectord 為lvs高可用提供規則自動生成及后端realserver健康狀態檢查的組件 ? ?

  • heartbeat-pils 裝載庫插件接口 * ? ?

  • heartbeat-stonith 爆頭接口 *

注:帶*表示必須安裝

2.安裝heartbeat

node1,node2:

[root@heatbeat-node1?~]#?yum?install?heartbeat*?-y

3.安裝httpd

node1:

[root@heatbeat-node1?~]#?yum?install?httpd?-y [root@heatbeat-node1?~]#?echo?"ServerName?localhost:80"?>>/etc/httpd/conf/httpd.conf? [root@heatbeat-node1?~]#?service?httpd?start Starting?httpd:????????????????????????????????????????????[??OK??] [root@heatbeat-node1?~]#?echo?"<h1>node1.test.com</h1>"?>?/var/www/html/index.html [root@heatbeat-node1?~]#?iptables?-I?INPUT?-p?tcp?--dport?80?-j?ACCEPT [root@heatbeat-node1?~]#?service?iptables?save

測試

[root@heatbeat-node1?~]#?service?httpd?stop Stopping?httpd:????????????????????????????????????????????[??OK??] [root@heatbeat-node1?~]#?chkconfig?httpd?off

說明:測試完成后關閉服務,并讓其開機不啟動(注,httpd由heartbeat管理)

node2:

[root@heatbeat-node2?~]#?yum?install?httpd?-y [root@heatbeat-node2?~]#?echo?"ServerName?localhost:80"?>>/etc/httpd/conf/httpd.conf? [root@heatbeat-node2?~]#?service?httpd?start Starting?httpd:????????????????????????????????????????????[??OK??] [root@heatbeat-node2?~]#?echo?"<h1>node2.test.com</h1>"?>?/var/www/html/index.html [root@heatbeat-node2?~]#?iptables?-I?INPUT?-p?tcp?--dport?80?-j?ACCEPT [root@heatbeat-node2?~]#?service?iptables?save

測試

[root@heatbeat-node2?~]#?service?httpd?stop Stopping?httpd:????????????????????????????????????????????[??OK??] [root@heatbeat-node2?~]#?chkconfig?httpd?off

說明:測試完成后關閉服務,并讓其開機不啟動(注,httpd由heartbeat管理)

五、配置 heartbeat

1.配置文件說明

[root@heatbeat-node1?~]#?ls?/etc/ha.d/ harc??rc.d??README.config??resource.d??shellfuncs

說明:安裝好的heartbeat默認是沒有配置文件的,但提供了配置文件樣本

[root@heatbeat-node1?~]#?ll?/usr/share/doc/heartbeat-3.0.4/ total?144 -rw-r--r--?1?root?root??1873?Dec??3??2013?apphbd.cf -rw-r--r--?1?root?root???645?Dec??3??2013?authkeys -rw-r--r--?1?root?root??3701?Dec??3??2013?AUTHORS -rw-r--r--?1?root?root?58752?Dec??3??2013?ChangeLog -rw-r--r--?1?root?root?17989?Dec??3??2013?COPYING -rw-r--r--?1?root?root?26532?Dec??3??2013?COPYING.LGPL -rw-r--r--?1?root?root?10502?Dec??3??2013?ha.cf -rw-r--r--?1?root?root??5905?Dec??3??2013?haresources -rw-r--r--?1?root?root??2935?Dec??3??2013?README [root@heatbeat-node1?~]#?cd?/usr/share/doc/heartbeat-3.0.4/ [root@heatbeat-node1?heartbeat-3.0.4]#?cp?authkeys?ha.cf?haresources?/etc/ha.d/

說明:其中有三個配置文件是我們需要的分別為,authkeys、ha.cf、haresources

  • authkeys #是節點之間的認證key文件,我們不能讓什么服務器都加入集群中來,加入集群中的節點都是需要認證的

  • ha.cf #heartbeat的主配置文件

  • haresources #集群資源管理配置文件(在heartbeat所有版本中都是支持haresources來配置集群中的資源的)

2.配置authkeys文件

[root@heatbeat-node1?ha.d]#?dd?if=/dev/random??bs=512?count=1?|openssl?md5????#生成隨機秘鑰數 0+1?records?in 0+1?records?out 16?bytes?(16?B)?copied,?4.1404e-05?s,?386?kB/s (stdin)=?f5e377b9a3a4ae407467946ae1d694d5#編輯authkeys文件 [root@heatbeat-node1?ha.d]#?grep?-v?^#?authkeys? auth?1 1?md5?f5e377b9a3a4ae407467946ae1d694d5[root@heatbeat-node1?ha.d]#?chmod?600?authkeys????#修改密鑰文件的權限為600 [root@heatbeat-node1?ha.d]#?ll total?44 -rw-------?1?root?root???691?Jun??2?15:00?authkeys -rw-r--r--?1?root?root?10502?Jun??2?14:57?ha.cf -rwxr-xr-x?1?root?root???745?Dec??3??2013?harc -rw-r--r--?1?root?root??5905?Jun??2?14:57?haresources drwxr-xr-x?2?root?root??4096?Jun??2?14:46?rc.d -rw-r--r--?1?root?root???692?Dec??3??2013?README.config drwxr-xr-x?2?root?root??4096?Jun??2?14:46?resource.d -rw-r--r--?1?root?root??2082?May??6?18:52?shellfuncs

3.配置ha.cf文件

主要修改兩處(其它都可以默認):

(1).修改心跳信息的傳播方式(這里是組播)

mcast?eth0?225.100.100.100?694?1?0

(2).配置集群中的節點數

node????heatbeat-node1 node????heatbeat-node2

4.配置haresources文件

heatbeat-node1?IPaddr::192.168.3.34/24/eth0?httpd

5.復制以上三個配置文件到node2上

[root@heatbeat-node1?ha.d]#?scp?authkeys?ha.cf?haresources?node2:/etc/ha.d/ authkeys??????????????????????????????????????????????????????????????????????????????????????100%??691?????0.7KB/s???00:00???? ha.cf?????????????????????????????????????????????????????????????????????????????????????????100%???10KB??10.3KB/s???00:00???? haresources???????????????????????????????????????????????????????????????????????????????????100%?5954?????5.8KB/s???00:00?? [root@heatbeat-node1?ha.d]#?ssh?node2?ls?-l?/etc/ha.d total?44 -rw-------?1?root?root???691?Jun??3?10:33?authkeys -rw-r--r--?1?root?root?10545?Jun??3?10:33?ha.cf -rwxr-xr-x?1?root?root???745?Dec??3??2013?harc -rw-r--r--?1?root?root??5954?Jun??3?10:33?haresources drwxr-xr-x?2?root?root??4096?Jun??2?14:44?rc.d -rw-r--r--?1?root?root???692?Dec??3??2013?README.config drwxr-xr-x?2?root?root??4096?Jun??2?14:44?resource.d -rw-r--r--?1?root?root??2082?May??6?18:52?shellfuncs

6.啟動node1與node2

[root@heatbeat-node1?ha.d]#?service?heartbeat?start Starting?High-Availability?services:?INFO:??Resource?is?stopped Done. [root@heatbeat-node1?ha.d]#?ssh?node2?service?heartbeat?start Starting?High-Availability?services:?2015/06/03_10:36:56?INFO:??Resource?is?stopped Done.

六、測試Web集群

1.查看啟動的服務

[root@heatbeat-node1?ha.d]#?netstat?-anpt Active?Internet?connections?(servers?and?established) Proto?Recv-Q?Send-Q?Local?Address???????????????Foreign?Address?????????????State???????PID/Program?name??? tcp????????0??????0?0.0.0.0:111?????????????????0.0.0.0:*???????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?0.0.0.0:22??????????????????0.0.0.0:*???????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????????0.0.0.0:*???????????????????LISTEN??????1426/master????????? tcp????????0??????0?0.0.0.0:56970???????????????0.0.0.0:*???????????????????LISTEN??????1160/rpc.statd?????? tcp????????0?????52?192.168.3.32:22?????????????192.168.3.2:7332????????????ESTABLISHED?1539/sshd??????????? tcp????????0??????0?:::111??????????????????????:::*????????????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?:::80???????????????????????:::*????????????????????????LISTEN??????2348/httpd?????????? tcp????????0??????0?:::22???????????????????????:::*????????????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?::1:25??????????????????????:::*????????????????????????LISTEN??????1426/master????????? tcp????????0??????0?:::55609????????????????????:::*????????????????????????LISTEN??????1160/rpc.statd

2.查看IP

[root@heatbeat-node1?ha.d]#?ip?a 1:?lo:?<LOOPBACK,UP,LOWER_UP>?mtu?16436?qdisc?noqueue?state?UNKNOWN?link/loopback?00:00:00:00:00:00?brd?00:00:00:00:00:00inet?127.0.0.1/8?scope?host?loinet6?::1/128?scope?host?valid_lft?forever?preferred_lft?forever 2:?eth0:?<BROADCAST,MULTICAST,UP,LOWER_UP>?mtu?1500?qdisc?pfifo_fast?state?UP?qlen?1000link/ether?00:0c:29:23:44:ba?brd?ff:ff:ff:ff:ff:ffinet?192.168.3.32/24?brd?192.168.3.255?scope?global?eth0inet?192.168.3.34/24?brd?192.168.3.255?scope?global?secondary?eth0inet6?fe80::20c:29ff:fe23:44ba/64?scope?link?valid_lft?forever?preferred_lft?forever

3.測試

4.故障演示

1).關閉node1上的heartbeat

[root@heatbeat-node1?ha.d]#?service?heartbeat?stop????????#這關閉的是node1上的heartbeat服務 Stopping?High-Availability?services:?Done.#查看node1的IP和服務 [root@heatbeat-node1?ha.d]#?ip?a 1:?lo:?<LOOPBACK,UP,LOWER_UP>?mtu?16436?qdisc?noqueue?state?UNKNOWN?link/loopback?00:00:00:00:00:00?brd?00:00:00:00:00:00inet?127.0.0.1/8?scope?host?loinet6?::1/128?scope?host?valid_lft?forever?preferred_lft?forever 2:?eth0:?<BROADCAST,MULTICAST,UP,LOWER_UP>?mtu?1500?qdisc?pfifo_fast?state?UP?qlen?1000link/ether?00:0c:29:23:44:ba?brd?ff:ff:ff:ff:ff:ffinet?192.168.3.32/24?brd?192.168.3.255?scope?global?eth0inet6?fe80::20c:29ff:fe23:44ba/64?scope?link?valid_lft?forever?preferred_lft?forever [root@heatbeat-node1?ha.d]#?netstat?-anpt Active?Internet?connections?(servers?and?established) Proto?Recv-Q?Send-Q?Local?Address???????????????Foreign?Address?????????????State???????PID/Program?name??? tcp????????0??????0?0.0.0.0:111?????????????????0.0.0.0:*???????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?0.0.0.0:22??????????????????0.0.0.0:*???????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????????0.0.0.0:*???????????????????LISTEN??????1426/master????????? tcp????????0??????0?0.0.0.0:56970???????????????0.0.0.0:*???????????????????LISTEN??????1160/rpc.statd?????? tcp????????0?????52?192.168.3.32:22?????????????192.168.3.2:7332????????????ESTABLISHED?1539/sshd??????????? tcp????????0??????0?192.168.3.32:51322??????????192.168.3.33:22?????????????TIME_WAIT???-??????????????????? tcp????????0??????0?:::111??????????????????????:::*????????????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?:::22???????????????????????:::*????????????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?::1:25??????????????????????:::*????????????????????????LISTEN??????1426/master????????? tcp????????0??????0?:::55609????????????????????:::*????????????????????????LISTEN??????1160/rpc.statd??? #上面的結果顯示heartbeat的IP資源和httpd資源已被移除

2).查看node2上的IP和服務

[root@heatbeat-node1?ha.d]#?ssh?node2?hostname heatbeat-node2 [root@heatbeat-node1?ha.d]#?ssh?node2?ip?a 1:?lo:?<LOOPBACK,UP,LOWER_UP>?mtu?16436?qdisc?noqueue?state?UNKNOWN?link/loopback?00:00:00:00:00:00?brd?00:00:00:00:00:00inet?127.0.0.1/8?scope?host?loinet6?::1/128?scope?host?valid_lft?forever?preferred_lft?forever 2:?eth0:?<BROADCAST,MULTICAST,UP,LOWER_UP>?mtu?1500?qdisc?pfifo_fast?state?UP?qlen?1000link/ether?00:0c:29:e3:b1:f7?brd?ff:ff:ff:ff:ff:ffinet?192.168.3.33/24?brd?192.168.3.255?scope?global?eth0inet?192.168.3.34/24?brd?192.168.3.255?scope?global?secondary?eth0inet6?fe80::20c:29ff:fee3:b1f7/64?scope?link?valid_lft?forever?preferred_lft?forever#查看node2的服務 [root@heatbeat-node1?ha.d]#?ssh?node2?netstat?-anpt Active?Internet?connections?(servers?and?established) Proto?Recv-Q?Send-Q?Local?Address???????????????Foreign?Address?????????????State???????PID/Program?name??? tcp????????0??????0?0.0.0.0:111?????????????????0.0.0.0:*???????????????????LISTEN??????1113/rpcbind???????? tcp????????0??????0?0.0.0.0:22??????????????????0.0.0.0:*???????????????????LISTEN??????1264/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????????0.0.0.0:*???????????????????LISTEN??????1350/master????????? tcp????????0??????0?0.0.0.0:49086???????????????0.0.0.0:*???????????????????LISTEN??????1131/rpc.statd?????? tcp????????0?????80?192.168.3.33:22?????????????192.168.3.32:51322??????????ESTABLISHED?2419/sshd??????????? tcp????????0??????0?192.168.3.33:22?????????????192.168.3.32:51319??????????TIME_WAIT???-??????????????????? tcp????????0??????0?192.168.3.33:22?????????????192.168.3.2:7337????????????ESTABLISHED?1463/sshd??????????? tcp????????0??????0?:::111??????????????????????:::*????????????????????????LISTEN??????1113/rpcbind???????? tcp????????0??????0?:::80???????????????????????:::*????????????????????????LISTEN??????2381/httpd?????????? tcp????????0??????0?:::22???????????????????????:::*????????????????????????LISTEN??????1264/sshd??????????? tcp????????0??????0?::1:25??????????????????????:::*????????????????????????LISTEN??????1350/master????????? tcp????????0??????0?:::51270????????????????????:::*????????????????????????LISTEN??????1131/rpc.statd???? #結果表明IP資源和httpd資源已啟動

3).測試

從上面的結果能看出集群實現了web的高可用

七、給heartbeat提供一個共享存儲

1.配置NFS服務器

[root@nfs?~]#?mkdir?-pv?/web mkdir:?created?directory?`/web'#安裝nfs服務 [root@nfs?~]#?yum?install?nfs-utils?rpcbind?-y [root@nfs?~]#?cat?/etc/exports? /web/ 192.168.3.0/24(ro,async) [root@nfs?~]#?echo?'<h1>Cluster?NFS?Server</h1>'?>/web/index.html [root@nfs?~]#?service?rpcbind?start Starting?rpcbind:??????????????????????????????????????????[??OK??] [root@nfs?~]#?service?nfs?start Starting?NFS?services:?????????????????????????????????????[??OK??] Starting?NFS?quotas:???????????????????????????????????????[??OK??] Starting?NFS?mountd:???????????????????????????????????????[??OK??] Starting?NFS?daemon:???????????????????????????????????????[??OK??] Starting?RPC?idmapd:???????????????????????????????????????[??OK??] [root@nfs?~]#?showmount?-e?192.168.3.31 Export?list?for?192.168.3.31: /web?192.168.3.0/24

2.節點測試掛載

node1:

[root@heatbeat-node1?~]#?mount?-t?nfs?192.168.3.31:/web?/mnt [root@heatbeat-node1?~]#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3??????????????18G??1.3G???16G???8%?/ tmpfs?????????????????495M?????0??495M???0%?/dev/shm /dev/sda1?????????????194M???28M??156M??16%?/boot 192.168.3.31:/web??????18G??1.2G???16G???8%?/mnt [root@heatbeat-node1?~]#?ls?/mnt/ index.html [root@heatbeat-node1?~]#?cat?/mnt/index.html? <h1>Cluster?NFS?Server</h1> [root@heatbeat-node1?~]#?umount?/mnt

node2:

[root@heatbeat-node2?~]#?mount?-t?nfs?192.168.3.31:/web?/mnt [root@heatbeat-node2?~]#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3??????????????18G??1.3G???16G???8%?/ tmpfs?????????????????495M?????0??495M???0%?/dev/shm /dev/sda1?????????????194M???28M??156M??16%?/boot 192.168.3.31:/web??????18G??1.2G???16G???8%?/mnt [root@heatbeat-node2?~]#?ls?/mnt/ index.html [root@heatbeat-node2?~]#?cat?/mnt/index.html? <h1>Cluster?NFS?Server</h1> [root@heatbeat-node2?~]#?umount?/mnt

3.修改haresource文件

#編輯配置文件 [root@heatbeat-node1?~]#?vim?/etc/ha.d/haresources? heatbeat-node1?IPaddr::192.168.3.34/24/eth0?Filesystem::192.168.3.31:/web::/var/www/html::nfs??httpd #這里的意思是在httpd服務器之前,掛載文件nfs系統,將nfs文件系統掛載到/var/www/html目錄下

4.同步haresource配置文件

[root@heatbeat-node1?~]#?scp?/etc/ha.d/haresources?node2:/etc/ha.d/

5.重啟一下heartbeat

#重啟node2的服務 [root@heatbeat-node1?~]#?ssh?node2?service?heartbeat?restart Stopping?High-Availability?services:?Done.Waiting?to?allow?resource?takeover?to?complete:Done.Starting?High-Availability?services:?2015/06/03_11:02:28?INFO:??Resource?is?stopped Done.#重啟node1的服務 [root@heatbeat-node1?~]#?service?heartbeat?restart Stopping?High-Availability?services:?Done.Waiting?to?allow?resource?takeover?to?complete:Done.Starting?High-Availability?services:?INFO:??Resource?is?stopped Done.

6.查看一下端口

#這個時候資源服務應該都在node1上 #查看httpd服務 [root@heatbeat-node1?~]#?netstat?-anpt Active?Internet?connections?(servers?and?established) Proto?Recv-Q?Send-Q?Local?Address???????????????Foreign?Address?????????????State???????PID/Program?name??? tcp????????0??????0?0.0.0.0:111?????????????????0.0.0.0:*???????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?0.0.0.0:22??????????????????0.0.0.0:*???????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????????0.0.0.0:*???????????????????LISTEN??????1426/master????????? tcp????????0??????0?0.0.0.0:33258???????????????0.0.0.0:*???????????????????LISTEN??????-??????????????????? tcp????????0??????0?0.0.0.0:56970???????????????0.0.0.0:*???????????????????LISTEN??????1160/rpc.statd?????? tcp????????0?????52?192.168.3.32:22?????????????192.168.3.2:7332????????????ESTABLISHED?1539/sshd??????????? tcp????????0??????0?192.168.3.32:814????????????192.168.3.31:2049???????????ESTABLISHED?-??????????????????? tcp????????0??????0?:::111??????????????????????:::*????????????????????????LISTEN??????1142/rpcbind???????? tcp????????0??????0?:::80???????????????????????:::*????????????????????????LISTEN??????5912/httpd?????????? tcp????????0??????0?:::22???????????????????????:::*????????????????????????LISTEN??????1294/sshd??????????? tcp????????0??????0?::1:25??????????????????????:::*????????????????????????LISTEN??????1426/master????????? tcp????????0??????0?:::55609????????????????????:::*????????????????????????LISTEN??????1160/rpc.statd?????? tcp????????0??????0?:::56927????????????????????:::*????????????????????????LISTEN??????-??????????????????? #查看nfs服務 [root@heatbeat-node1?~]#?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3??????????????18G??1.3G???16G???8%?/ tmpfs?????????????????495M?????0??495M???0%?/dev/shm /dev/sda1?????????????194M???28M??156M??16%?/boot 192.168.3.31:/web??????18G??1.2G???16G???8%?/var/www/html#查看IP資源 [root@heatbeat-node1?~]#?ip?a 1:?lo:?<LOOPBACK,UP,LOWER_UP>?mtu?16436?qdisc?noqueue?state?UNKNOWN?link/loopback?00:00:00:00:00:00?brd?00:00:00:00:00:00inet?127.0.0.1/8?scope?host?loinet6?::1/128?scope?host?valid_lft?forever?preferred_lft?forever 2:?eth0:?<BROADCAST,MULTICAST,UP,LOWER_UP>?mtu?1500?qdisc?pfifo_fast?state?UP?qlen?1000link/ether?00:0c:29:23:44:ba?brd?ff:ff:ff:ff:ff:ffinet?192.168.3.32/24?brd?192.168.3.255?scope?global?eth0inet?192.168.3.34/24?brd?192.168.3.255?scope?global?secondary?eth0inet6?fe80::20c:29ff:fe23:44ba/64?scope?link?valid_lft?forever?preferred_lft?forever

7.測試一下Web服務

測試結果能看出我們通過heartbeat已經能夠正常訪問web共享站點了

8.模擬故障并測試

(1).停止node11上的heartbeat

[root@heatbeat-node1?~]#?service?heartbeat?stop Stopping?High-Availability?services:?Done.

(2).查看節點2的IP與服務

#查看node2 [root@heatbeat-node1?~]#?ssh?node2?ip?a 1:?lo:?<LOOPBACK,UP,LOWER_UP>?mtu?16436?qdisc?noqueue?state?UNKNOWN?link/loopback?00:00:00:00:00:00?brd?00:00:00:00:00:00inet?127.0.0.1/8?scope?host?loinet6?::1/128?scope?host?valid_lft?forever?preferred_lft?forever 2:?eth0:?<BROADCAST,MULTICAST,UP,LOWER_UP>?mtu?1500?qdisc?pfifo_fast?state?UP?qlen?1000link/ether?00:0c:29:e3:b1:f7?brd?ff:ff:ff:ff:ff:ffinet?192.168.3.33/24?brd?192.168.3.255?scope?global?eth0inet?192.168.3.34/24?brd?192.168.3.255?scope?global?secondary?eth0inet6?fe80::20c:29ff:fee3:b1f7/64?scope?link?valid_lft?forever?preferred_lft?forever [root@heatbeat-node1?~]#?ssh?node2?netstat?-anpt Active?Internet?connections?(servers?and?established) Proto?Recv-Q?Send-Q?Local?Address???????????????Foreign?Address?????????????State???????PID/Program?name??? tcp????????0??????0?0.0.0.0:111?????????????????0.0.0.0:*???????????????????LISTEN??????1113/rpcbind???????? tcp????????0??????0?0.0.0.0:38901???????????????0.0.0.0:*???????????????????LISTEN??????-??????????????????? tcp????????0??????0?0.0.0.0:22??????????????????0.0.0.0:*???????????????????LISTEN??????1264/sshd??????????? tcp????????0??????0?127.0.0.1:25????????????????0.0.0.0:*???????????????????LISTEN??????1350/master????????? tcp????????0??????0?0.0.0.0:49086???????????????0.0.0.0:*???????????????????LISTEN??????1131/rpc.statd?????? tcp????????0??????0?192.168.3.33:926????????????192.168.3.31:2049???????????ESTABLISHED?-??????????????????? tcp????????0?????80?192.168.3.33:22?????????????192.168.3.32:51327??????????ESTABLISHED?6572/sshd??????????? tcp????????0??????0?192.168.3.33:22?????????????192.168.3.2:7337????????????ESTABLISHED?1463/sshd??????????? tcp????????0??????0?:::111??????????????????????:::*????????????????????????LISTEN??????1113/rpcbind???????? tcp????????0??????0?:::80???????????????????????:::*????????????????????????LISTEN??????6546/httpd?????????? tcp????????0??????0?:::22???????????????????????:::*????????????????????????LISTEN??????1264/sshd??????????? tcp????????0??????0?::1:25??????????????????????:::*????????????????????????LISTEN??????1350/master????????? tcp????????0??????0?:::57119????????????????????:::*????????????????????????LISTEN??????-??????????????????? tcp????????0??????0?:::51270????????????????????:::*????????????????????????LISTEN??????1131/rpc.statd?????? [root@heatbeat-node1?~]#?ssh?node2?df?-h Filesystem????????????Size??Used?Avail?Use%?Mounted?on /dev/sda3??????????????18G??1.3G???16G???8%?/ tmpfs?????????????????495M?????0??495M???0%?/dev/shm /dev/sda1?????????????194M???28M??156M??16%?/boot 192.168.3.31:/web??????18G??1.2G???16G???8%?/var/www/html #通過以上結果能看出node2已全部接管所有資源

(3).測試服務

4).重新啟動node1上heartbeat

#node1重新啟動服務 [root@heatbeat-node1?~]#?service?heartbeat?start Starting?High-Availability?services:?INFO:??Resource?is?stopped Done.#查看日志 [root@heatbeat-node1?~]#?tail?-f?/var/log/messages? Jun??3?11:10:33?heatbeat-node1?/usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.3.34)[6491]:?INFO:??Success Jun??3?11:10:33?heatbeat-node1?/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.3.31:/web)[6599]:?INFO:??Resource?is?stopped Jun??3?11:10:33?heatbeat-node1?ResourceManager(default)[6372]:?info:?Running?/etc/ha.d/resource.d/Filesystem?192.168.3.31:/web?/var/www/html?nfs?start Jun??3?11:10:33?heatbeat-node1?Filesystem(Filesystem_192.168.3.31:/web)[6674]:?INFO:?Running?start?for?192.168.3.31:/web?on?/var/www/html Jun??3?11:10:33?heatbeat-node1?/usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.3.31:/web)[6666]:?INFO:??Success Jun??3?11:10:33?heatbeat-node1?ResourceManager(default)[6372]:?info:?Running?/etc/init.d/httpd??start Jun??3?11:10:33?heatbeat-node1?heartbeat:?[6359]:?info:?local?HA?resource?acquisition?completed?(standby). Jun??3?11:10:33?heatbeat-node1?heartbeat:?[6334]:?info:?Standby?resource?acquisition?done?[foreign]. Jun??3?11:10:33?heatbeat-node1?heartbeat:?[6334]:?info:?Initial?resource?acquisition?complete?(auto_failback) Jun??3?11:10:34?heatbeat-node1?heartbeat:?[6334]:?info:?remote?resource?transition?completed.

到此heartbeat的高可用已基本完成

轉載于:https://blog.51cto.com/ly36843/1657488

總結

以上是生活随笔為你收集整理的Heartbeat+httpd+NFS 实现高可用的Web服务器的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。