HeartBeatv2 Haresources simple implementation HTTPD service high available

Experimental environment:

Virtual machine ha1: 192.168.61.130

Virtual machine ha2: 192.168.61.132

vip:192.168.61.100

Experiment description:

ha1 httpdServiceindex.html The content is set toha1

ha2ofhttpdServiceindex.html The content is set toha2

It is convenient to observe the effect when switching between the two hosts

Notes:

(a) .Times between nodes must be synchronized: usentpProtocol implementation;

Server/etc/ntp.confFor reference:

driftfile/var/lib /ntp/drift

restrict -6default kod nomodify notrap nopeer noquery

restrict127.0.0.1

restrict -6 ::1

restrict192.168.61.0 mask 255.255.255.0 nomodify

restrict 0.0.0.0mask 0.0.0.0 nomodify notrap noquery notrust

server127.127.1.0

fudge 127.127.1.0stratum 8

server220.130.158.71 prefer

server220.130.158.51

includefile/etc/ntp/crypto/pw

keys/etc/ntp/keys

Note: You must wait after setting the restart service10-15Try to sync again in minutes, command:ntpdata 192.168.61.130, Compare the time of the two machines with the synchronization command:data;ssh 192.168.61.130’data’

ha2 It is best to set a timed task every5Minute sync time:

crontab -e

*/5 * * * * / usr/sbin/ntpdata 192.168.61.130

(b). Nodes need to communicate with each other through host names, and the host must be resolved toIPAddress;

(1)It is recommended to use the name resolution functionhostsfile to achieve; span>

(2) The name used in the communication must be consistent with the node name: “uname -n” command, or< /span>hostname” The displayed names are consistent;

(3) .Establish rootUsers can authenticate based on the key;

# ssh-keygen -t rsa -P”

#ssh-copy-id -i /root/.ssh/id_rsa.pub root@HOSTNAME

(4) .Be sure to close SELINUX and empty iptables

< p style="margin-left:84px;"> Note: Defined as resources in the cluster service, they must not be automatically started after booting; because they will be controlled by crmManagement;

ha1Configuration

Install heartbeat V2

(a ). Install the epel source first, the system source does not have libnet

wget ftp://ftp.pbone.net/mirror/dl.iuscommunity.org/pub/ius/archive/Redhat/6/i386/epel-release-6-5.noarch.rpm< /p>

rpm -ivh epel-release-6-5.noarch. rpm

(b ). Install related packages:

yum install net-snmp-libs libnet PyXML

rpm -ivh heartbeat-2.1.4-12.el6.x86_64.rpm

heartbeat-pils-2.1.4-12.el6.x86_64.rpm

heartbeat-stonith-2.1.4-12.el6.x86_64.rpm

yum install httpd

(c) .Edit ha.cf file

vim / etc/ha.cf add content as follows:

Logfacility local0# The log uses the local0 setting in rsyslog

keepalive1 #monitoring frequency, every 1 second

deadtime3 #Death judgment time

warntime2 #Exception warning time

mcasteth0 225.0. 0.1 694 1 0 #Multicast address setting

auto_failbackon #automatically go online after repair

node ha1 #Node set置

node node ha2 #Node settings

ping 192.168.61.2 #third-party arbitration settings

(d). Edit the authkeys file

< p style="margin-left:28px;">auth 2

#1 crc

2 sha1HI! #The longer the key phrase, the more random the better

#3 md5Hello!

(e) EditharesourcesAdd:

ha1 192.168.61.100 httpd #Set the host name of the main service ,VIP, service3A resource

(f)Editindex.htmlHome

echo “ha1″> /var/www /html/index.html

ha2Configuration strong>

Install heartbeat V2

(a). Install epel source first, system source does not have libnet p>

wget ftp://ftp.pbone.net/mirror/dl .iuscommunity.org/pub/ius/archive/Redhat/6/i386/epel-release-6-5.noarch.rpm

< span style="font-family:'宋体';font-size:12px;"> rpm -ivh epel-release-6-5.noarch.rpm

(b). Install related packages:

yum install net-snmp-libs libnet PyXML

rpm-ivh heartbeat-2.1.4-12.el6.x86_64.rpm

heartbeat-pils-2.1.4- 12.el6.x86_64.rpm

Heartbeat -stonith-2.1.4-12.el6.x86_64.rpm

yum install httpd

(c)copyha1ha.cfharesourcesauthkeys

scp192.168.61.130: /etc/ha.d/{ha.cf,haresour ces,authkeys} /etc/ha.d/

(d)Editindex.htmlHome

echo “ha2″> /var/www /html/index.html

(e)Add timed school hours task,every5Update time every minute p>

crontab-e

*/5* * * * /usr/sbin/ntpdata 192.168.61.130

Start the two machines separatelyheartbeatService

service heartbeat start p>

Use other hosts to accesshttp://192.168.61.100/index.html, Closeha1,ha2One ​​of them, refresh the page and you can see the content of the webpageha1ha2show in turn

Show. Useifconfig to check the working host, you can findvip Already configured oneth0:0on

Leave a Comment

Your email address will not be published.