Lamp + WordPress for HA High Availability Based on HeartBeat V2 CRM

One Heartbeat basic theory

Provide redundant system:
HA Cluster: In order to improve the system callability, combine multiple hosts to build a cluster;

Split brain, partitioned cluster

Voting system: voting system
When each node in HA cannot detect each other’s heartbeat information, it must not be able to coordinate work; this state is partitioned cluster;

The principle that the minority obeys the majority: quorum
With quorum> total/2
Without quorum <= total/2

Arbitration equipment:
disk = qdisk
ping node

failover: failover, failover
failback: failback, failback

Resource type: HA-aware : The resource itself can directly call the HA function at the bottom of the HA cluster;
Non-HA-aware: The HA function must be implemented on the HA cluster with the help of CRM;

Resource constraint:
location : Location constraint, which defines the tendency of the resource to the node; expressed in numerical values, -oo, +oo;
colocation: arrangement constraint, defines the tendency of resources to be “together” with each other; -oo, +oo
Grouping: It is also possible to bind multiple resources together;
Order: Order constraint, which defines the order in which resources are started on the same node;

Resource type:
Primitive: The main resource can only run on a single node in the cluster; (also called native);
group: group resource, container, containing one or more resources, these resources can be uniformly scheduled through the “group” resource ;
clone: ​​clone resources, you can run multiple clones on multiple nodes in the same cluster;
master/slave: master-slave Resources, run two resources on two nodes in the same cluster, one of which is the master and the other is the slave;

Resource isolation:
Level
Node: STONITH (Shooting The Other Node In The Head)
Power switch
Power switch
Resource: fencing
FC SAN switch

V Heart vbr> 3 Messaging Layer: 2
vbr> > Corosync
named cman (RedHat, RHCS)
keepalived (completely different from the above three types)

resources (resources, configuration files)
heartbeat vha 1 resource, configuration file: heartbeat vha br> Heartbeat v2 crm (Run a crmd process on each node, configure the interface: command line client program crmsh, GUI client: hb_gui);
Heartbeat v3, pacemaker (pacemaker can be run as a plug-in or stand-alone; configuration interface , CLI interface: crmsh, pcs; GUI: hawk(webgui), LCMC, pacemaker-mgmt);
rgmanager (configuration interface, CLI: clust, cman_tool; GUI: Conga(luci+ricci))

< p> Combination method:
comaker + comaker coagbr> heartbeat v1
heartbeat v2
heartbeat v3 + pacemaker pacemaker pacemaker
er (RHCS)
cman + pacemaker

LRM: Local Resource Manager, provided by CRM through subroutines;
RA: Resouce Agent
usually heartbeat legacy RA, heartbeat legacy Located in the /etc/ha.d/haresources.d/ directory;
LSB: Linux Standard Base, scripts in the /etc/rc.d/init.d directory, accept at least 4 parameters: {start|stop| restart|status};
OCF: Open Cluster Framework
Subcategory: provider
STONITH: Resources dedicated to calling STONITH device functions; usually a clone Heartbeat;

Information transmission mechanism
Serail cable: The scope of action is limited and it is not recommended to use it;
Ethernet cable:
UDP Unicast
UDP Multicast
UDP Multicast
It identifies an IP multicast domain; IANA (Internet Assigned number authority) allocates Class D address space for IP multicast use; its range is: 224.0.0.0-239.255.255.255;
Permanent multicast address: 224.0.0.0 -224.0.0.255;
Temporary multicast address: 224.0.1.0-238.255.255.255;
Local multicast address: 239.0.0.0-239.255.255.255, which is only valid in a specific local area;

< p>

HA case: ha web services
There are three resources:
ip, httpd, filesystem

fip: floating ip, 172.16.100.17
Relations: use daemon: httpd

Let resources run on the same node through arrangement constraints;
Sequential constraints: Start resources in an order;

Program selection:
Heartbeat v2 + haresources
heartbeat v2 + haresources

Prerequisites for configuring HA cluster:
(1) Time between nodes must be synchronized: use ntp protocol to achieve;
(2) Nodes need to communicate with each other through host names, and host to IP must be resolved Address;
(a) It is recommended that the name resolution function be implemented using the hosts file;
(b) The name used in the communication must be consistent with the node name: the “uname -n” command, or the “hostname” display Keep the names consistent;
(3) Consider whether the arbitration device will be used;
(4) Establish root users between nodes to be authenticated based on keys;
# ssh-keygen -t rsa -P ”
# ssh-copy-id -i /root/.ssh/id_rsa.pub root@HOSTNAME

Note: It is defined as a resource in the cluster service, and it must not be started automatically; because they It will be managed by crm;

The working model of HA Cluster:
A/P: Two-node cluster, active, passive; working in the active/standby model;
There is usually only one HA Service: HA resources are possible There will be multiple;
A/A: Two-node cluster, active/active, Working in a two-party model;
NM: N nodes, M services; usually N>M;
NN: N nodes, N services;

