The two hosts are backup to each other, and the Web service displays the resources on the NFS file system.
Add a Linux 6.8 system as an NFS file server
catalog:
1. Complete the basic configuration of HeartBeat
2. Configure server for NFS
3. Configure HeartBeat resource management server to use NFS resources
4. Result test
1. Complete the basic configuration of HeartBeat
The basic configuration is not described here. Please refer to the following document.
HeartBeat basic configuration (realizing Web service hot standby)
2. Configure server for NFS
Create a shared folder/file/web/
mkdir -p /file/web/ echo "<h1>this is nfs server</h1>" >> /file/web/index.html
Configure shared files
vim /etc/exports //add to /file/web 192.168.0.0/255.255.0.0(ro)
NFS service configuration
vim /etc/sysconfig/nfs
Start the corresponding NFS version, here we use 4
Start the service and configure the power on self start
service nfs start chkconfig nfs on
Check shared folders
Turn off selinux
If it's a temporary test
setenforce 0If used for a long time
vim /etc/selinux/config
be careful:
If it is an actual production environment, it is recommended to turn on selinux, and then write security rules.
NFS service configuration complete
3. Configure HeartBeat resource management server to use NFS resources
Mounting of test documents
NA1(close selinux)
setenforce 0 mkdir -p /mnt/webfile/ mount -t nfs 192.168.94.131:/file/web /mnt/webfile/
No problem with mounting. Unmount
umount /mnt/webfile
NA2 (turn off selinux)
setenforce 0
Configure heartbeat Explorer
NA1&NA2 close heartbeat service
service heartbeat stop
Mount the NFS shared directory to / var/www/html
vim /etc/ha.d/haresources //add to na1.server.com IPaddr::192.168.94.222/24/eth1 Filesystem::192.168.94.131:/file/web::/var/www/html::nfs httpd
Then copy the haresource to NA2.
scp /etc/ha.d/haresources na2:/etc/ha.d/
Start heartbeat service
service heartbeat start ssh na2 'service heartbeat start'
view log
[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. Result test
visit VIP192.168.94.222
close NA1 Revisit
Access normal, view NA2 Log of
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.
Red font indicates a series of activities carried out by NA2 after NA1dead.
Take over VIP, Mount resources and start httpd service.
There is always one on the way to study and keep fit