2台主機互為備份,Web服務顯示NFS文件系統上的資源。新增一個Linux6.8的系統作為NFS文件伺服器目錄:1、完成HeartBeat基礎配置2、配置NFS伺服器3、配置HeartBeat資源管理伺服器使用NFS資源4、結果測試1、完成HeartBeat基礎配置基礎配置這裡就不在敘述了,參考下麵... ...
2台主機互為備份,Web服務顯示NFS文件系統上的資源。
新增一個Linux6.8的系統作為NFS文件伺服器
目錄:
1、完成HeartBeat基礎配置
2、配置NFS伺服器
3、配置HeartBeat資源管理伺服器使用NFS資源
4、結果測試
1、完成HeartBeat基礎配置
基礎配置這裡就不在敘述了,參考下麵這篇文檔。
HeartBeat基礎配置(實現Web服務雙機熱備)
2、配置NFS伺服器
創建共用文件夾/file/web/
mkdir -p /file/web/ echo "<h1>this is nfs server</h1>" >> /file/web/index.html配置共用文件
vim /etc/exports 添加 /file/web 192.168.0.0/255.255.0.0(ro)NFS服務配置
vim /etc/sysconfig/nfs啟動相應的NFS版本,這裡我們使用4
啟動服務,配置開機自啟
service nfs start chkconfig nfs on檢查共用的文件夾
關閉selinux
如果是臨時測試
setenforce 0如果長期使用
vim /etc/selinux/config
註意:
如果是實際生產環境,建議將selinux開啟,然後乖乖去寫安全規則。
NFS服務配置完畢
3、配置HeartBeat資源管理伺服器使用NFS資源
測試文件掛載
NA1(關閉selinux)
setenforce 0 mkdir -p /mnt/webfile/ mount -t nfs 192.168.94.131:/file/web /mnt/webfile/掛載沒問題。取消掛載
umount /mnt/webfileNA2(關閉selinux)
setenforce 0
配置heartbeat資源管理器
NA1&NA2關閉heartbeat服務
service heartbeat stop將NFS共用目錄掛載到/var/www/html下
vim /etc/ha.d/haresources 添加 na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd然後將haresource複製到NA2上。
scp /etc/ha.d/haresources na2:/etc/ha.d/啟動heartbeat服務
service heartbeat start ssh na2 'service heartbeat start'查看日誌
[root@na1 ~]# tail -f /var/log/messages May 25 09:09:33 na1 heartbeat: [4960]: info: G_main_add_SignalHandler: Added signal handler for signal 17 May 25 09:09:33 na1 heartbeat: [4960]: info: Local status now set to: 'up' May 25 09:09:33 na1 heartbeat: [4960]: info: Link na1.server.com:eth1 up. May 25 09:09:44 na1 heartbeat: [4960]: info: Link na2.server.com:eth1 up. May 25 09:09:44 na1 heartbeat: [4960]: info: Status update for node na2.server.com: status up May 25 09:09:44 na1 harc(default)[4968]: info: Running /etc/ha.d//rc.d/status status May 25 09:09:44 na1 heartbeat: [4960]: info: Comm_now_up(): updating status to active May 25 09:09:44 na1 heartbeat: [4960]: info: Local status now set to: 'active' May 25 09:09:45 na1 heartbeat: [4960]: info: Status update for node na2.server.com: status active May 25 09:09:45 na1 harc(default)[4986]: info: Running /etc/ha.d//rc.d/status status May 25 09:09:55 na1 heartbeat: [4960]: info: remote resource transition completed. May 25 09:09:55 na1 heartbeat: [4960]: info: remote resource transition completed. May 25 09:09:55 na1 heartbeat: [4960]: info: Initial resource acquisition complete (T_RESOURCES(us)) May 25 09:09:55 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5038]: INFO: Resource is stopped May 25 09:09:55 na1 heartbeat: [5002]: info: Local Resource acquisition completed. May 25 09:09:55 na1 harc(default)[5119]: info: Running /etc/ha.d//rc.d/ip-request-resp ip-request-resp May 25 09:09:55 na1 ip-request-resp(default)[5119]: received ip-request-resp IPaddr::192.168.94.222/24/eth1 OK yes May 25 09:09:55 na1 ResourceManager(default)[5138]: info: Acquiring resource group: na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5164]: INFO: Resource is stopped May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.94.222/24/eth1 start May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: Adding inet address 192.168.94.222/24 with broadcast address 192.168.94.255 to device eth1 May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: Bringing device eth1 up May 25 09:09:56 na1 IPaddr(IPaddr_192.168.94.222)[5285]: INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.94.222 eth1 192.168.94.222 auto not_used not_used May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[5259]: INFO: Success May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[5369]: INFO: Resource is stopped May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/ha.d/resource.d/Filesystem 192.168.94.131:/file/web /var/www/html nfs start May 25 09:09:56 na1 Filesystem(Filesystem_192.168.94.131:/file/web)[5444]: INFO: Running start for 192.168.94.131:/file/web on /var/www/html May 25 09:09:56 na1 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[5436]: INFO: Success May 25 09:09:56 na1 ResourceManager(default)[5138]: info: Running /etc/init.d/httpd start May 25 09:09:57 na1 ntpd[1741]: Listen normally on 7 eth1 192.168.94.222 UDP 123
4、結果測試
訪問VIP192.168.94.222
關閉NA1再訪問
訪問正常,查看NA2的日誌
May 25 09:09:04 na2 heartbeat: [3838]: info: Status update for node na1.server.com: status up May 25 09:09:04 na2 harc(default)[3845]: info: Running /etc/ha.d//rc.d/status status May 25 09:09:05 na2 heartbeat: [3838]: info: Comm_now_up(): updating status to active May 25 09:09:05 na2 heartbeat: [3838]: info: Local status now set to: 'active' May 25 09:09:05 na2 heartbeat: [3838]: info: Status update for node na1.server.com: status active May 25 09:09:05 na2 harc(default)[3861]: info: Running /etc/ha.d//rc.d/status status May 25 09:09:15 na2 heartbeat: [3838]: info: local resource transition completed. May 25 09:09:15 na2 heartbeat: [3838]: info: Initial resource acquisition complete (T_RESOURCES(us)) May 25 09:09:15 na2 heartbeat: [3879]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys na2.server.com] to acquire. May 25 09:09:15 na2 heartbeat: [3838]: info: remote resource transition completed. May 25 09:15:28 na2 dhclient[1500]: DHCPREQUEST on eth1 to 192.168.94.254 port 67 (xid=0x14aa7d01) May 25 09:15:28 na2 dhclient[1500]: DHCPACK from 192.168.94.254 (xid=0x14aa7d01) May 25 09:15:28 na2 dhclient[1500]: bound to 192.168.94.130 -- renewal in 848 seconds. May 25 09:15:28 na2 NetworkManager[1470]: <info> (eth1): DHCPv4 state changed renew -> renew May 25 09:15:28 na2 NetworkManager[1470]: <info> address 192.168.94.130 May 25 09:15:28 na2 NetworkManager[1470]: <info> prefix 24 (255.255.255.0) May 25 09:15:28 na2 NetworkManager[1470]: <info> gateway 192.168.94.2 May 25 09:15:28 na2 NetworkManager[1470]: <info> nameserver '192.168.94.2' May 25 09:15:28 na2 NetworkManager[1470]: <info> domain name 'localdomain' May 25 09:15:28 na2 heartbeat: [3838]: info: Received shutdown notice from 'na1.server.com'. May 25 09:15:28 na2 heartbeat: [3838]: info: Resources being acquired from na1.server.com. May 25 09:15:28 na2 heartbeat: [3931]: info: acquire local HA resources (standby). May 25 09:15:28 na2 heartbeat: [3931]: info: local HA resource acquisition completed (standby). May 25 09:15:28 na2 heartbeat: [3838]: info: Standby resource acquisition done [all]. May 25 09:15:28 na2 heartbeat: [3932]: info: No local resources [/usr/share/heartbeat/ResourceManager listkeys na2.server.com] to acquire. May 25 09:15:28 na2 harc(default)[3957]: info: Running /etc/ha.d//rc.d/status status May 25 09:15:29 na2 mach_down(default)[3972]: info: Taking over resource group IPaddr::192.168.94.222/24/eth1 May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Acquiring resource group: na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[4023]: INFO: Resource is stopped May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Running /etc/ha.d/resource.d/IPaddr 192.168.94.222/24/eth1 start May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: Adding inet address 192.168.94.222/24 with broadcast address 192.168.94.255 to device eth1 May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: Bringing device eth1 up May 25 09:15:29 na2 IPaddr(IPaddr_192.168.94.222)[4144]: INFO: /usr/libexec/heartbeat/send_arp -i 200 -r 5 -p /var/run/resource-agents/send_arp-192.168.94.222 eth1 192.168.94.222 auto not_used not_used May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/IPaddr(IPaddr_192.168.94.222)[4118]: INFO: Success May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[4228]: INFO: Resource is stopped May 25 09:15:29 na2 ResourceManager(default)[3997]: info: Running /etc/ha.d/resource.d/Filesystem 192.168.94.131:/file/web /var/www/html nfs start May 25 09:15:29 na2 Filesystem(Filesystem_192.168.94.131:/file/web)[4303]: INFO: Running start for 192.168.94.131:/file/web on /var/www/html May 25 09:15:29 na2 /usr/lib/ocf/resource.d//heartbeat/Filesystem(Filesystem_192.168.94.131:/file/web)[4295]: INFO: Success May 25 09:15:30 na2 ResourceManager(default)[3997]: info: Running /etc/init.d/httpd start May 25 09:15:30 na2 mach_down(default)[3972]: info: /usr/share/heartbeat/mach_down: nice_failback: foreign resources acquired May 25 09:15:30 na2 mach_down(default)[3972]: info: mach_down takeover complete for node na1.server.com. May 25 09:15:59 na2 heartbeat: [3838]: WARN: node na1.server.com: is dead May 25 09:15:59 na2 heartbeat: [3838]: info: Dead node na1.server.com gave up resources. May 25 09:15:59 na2 heartbeat: [3838]: info: Link na1.server.com:eth1 dead.紅色字體表示,NA1dead後,NA2進行的一系列活動。
接管VIP,掛載資源,啟動httpd服務。
讀書和健身總有一個在路上