The tendency of resource operation:< br> rgmanager:
failover domain, node priority
pacemaker:
Resource stickiness: tendency to run on the current node; resource constraints:
Resource constraints: the tendency
inf: positive infinity
-inf: negative infinity
n:
-n:
arrangement constraint: the resources to run tendency of a
inf
-inf
C
C
C p> DC: Designated Coordinator

corosync:
AIS: Application Interface Standard,

SA Forum: OpenAIS

OpenAIS: Provides a cluster model , Including cluster framework, cluster member management, communication methods, cluster monitoring, but no cluster resource management function;

Components include: AMF, CLM, CPKT, EVT, etc.; different branches have slightly different components ;

Branches: picacho, whitetank, wilson,
corosyn c (Cluster Management Engine)
Cent is just a sub-component of openais;

Split into two projects:
Coro sync, wilson(ais 5) interface standards : CentOS 6:
Cman + rgmanager
CentOS 6:
Cman + rgmanager
Cman + rgmanager
Cman + rgmanager
6.4 Cman + rgmanager
Manage: corosync + pacemaker

Manage pcs: RedHat, CentOS 6.5+

Commonly used crm sub-commands:
status
node
configure
p
p subcommand:
primitive
group
clone
ms
location
colocation
order
show
property

primitive class:provider:ra params param1=value1 param2=value2 op op1 param1=value op op2 parma1=value1

Second test heartbeat+httpd

Basic environment Settings10.10.10.50/24 node1.test.com node1
10.10.10.51/24 node2.test.com node2

10.10.10.5/24 vip

Turn off iptables

service iptables stopchkconfig iptables off

Turn off selinx

vim /etc/selinux/configSELINUX=disabled

Modify the host name

vim/ etc/sysconfig/networkHOSTNAME=node2.test.comvim /etc/hosts10.10.10.50 node1.test.com node110.10.10.51 node2.test.com node2reboot
[root@node1~]# uname-nnode1.test.com[root@node2~]# uname-nnode2.test.com

Install httpd

yuminstall httpd[root@node1~]#vim/var/www/html/index.htmlnode1.test.com 10.10.10.50[root@node2~]#vim/var/ www/html/index.htmlnode2.test.com 10.10.10.51service httpd start

Open the test http://10.10.10.50

http://10.10.10.51

service httpd stop

Prepare ssh trust (no need to enter the account password to enter the system)

 cd ~ssh-keygen -t rsassh-copy-id localhostssh node2 cat ~/.ssh/id_rsa.pub >>.ssh/authorized_keys scp.ssh/authorized_keys node2:~/.ssh/


Install heartbeat
Set epel source libnet in epel

wget http://mirrors.aliyun.com/epel/6/x86_64/ epel-release-6-8.noarch.rpmrpm -ivh epel-release-6-8.noarch.rpmyum install net-snmp-libs libnet PyXML libtool-ltdl 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

Configure heartbeat

cd/etc/ha.d/cp-r/usr/share/doc/heartbeat-2.1.4//etc/ha.d/cp./heartbeat-2.1.4 /{ha.cf,authkeys,haresources}./chmod 600 authkeys
vim authkeysauth 2#1crc2sha1password#3md5Hello!
vim ha.cfdebugfile /var/l og/ha-debug#logfacility local0keepalive 2deadtime 30warntime 10udpport 694mcast eth0 225.10.0.1 694 1 0auto_failback onnode bash node1.test.comnode bash node2.test.comping 10.10.2compression prereshold 2;preres: :false">vim haresourcesnode1.test.com 10.10.10.5/24/eth0/10.10.10.254 httpd
scp-p ha.cf haresources authkeys node2: /etc/ha.d/service heartbeat start;ssh node2 service heartbeat start

View real-time generated logs

tail -f/ var/log/ha-debug

Check the running status, all resources are on node1, and only the heartbeat service on node2

[root@ node1 ha.d]# ifconfigeth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr: 10.10.10.50 Bcast: 10.10. :ae0d/64 Scope: Link UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric:1 RX packets:1469 errors:0 dropped:0over runs:0 frame:0 TX packets:1324 errors:0dropped:0overruns:0 carrier:0collisions:0 txqueuelen:1000RXbytes:178040(173.8KiB)TXbytes:235KiB Ethernet HWaddr 00:0C:29:9F:AE:0D ineet addr:10.10.10.5 Bcast: 10.10. Mask: 255.0.0.0 inet6 addr::: 1/128 Scope: Host RUNNING MTU: 65536 Metric:1 RX packets: 61 errors: 0 dropped:0 overruns: 0 frame: 0 61 0 overruns:0 carrier:0collisions:0txqueuelen:0 RXbytes:12332(12.0KiB)TX TXbytes:12332(12.0KiB)[[email protected]#cpnetstat-nlptu:0|grep80:0 :::* LISTEN LISTEN 3056/httpd [root@node1 ha.d]# ps aux |grep httproot 0.3 175276 3736: 00 s 0:00 /usr/sbin/httpdapache 3060 0.0 0.2 175276 2460 S 20:00 0:00 /usr/sbin/httpdapache 0 0 0 2 175276 s 0306/ 0 0 0 2 175276 2 0 s 3061/ 0 0 2 175276 2 0 s 175276 2444 S 276: 20:00 0:00/usr/sbin/httpdapache 3063 0.0 0.2175276 2444 S 175 20:00 444 0:00/usr/sbin 0:00/usr/sbin 0:00 0:00/usr/sbin/httpd64 / sbin / httpdapache 3065 0.0 0.2 175276 2444? S 20:00 0:00 / usr / sbin / httpdapache 3066 0.0 0.2 175276 2444? S 20:00 0:00 / usr / sbin / httpdapache 3067 0.0 0.2 175276 2444? S 20 :00 0:00 /usr/sbin/httpdroot SL 3111 0.0 0.0 103304 896 pts/0 0:00 grep http[root@node1 ha.d]# ps aux 65 348 2 heartbeat root 1.4 19:59 0:00 heartbeat: master control processnobody 2666 0.0 0.7 58764 SL 7616 19:59 0:00 heartbeat: FIFO reader nobody 2667 0 .0 0.7 58892 7744 SL 19:59 0:00 heartbeat:? Write: mcast eth0 nobody 2668 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat:? Read:? Mcast eth0 nobody 2669 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat: write: ping 10.10. heartbeat[[email protected]]# ifconfigeth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 inet addr:10.10.10.51 Bcast:10.10.1addr:0.255 Mask:255. :29ff:fe05:71e9/64 Scope: Link: 0 UP BROADCAST RUNNING MULTICAST MTU: 1500 RX Packets: 22144 errors:0 dropped:0 overruns:0 frame:0 dropovers:0 16drops:0 634 dropovers: 0 carrier: 0 collisions:0 txqueuelen: 1000 RX bytes: 24037006 (22.9 MiB) TX bytes: 7355584 (7.0 MiB) lo Link encap: Local Loopback inet addr: 127.0.0.1 Mask: 255.0.0.0 inet6 addr::: 1/128 Scope: Host RUNNING MTU: 65536 Metric: 1 packet: 0 ped 0 RX overpackets: 61 error: 0 61 errors:0dropped:0overruns:0carrier:0collisions:0txqueuelen:0RXbytes:26550(25.9KiB)TXbytes:26550(25.9KiB)[root@node2|grep-n80|ha.d]#tunet80 [root@node2 ha.d]# ps aux |grep httproot 2823 0.0 0.0 103308 S+ 20:02 0:00 grep http[root@node2 ha.d]# ps aux aux 2 496 heartbeat 141.4651.4 ? SLs 19:59 0:00 heartbeat: master control processnobody 2738 0.0 0.7 58764 7616 SL 19:59 0:00 heartbeat:? FIFO reader nobody 2739 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat:? write: mcast eth0 nobody 2740 0.0 0.7 58892 SL 19:59 0:00 heartbeat: read: mcast eth0 nobody 0.0 0.7 58892 7774: 59 0 heartbeat: write: ping 10.10. pre> 

Open the webpage http://10.10.10.5

wKiom1YsoNjymWesAACCVn04Vds870.jpg

Stop the first node

[[email protected]]# service heartbeat stopStopping High-Availability services: Done.

Node1 node servers are all stopped, all services are transferred to node2

[root@node2 ha.d]# ifconfig eth0 Link encap:Ethernet HWaddr 00:0C:29:05:71:E9 addr: 10.10.10.51: fe 6fe: 255.255. Addr: 10.10. :71e9/64 Scope: Link UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1 RX packets: 22411 errors: 0 dropped:0 overruns:0 frame:0 TX packets: 16943 errors:0 dropped:0 overruns:0 carrier:0 852: tcollisions:0 852: tcollisions:0 22.9 MiB TX bytes: 7416808 (7.0 MiB) eth0:0 Link encap: Ethernet HWaddr 00:0C:29:05:71:E9 inet addr: 10.10.10.5 ASTRO Bcast: 10.10. MTU: 1500 Metric: 1lo RX Link encap: Local Loopback: 0 Inet addr: 127.0.0.1 Mask: 255.0.0.0 Addr: inet6 addr: BACK: 1/128 Scope: OP 36 BACK Mdrop: OP 36 BACK: OP 36 drop: UP :0 overruns:0 frame:0 TX packets:61 errors:0dropped:0overruns:0 carrier:0 txqueuelen:0 RXbytes:26550(25.950KiB)26550(25.950KiB) 26550(25.950KiB) ha.d]#netstat -nlptu|grep 80tcp 0:::80 …:::: LIST 139 [root] @node2 ha.d]# ps aux |grep http 3139 0.0 0.3 175276 3736 Ss 20:05 0:00/usr/sbin/ 0:00/usr/sbin/ 0:00/usr/sbin/ 0:00/s 0/ 175/ 0 175/ 24 60 3141 httpdapache 3143 0.0 0.2 175276 2444? S 20:05 0:00 / usr / sbin / httpdapache 3145 0.0 0.2 175276 2444? S 20:05 0:00 / usr / sbin / httpdapache 3146 0.0 0.2 175276 2444? S 20:05 0 :00 /usr/sbin/httpdapache 3149 0.0 0.2 175276 2444 S 20:05 0:00 /usr/sbin/httpdapache 175 276 sbin/httpdapache 175 276 2444/20: 0:00/usr/sbin/httpdapache 175 276 2s 0 175 276 2s 0 175 276 2 0 175 276 2s 2444 S 20:05 0:00 /usr/sbin/httpdapache 3157 0.0 0.2 175276 2444 20:05 0: 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0/usr/sbin/usr/sbin/usr/sbin/httpdroot http[[email protected]]# ps aux|grep heartbeatroot 2733 0.0 1.4 65496 14348 SLs 19:59 0:00 heartbeat: master control processnobody 2738 0.0 ? 0.7 58764 7616 SL 19:59 0:00 heartbeat: FIFO reader nobody 2739 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat:? Write:? Mcast eth0 nobody 2740 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat : Read: mcast eth0 nobody SL 2741 0.0 0.7 58892 7744 SL 19:59 0:00 heartbeat: write: ping 10.10.1 0.2 nobody: 0 ping 10.1 0. 3170 0.0 0.0 103308 852 pts/0 S+ 20:06 0:00 grep heartbeat

Open the webpage http://10.10.10.5

wKiom1YsoP-QkXGrAACDm_MKk0U599.jpg

Restart node1

[[email protected]]# ifconfigeth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr: 10.10.10.50 Bcast: 10.10.10.255 Mask: 255.255.255.0 inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope: Link: AST 1500 Metric: AST UPMULTIC: 1457 MULTICpack: BROADCAST error: RUNNING MULT: 0 dropped: 0 overruns: 0 frame: 0 TX packets: 2066 errors: 0 dropped: 0 overruns: 0 carrier: 0 collisions:0 txqueuelen: 1000 RX bytes: 299678 (292.6KiB) bytes: 299678(292.6KiB) 0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D Inet addr:10.10.10.5Bcast:10.10.10.254HWaddr00:0C:29:9F:AE:0D :127.0.0.1 Mask: 255.0.0.0 inet6 addr:::1/128 Scope: Host LOOPBACK RUNNING MTU: 65536 Metric:1 RX packets: 61 overpacks:0 runpacks: 61 errors:0run :0 dropped:0 overruns:0 carrier:0 collisions:0 txqueuelen:0 RX bytes:12332(12.0KiB)TX bytes:12332(12.0KiB)[roo t@node1 ha.d]# ifconfigeth0 Link encap:Ethernet HWaddr 00:0C:29:9F:AE:0D inet addr: 10.10.10.50 Bcast: 10.10.10.50 Bcast: 10.10.10.50 Bcast: 10.10.10.50 fe: 0.25 fe: 255.255. :fe9f:ae0d/64 Scope: Link: 0 UP BROADCAST RUNNING MULTICAST MTU: 1500 RX packets: 2465 errors: 0 dropped:0 overruns:0 frame:0 1drops: 0 207 droppacks: 0 0 Collisions:0 txqueuelen: 1000 RX bytes: 300586 (293.5 KiB) TX bytes: 367585 (358.9 KiB) eth0:0 Txqueuelen: 1000 RX bytes: 300586 (293.5 KiB) TX bytes: 367585 (358.9 KiB) eth0:0 Linkcast: Ethernet:00.5 HWaddr 00:0C: 29: 9D 10.10.10.254 Mask: 255.255.255.0 UP BROADCAST RUNNING MULTICAST MTU: 1500 Metric: 1lo Link encap: Local Loopback inet addr: 127.0.0.1 Mask: 255.0.0.0 inet6 addr: :: 1/128 Scope: Host UP LOOPBACK RUNNING MTU: 65536 Metric:1 RX packets: 61 errors:0 dropped:0 overruns:0 frame:0 TX packets:61 errors:0 dropped:0 overruns:0 carriers:0 col lisions: 0 txqueuelen: 0 RX bytes: 12332 (12.0 KiB) TX bytes: 12332 (12.0 KiB) [root @ node1 ha.d] # netstat -nlptu | grep 80 tcp 0 0 ::: 80 ::: * LISTEN 3693 /httpd [root@node1 ha.d]# ps aux |grep http 3693 0.0 0.3 175276 Ss 20:07 0:00 0:00/usr/sbin 0:00/usr/sbin 0:00/usr/sbin 0:00 usr / sbin / httpdapache 3696 0.0 0.2 175276 2444? S 20:07 0:00 / usr / sbin / httpdapache 3698 0.0 0.2 175276 2444? S 20:07 0:00 / usr / sbin / httpdapache 3700 0.0 0.2 175276 2444? S 20:07 0:00 /usr/sbin/httpdapache 3701 0.0 0.2 175276 S 2444 20:07 0:00/usr/sbin/httpdapache 0:00/usr/sbin/httpdapache/usr/sbin/httpdapache/s: 00/usr/sbin/httpdapache 2 444 20.0 0 0.2 175276 3703 0.0 0.2 175276 2444 S 20:07 0:00 /usr/sbin/httpdapache 3704 0.0 0.2 175276 2444 S/s 20:07/us 0:00 /httpdroot 3713 0.0 0.0 103304 896 pts/0 S+ 20:07 0:00 grep http[root@node1 ha.d]# ps aux |grep heartbeat root: heart master 20 07405 3348 0.0 496 14 control processnobody 3410 0.0 0.7 58764 7616 SL 20:07 0:00 heartbeat:? FIFO reader nobody 3411 0.0 0.7 58892 7744 SL 20:07 0:00 heartbeat:? write:? mcast eth0 nobody 3412 0.0 0.7 58892 7744 SL 20:07 0:00 heartbeat: read: mcast eth0 nobodySL 3413 0.0 0.7 58892 SL 7744 20:07 0:00 heartbeat: 00 write: ping 10.10. 10.10.10.2 root 3715 0.0 0.0 103308 896 pts/0 S+ 20:07 0:00 grep heartbeat

All resources are transferred to node1

Three tests heartbeat+httpd +nfs

Open a new server, the version is cenos 7.1 ip address is 10.10.10.60
Close iptables

 systemctl stop firewalld systemctl disable fire walld

Close selinx

vim /etc/selinux/configSELINUX=disabled

Install nfs< br>

m install nfs*

Create nfs shared file directories and files

mkdir -p /home/data/htmlvim /home/data/html/index.htmlhtml on nfs server 10.10.10.60

Configure nfs

vim /etc/exports/home/data 10.10.10.0/24(rw,no_root_squash)exportfs-arv

Start nfs

systemctl start nfs-server systemctl status nfs-server

Manually mount and test on node1 node2

[[email protected]]#mount-t nfs 10.10.10.60:/home/data/html/var/www/html[[email protected]]#cat/var/www/html/index. html html on nfs server 10.10.10.60[[email protected]]#umount/var/www/html
[[email protected]] #Mount -t nfs 10.10.10.60:/home/data/html /var/www/html[[email protected]]#cat /var/www/html/ index.htmlhtml on nfs server 10.10.10.60[root@node2/]# umount/var/www/html

Modify heartbeat settings

[[email protected]]#vim haresourcesnode1.test.com 10.10.10.5/24 Filesystem::10.10.10.60:/home/data/html::/var/www/html::nfs httpd< /pre> 

Copy to node2 and start the service

scp haresources node2:/etc/ha.d/service heartbeat start;ssh node2 service heartbeat start 

node1 node check

[[email protected]]# ifconfigeth0 Link encap:Ethernet HWaddr 00:0C: 29:9F:AE:0D inet addr: 10.10.10.50 Bcast: 10.10.10.50 Bcast: 10.10. 1          RX packets:4330 errors:0 dropped:0 overruns:0 frame:0          TX packets:3581 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:561109 (547.9 KiB)  TX bytes: 658645 ( 643.2 KiB)eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:9F:AE:0D            inet addr:10.10.10.5  Bcast:10.10.10.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:61 errors:0 dropped:0 overruns:0 frame:0          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:12332 (12.0 KiB)  TX bytes:12332 (12.0 KiB)[root@node1 ha.d]# netstat -nlptu|grep 80tcp        0      0 :::80                       :::*                        LISTEN      4808/httpd          [root@node1 ha.d]# ps aux |grep httproot       4808  0.0  0.3 175276  3736 ?        Ss   20:24   0:00 /usr/sbin/httpdapache     4810  0.0  0.2 175276  2460 ?        S    20:24   0:00 /usr/sbin/httpdapache     4811  0.0  0.2 175276  2444 ?        S    20:24   0 :00 /usr/sbin/httpdapache     4814  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdapache     4815  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdapache     4816  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdapache     4817  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdapache     4818  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdapache     4819  0.0  0.2 175276  2444 ?        S    20:24   0:00 /usr/sbin/httpdroot       4826  0.0  0.0 103304   896 pts/0    S+   20:25   0:00 grep http[root@node1 ha.d]# ps aux |grep heartbeatroot       4272  0.0  1.4  65496 14348 ?        SLs  20:24   0:00 heartbeat: master control processnobody     4278  0.0  0.7  58764  7616 ?        SL   20:24   0:00 heartbeat: FIFO reader        nobody     4279  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: mcast eth0  nobody     4280  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: mcast eth0   nobody     4281  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: ping 10.10.10.2nobody     4282  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: ping 10.10.10.2root       4828  0.0  0.0 103304   896 pts/0    S+   20:25   0:00 grep heartbeatnode2节点[root@node2 /]# ifconfigeth0      Link encap:Ethernet  HWaddr 00:0C:29:05:71:E9            inet addr:10.10.10.51  Bcast:10.10.10.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:23901 errors:0 dropped:0 overruns:0 frame:0          TX packets:18324 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:24337685 (23.2 MiB)  TX bytes:7683518 (7.3 MiB)lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:61 error s:0 dropped:0 overruns:0 frame:0          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:26550 (25.9 KiB)  TX bytes:26550 (25.9 KiB)[root@node2 /]# netstat -nlptu|grep 80[root@node2 /]# ps aux |grep httproot       3735  0.0  0.0 103308   852 pts/0    S+   20:26   0:00 grep http[root@node2 /]# ps aux |grep heartbeat root       3684  0.0  1.4  65496 14348 ?        SLs  20:24   0:00 heartbeat: master control processnobody     3689  0.0  0.7  58764  7616 ?        SL   20:24   0:00 heartbeat: FIFO reader        nobody     3690  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: mcast eth0  nobody     3691  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: mcast eth0   nobody     3692  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: ping 10.10.10.2nobody     3693  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: ping 10.10.10.2root       3739  0.0  0.0 103308   852 pts/0    S+   20:27   0:00 grep heartbeat

打开网页 http://10.10.10.5 

wKiom1YsofCjzSzmAAB_7YgkQR8509.jpg

停止第一个节点

[root@node1 ha.d]# service heartbeat stopStopping High-Availability services: Done.

node1节点服务器全部停止 ,所有服务转移到node2

[root@node2 /]# ifconfig              eth0      Link encap:Ethernet  HWaddr 00:0C:29:05:71:E9            inet addr:10.10.10.51  Bcast:10.10.10.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe05:71e9/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:24306 errors:0 dropped:0 overruns:0 frame:0          TX packets:18704 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:24389056 (23.2 MiB)  TX bytes:7747299 (7.3 MiB)eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:05:71:E9            inet addr:10.10.10.5  Bcast:10.10.10.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:61 errors:0 dropped:0 overruns:0 frame:0          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:26550 (25.9 KiB)  TX bytes:26550 (25.9 KiB)[root@node2 /]# netstat -nlptu|grep 80tcp        0      0 :::80                       :::*                        LISTEN      4197/httpd          [root@node2 /]# ps aux |grep http     root       4197  0.0  0.3 175276  3728 ?        Ss   20:27   0:00 /usr/sbin/httpdapache     4199  0.0  0.2 175276  2460 ?        S    20:27   0:00 /usr/sbin/httpdapache     4202  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4203  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4205  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4207  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4210  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4214  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdapache     4217  0.0  0.2 175276  2444 ?        S    20:27   0:00 /usr/sbin/httpdroot       4224  0.0  0.0 103308   856 pts/0    S+   20:28   0:00 grep http[root@node2 /]# ps aux |grep heartbeatroot       3684  0.0  1.4  65496 14348 ?        SLs  20:24   0:00 heartbeat: master control processnobody     3689  0.0  0.7  58764  7616 ?        SL   20:24   0:00 heartbeat: FIFO reader        nobody     3690  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: mcast eth0  nobody     3691  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: mcast eth0   nobody     3692  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: write: ping 10.10.10.2nobody     3693  0.0  0.7  58892  7744 ?        SL   20:24   0:00 heartbeat: read: ping 10.10.10.2root       4226  0.0  0.0 103308   856 pts/0    S+   20:28   0:00 grep heartbeat

刷新网页 http://10.10.10.5  

wKioL1YsomTi1gINAAB_7YgkQR8748.jpg

重新开启node1

[root@node1 ha.d]# ifconfig               eth0      Link encap:Ethernet  HWaddr 00:0C:29:9F:AE:0D            inet addr:10.10.10.50  Bcast:10.10.10.255  Mask:255.255.255.0          inet6 addr: fe80::20c:29ff:fe9f:ae0d/64 Scope:Link          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1          RX packets:5051 errors:0 dropped:0 overruns:0 frame:0          TX packets:4184 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:1000           RX bytes:656248 (640.8 KiB)  TX bytes:765685 (747.7 KiB)eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:9F:AE:0D            inet addr:10.10.10.5  Bcast:10.10.10.255  Mask:255.255.255.0          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1lo        Link encap:Local Loopback            inet addr:127.0.0.1  Mask:255.0.0.0          inet6 addr: ::1/128 Scope:Host          UP LOOPBACK RUNNING  MTU:65536  Metric:1          RX packets:61 errors:0 dropped:0 overruns:0 frame:0          TX packets:61 errors:0 dropped:0 overruns:0 carrier:0          collisions:0 txqueuelen:0           RX bytes:12332 (12.0 KiB)  TX bytes:12332 (12.0 KiB)[root@node1 ha.d]# netstat -nlptu|grep 80 tcp        0      0 :::80                       :::*                        LISTEN      5614/httpd          [root@node1 ha.d]# ps aux |grep http      root       5614  0.0  0.3 175276  3724 ?        Ss   20:29   0:00 /usr/sbin/httpdapache     5616  0.0  0.2 175276  2456 ?        S    20:29   0:00 /usr/sbin/httpdapache     5617  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5619  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5621  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5622  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5623  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5624  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdapache     5625  0.0  0.2 175276  2440 ?        S    20:29   0:00 /usr/sbin/httpdroot       5632  0.0  0.0 103304   896 pts/0    S+   20:29   0:00 grep http[root@node1 ha.d]# ps aux |grep heartbeat root       5185  0.0  1.4  65496 14348 ?        SLs  20:29   0:00 heartbeat: master control processnobody     5188  0.0  0.7  5876 4  7616 ?        SL   20:29   0:00 heartbeat: FIFO reader        nobody     5189  0.0  0.7  58892  7744 ?        SL   20:29   0:00 heartbeat: write: mcast eth0  nobody     5190  0.0  0.7  58892  7744 ?        SL   20:29   0:00 heartbeat: read: mcast eth0   nobody     5191  0.0  0.7  58892  7744 ?        SL   20:29   0:00 heartbeat: write: ping 10.10.10.2nobody     5192  0.0  0.7  58892  7744 ?        SL   20:29   0:00 heartbeat: read: ping 10.10.10.2root       5634  0.0  0.0 103304   896 pts/0    S+   20:29   0:00 grep heartbeat

所有资源又全部转移到node1

四 测试heartbeat CRM LAMP WordPress

安装mysql 和php

m install mysql-server php  php-mysql

测试php

[root@node1 ha.d]# vim /var/www/html/info.php [root@node1 ha.d]# service httpd start

打开http://10.10.10.50/info.php 测试PHP 信息

[root@node1 ha.d]# service httpd stop< /pre> 

测试mysql

[root@node1 ha.d]# service mysqld start[root@node1 ha.d]# mysqlmysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               |+--------------------+3 rows in set (0.00 sec)mysql> exitBye[root@node1 ha.d]# service mysqld stop

设置mysql data on nfs
在nfs 服务器  

mkdir /home/data/mysql

在节点1

mkdir /datavim /etc/my.cnf[mysqld]datadir=/data/mount -t nfs 10.10.10.60:/home/data/mysql /data/usr/bin/mysql_install_db --user=mysql --datadir=/data/[root@node1 ha.d]# service mysqld start[root@node1 ha.d]# mysqlmysql> create database wordpress;Query OK, 1 row affected (0.00 sec)mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               || wordpress          |+--------------------+4 rows in set (0.01 sec)mysql> exitBye[root@node1 ha.d]# service mysqld stop[root@node1 ha.d]# umount /data

在节点2

[root@node2 /]# mkdir /data[root@node2 /]# vim /etc/my.cnf [mysqld]datadir=/data/[root@node2 /]# mount -t nfs 10.10.10.60:/home/data/mysql /data[root@node2 /]# /usr/bin/mysql_install_db --user=mysql --datadir=/data/[root@node2 /]#  service mysqld start[root@node2 /]# mysqlmysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || mysql              || test               || wordpress          |+--------------------+4 rows in set (0.00 sec)mysql> exitBye[root@node2 /]# service mysqld stop[root@node2 /]# umount /data

安装 heartbeat-gui

yum install pygtk2-libglade xorg-x11-xauth  rpm -ivh heartbeat-gui-2.1.4-12.el6.x86_64.rpm
echo "password" | passwd --std in hacluster
yum install xorg-x11-xauth    #如果未安装图型系统,要安装此组件,要不xshell报错vim /etc/ha.d/ha.cf crm onservice heartbeat start;ssh node2 service heartbeat start

在xshell 执行

hb_gui&

连接127.0.0.1 安装gui默认生成hacluster 用户, 默认无密码

请使用echo "password" | passwd --stdin hacluster 创建密码

wKiom1YsoxziPK_vAAG1Dese07Q332.jpg

连接成功后如图显示

wKioL1Yso1Gze6EWAAKZHObjP-8602.jpg

开始添加资源 ,些次添加资源组 名为wordp ress

wKioL1Yso1WA6w8AAAJpcTfpwKw005.jpg

添加第一个资源名为 ha_ip

类型为IPaddr  参数为  ip  10.10.10.5

wKiom1YsoyfCSILOAAQaKD0P0tA867.jpg

wKiom1YsoyqiGShhAAIk0hGXwNw067.jpg

添加第二个资源名为ha_nfs_mysql ,和我们之前测试时使用的参数一至,为mysql的共享存储

类型为Fi lesystem

参数为  device      10.10.10.60:/home/data/mysql

            directory   /data

            fstype        nfs

wKioL1Yso17yIBRiAARvpsiH7pQ984.jpg

添加第三个资源名为ha_nfs_httpd ,和我们之前测试时使用的参数一至,为httpd的共享存储

类型为Filesystem

参数为  device      10.10.10.60:/home/data/html

            directory   /var/www/html

            fstype        nfs

wKioL1Yso2LiIBaZAARvaIyiVr8613.jpg

添加第四个资源名为ha_mysql

类型为我们安装的mysqld ,不需要参数

wKiom1YsozfCG7MVAAQEVpUbnLw372.jpg

添加第五个资源名为ha_httpd

类型为我们安装的httpd ,不需要参数

wKioL1Yso2ri9PPCAAQ-PoG5mnI153.jpg

 

添加主机colocations ,为资源起动所有的位置

第一个为,ha_ip  ha_nfs_mysql 必须在同一个node上

wKiom1Ysoz3AF8SXAAQtBOHztsI613.jpg

第一个为,ha_i p  ha_nfs_httpd 必须在同一个node上

wKiom1Yso0LwQQDeAAQg6v5yRSQ728.jpg

第一个为,ha_mysql  ha_nfs_mysql 必须在同一个node上

wKioL1Yso3bgQ1FFAAQ2QqZ4r_w649.jpg

第一个为,ha_httpd  ha_nfs_httpd 必须在同一个node上

wKiom1Yso0zxY1QzAARRt1jSgag706.jpg

以上设置保证所有资源启动在同一个node上,根据需要修改。

 

添加资源order,意为资源的启动顺序

第一个为, ha_ip 比ha_nfs_mysql先启动

如果不能启动ha_ip ,则不启动ha_nfs_mysql

停止时,先停止ha_nfs_mysql ,后停止ha_ip

如果不能停止ha_nfs_mysql,则不停止ha_ip

wKioL1Yso4PjvHfNAAQndpj25o0458.jpg

第二个为, ha_ip 比ha_nfs_httpd先启动

如果不能启动ha_ip ,则不启动ha_nfs_httpd

停止时,先停止ha_nfs_httpd ,后停止ha_ip

如果不能停止ha_nfs_httpd,则不停止ha_ip

wKiom1Yso1qC6cy7AAQFxMY6NAs185.jpg

第三个为, ha_nfs_mysql 比ha_mysql先启动

如果不能启动ha_nfs_mysql ,则不启动ha_mysql

停止时,先停止ha _mysql ,后停止ha_nfs_mysql

如果不能停止ha_mysql,则不停止ha_nfs_mysql

 

wKiom1Yso1-SsAM5AAREJ6BdY-E178.jpg

第四个为, ha_nfs_httpd 比ha_httpd先启动

如果不能启动ha_nfs_httpd ,则不启动ha_httpd

停止时,先停止ha_httpd,后停止ha_nfs_httpd

如果不能停止ha_httpd,则不停止ha_nfs_httpd

wKioL1Yso5byjxfXAAQqzJw8jaA468.jpg

右键ha_wordpress ,start 启动ha_wordpress资源

以上配置启动顺序为   ha_ip --> ha_nfs_mysql --> ha_mysql

                                  ha_ip --> ha_nfs_httpd--> ha_httpd

wKiom1Yso2qi74xjAANvdP-Zk1w833.jpg

wKioL1Yso52j1VozAAOXNQybBvU544.jpg

右键节点node2 standby

wKiom1Yso3HSq1HRAAOhYyT1uLo785.jpg

资源全部转移动node1

wKioL1Yso6iQ 7f0lAAOqPxmcIVM717.jpg

 

安装wordpress

wget  https://cn.wordpress.org/wordpress-4.3.1-zh_CN.zip
unzip wordpress-4.3.1-zh_CN.zip
cp -rf  wordpress/ /var/www/html/
http://10.10.10.5/wordpress/wp-admin/setup-config.php

wKiom1Ysp-qQaPlHAALhjCQT9F4273.jpg

wKioL1YsqB7DM1q9AAI1S0gY4uY534.jpg

wKiom1Ysp-_zV5ooAAM9bVTaDz0507.jpg

如果没有设置权限 ,

cd /var/www/html/
vim wp-config.php

复制上图中生成的代码,然后点击进行安装。

wKioL1YsqCDydrbvAAJkqo0TxcI291.jpg

wKiom1Ysp_LjhICLAAFpSo-n7Ug547.jpg

wKioL1YsqCfRL9_hAANKK9ZqbWs458.jpg

发表一个博客

wKiom1Ysp_ngqq80AAHYSk2k ANc849.jpg

设置node2 为 standby

wKioL1YsqDCwoDjWAAOiaNfR-h4189.jpg

 

wKiom1YsqAei5EZtAAOLGbaA4Vs223.jpg

 

结果刷新后发表的内容也可以显示

Leave a Comment

Your email address will not be published.