L8 HeartBeat V2 Constructing WordPress using CRM

One, elaborate The background of Linux HA Cluster;

HA Introduction

1. Definition of high-availability cluster
High-availability cluster, the original English is High Availability Cluster, Referred to as HACluster, to put it simply, a cluster is a group of computers that provide users with a set of network resources as a whole. These individual computer systems are the nodes of the cluster.
The emergence of high-availability clusters is to make the overall services of the cluster as available as possible, thereby reducing the loss caused by the error-proneness of computer hardware and software. If a node fails, its backup node will take over its responsibilities within a few seconds. Therefore, for users, the cluster will never be down.
The main function of high-availability cluster software is to automate fault checking and business switching. A high-availability cluster with only two nodes is also called dual-system hot standby, that is, two servers are used to back up each other. When one server fails, another server can take on the service task, so that the system can automatically ensure that the system can continue to provide services without manual intervention. Dual-system hot backup is only one type of high-availability cluster. The high-availability cluster system can support more than two nodes, provide more and more advanced functions than dual-system hot backup, and better meet the changing needs of users.
2. Measurement criteria for high-availability clusters
HA (High Available), high-availability clusters are measured by the reliability and maintainability of the system. In engineering, the mean time between failures (MTTF) is usually used to measure the reliability of the system, and the mean time to repair (MTTR) is used to measure the maintainability of the system. Therefore, the availability is defined as: HA=MTTF/(MTTF+MTTR)*100%
Specific HA measurement standard:
99% The downtime of a year does not exceed 4 days

99.9% of downtime is no more than 10 hours a year

99.99% a year of downtime for no more than 1 hour

99.999% of downtime is no more than 6 minutes a year

Second, summarize the system composition of Linux HA Cluster and the working model of HA Cluster;

1, HA Cluster system composition

Messaging Layer: realize heartbeat information transmission, cluster transaction messaging;

heartbeat

v1, v2, v3

corosync

cman (RedHat, RHCS)

keepalived (completely different from the above three)

< br>

CRM: Cluster Explorer;

< span style="font-family:'Microsoft YaHei','Microsoft YaHei';"> heartbeat v1 haresources (configuration interface: configuration file, the file name is haresources)

heartbeat v2 crm (run a crmd process on each node, configuration interface: command line client program crmsh, GUI client: hb_gui);

heartbeat v3, pacemaker (pacemaker can be run as a plug-in or standalone; configuration interface, CLI interface :Crmsh, pcs; GUI: hawk(webgui), LCMC, pacemaker-mgmt);

rgmanager (configuration interface, CLI: clust, cman_tool; GUI: Conga(luci+ricci))

Combination method:

heartbeat v1, comes with haresources (v2 version of crm)

heartbeat v2, comes with crm management (graphic tool hb_gui installation package)

heartbeat v3 + pacemaker

corosync + pacemaker

cman + rgmanager (RHCS)

cman + pacemaker

LRM: Local Resource Manager, provided by CRM through subprograms;

RA: Resouce Agent resource agent

heartbeat legacy: heartbeat legacy RA, usually located in the /etc/ha.d/haresources.d/ directory;

LSB: Linux Standard Base, the script in the /etc/rc.d/init.d directory, accepts at least 4 parameters: {start|stop|restart |status};

OCF: Open Cluster Framework

Subcategory: provider

STONITH: A resource dedicated to the function of calling STONITH equipment; usually a clone type;

Messaging Layer notice, CRM command LRM, LRM uses RA to complete resource management

One ​​of our DCs decided that high availability services should be enabled on a certain node. This DC’s CRM (the dominant role CRM through the election) is reported to the Messaging Layer of another node through the Messaging Layer. This Messaging Layer is then passed to the CRM, and the CRM instructs LRM to complete resource management through RA.

Overview of some important concepts:

Usually we need to limit multiple resources through constraints: web services, we need, webip, webserver services are on the same host, we need to start webip first, then start webserver, close It is also necessary to close the webserver first and then close the webip. The following resource constraints will be used here

vote system: voting system

< p> When the nodes in HA cannot detect each other’s heartbeat information, they must not be able to coordinate their work; this state is a partitioned cluster;

The principle that the minority obey the majority: quorum

with quorum> total/2

without quorum <= total/2

Arbitration equipment:

quorum disk = qdisk

ping node

< p>

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: It must be completed with the help of CRM Realize HA function on HA cluster;

Resource constraint relationship:

location: location constraint, which defines the tendency of the resource to the node; expressed in numerical value, -oo, +oo; when it is -oo At the time, it means that it will not run on this node anyway.

colocation: arrangement constraints, defining the tendency of resources to “be together” with each other ;-Oo, +oo; For example, webip and webserver must be on the same host, webserver is started and shut down according to webip.

resources group grouping: It can also bind multiple resources together ;

order: order constraint, defines when resources are started on the same node The order of precedence; for example, webip first, then webserver.

Resource type:

< span style="color:rgb(0,176,240);"> primitive: the primary resource, which can only run on a single node in the cluster; (also called native);

group: group resources, containers, containing one or more resources, these resources can be uniformly scheduled through the “group” resource;

< span style="color:rgb(0,176,240);"> clone: ​​clone resource, 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;

< br>

Resource isolation:

Level

Node: STONITH (Shooting The Other Node In The Head)

power switch

Resource: fencing p>

FC SAN switch

2, HA Cluster working model

Model classification of high-availability clusters
1. Hot standby (Active /Passive)
Official description: Two-node Active/Passive clusters using Pacemaker and DRBD are a cost-effective solution for many High Availability situations.

2. Multi-node hot backup (N+1)
Official note: By supporting many nodes, Pacemaker can dramatically reduce hardware costs by allowing several active/passive clusters to be combined and share a common backup node.
< /p>


3. Multi-node shared storage (N-TO-N)
< /p>

Official instructions: When shared storage is available, every node can potentially be used for failover. Pacemaker can even run multiple copies of services to spread out the workload.

4. Shared storage hot backup (Split Site)

Official description: Pacemaker 1.2 will include enhancements t o simplify the creation of split-site clusters.

Three,through LAMP combination, based on heartbeat v2 crm to achieve HA; requirements, deploymentwordpress,any data in the article for editing is switched in the node Can be accessed normally afterwards;

Node: 192.168.0.190 node1

Node: 192.168.0.201 node2

NFS server and arbitration device: 192.168.0.202 node4 p>

Premise:

< span style="font-family:'Microsoft YaHei','Microsoft YaHei';">1, time synchronization

2, the host file can resolve the host name

3 , Ssh, root without verification

4, do you need arbitration equipment Arbitration equipment should be an even number

1, each node is configured with 192.168.0.190 201 (Each node has the same configuration, and the configuration file can be copied)

Install the heartbeat package

yum installhttp://mirrors.hustunique.com/epel//6/x86_64/epel-release-6-8.noarch.rpm

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

[root@node1heartbeat2]#rpm-ivhheartbeat-gui-2.1. 4-12.el6.x86_64.rpm
heartbeat-stonith-2.1.4-12.el6.x86_64.rpm —Complete node isolation package

heartbeat-pils-2.1.4-12.el6.x86_64.rpm —dependent library

heartbeat-gui-2.1.4-12.el6.x86_64.rpm –crm graphics management package

Install LAMP

yum install http mysql-server php php-mysql

vim /etc /my.cf

datadir=/mysql/data

[root@node1lib]#mkdir-p/mysql/data
[root@node1lib]# chown mysql.mysql /mysql/data -R

After that chkconfig mysqld off ;Chkconfig httpd off Do not boot

Configure heartbeat

cd /usr/share/doc/heartbeat-2.1.4/

cp -p authkeys ha.cf haresources /etc/ha.d/

[root@node1ha.d]#ls
authkeysha.cf harc haresources rc.d README.config resource.d shellfuncs

Configuration: authkeys

[ root@node1ha.d]#chmod 600authkeys

[root@node1< span style="font-family:'Microsoft YaHei','Microsoft YaHei';">ha.d]#openssl rand-base64 6
UBNXiK8Q< /p>

[root@node1 ha.d]# vim authkeys

auth 2

#1 crc

2 sha1 UBNXiK8Q

#3 md5 Hello!

Configuration: ha.cf

logfacility local0 #Log function: logfacility means that it will be sent to syslog, and the log will be recorded by syslog, but it points to local0. There is no local0 here, and there is probably no log, so we can

< p>vim /etc/rsyslog.conf

Add

local0.* /var/log/headbeat.log

Or comment logfacility local0

restart rsyslog afterwards

Open logfile /var/log/ha-log

crm on #After enabling this, the default is Haresources files are disabled

#keepalive 2 –The default heartbeat is every two seconds< /p>

#deadtime 30 –How often does it take to announce that a node is down? (Detect once every 2 seconds, and not in after 30 seconds Declared dead)

#warntime 10 –Warntime 10 –For example, if the node is not online after 10s of detection, the log may prompt a warning that the node may be down, etc. information.

udpport 694 –The default heatbeat port is 694

#bcast eth0 # Linux Broadcast

mcast eth0 225.0.0.1 694 1 0 Multicast 1 means ttl is 1, and it is not allowed to return. 0 is not allowed to leave the router ttl=1 loop=0; we enable multicast here

#ucast eth0 192.168.1.2 Unicast

The use of multicast requires the network card to enable the multicast mode:

[root@node1ha.d]# ifconfig
eth0 Link encap:Ethernet HWaddr 00:0C:29:4D:AA:F0 br style=”background-color:inherit;”>inet addr:192.168.0.190 Bcast:192.168.0.255 Mask:255.255.255.0
inet6addr:fe80::20c:29ff :fe4d:aaf0/64 Scope:Link
UP BROADCAST RUNNING MULTICASTMTU:1500 Metric:1
TX packets:21653errors:0dropped:0overruns:0 carrier:0
br style=”background-color:inherit;”>collisions:0 txqueuelen:1000
RXbytes:5715766(5.4MiB)TXbytes:25228602(24.0MiB)

Note:[ root@node1 Ha.d]#ip link set eth0 multicast on –Enable multicast off is off

auto_failback on –Whether to receive resources when the active node is disconnected and then recovered (automatic failback)< /span>

node node1.zkl.com

node node2.zkl.com –There are nodes defined, which must be consistent with usname -r

ping 192.168.0.202–Arbitration device

#ping_group group1 10.10.10.254 10.10.10.253 –If a host is not insured, you can define it in the group

#compression bz2 –Whether to compress information between hosts

#compression_threshold 2-Compression is greater than 2KB

[root@node1ha.d]# crm_mon # command can realize monitoring, 5560 crm monitoring Port.

Refresh in 6s…< /span>

======== ====

Last updated: Thu Oct 22 10:50:03 2015

Current DC: node1.zkl.com (c823878a-8569-421a-af56-b4f9c0786a4a)

2 Nodes configured.

0 Resources configured.

============

Node: node2.zkl.com (696677c1-4909-4699-8d4c-f02 e693167b4): online

Node: node1 .zkl.com (c823878a-8569-421a-af56-b4f9c0786a4a): online

Copy node1 node configuration file to node2

[root@node1ha.d]#scp -p authkeys ha.cf 192.168 .0.201:/etc/ha.d/

Note:< /p>

1, when switching IP resources, the node will send a broadcast to inform other devices of their mac, ip .

2, in the hb_standby Run this script to turn the current host into a standby node, hb_takeover can grab resources back.


2, configure on nfs host 202:

mkdir -p /mydata

chown mysql.mysq /mydata/data -R

[root@node4~]#cat /etc/exports

/mydata/data 192.168.0.0/24(rw,no_root_squash)

创建组和用户必须和节点mysql用户组一致。节点mysql用户uid,gid都为27

groupadd -g 27 mysql

useradd -u 27 -g 27 mysql

id mysql

uid=27(mysql) gid=27(mysql) 组=27(mysql)

或者每个主机上:groupadd -r -g 306 mysql useradd -r -g 306 -u 306 mysql

service nfs restart

这样mysql,NFS共享配置完成。

3,在node1节点挂载NFS目录

mount -t nfs node4:/mydata/data /mysql/data

初始化数据库,只要在NFS挂载状态下连个节点只要初始化一次即可

service mysqld start 

继续,配置mysql

mysql一些配置:(注意一定要在NFS挂载状态下配置,这样保持数据一致)

设置mysql,root密码

mysqladmin -u root password “root”

创建远程登录用户,授权:

mysql> CREATE USER ‘zkl’@’192.168.0.%’ IDENTIFIED BY ‘zkl’;

Query OK, 0 rows affected (0.31 sec)

mysql> GRANT ALL ON *.* TO ‘zkl’@’192.168.0.%’;

Query OK, 0 rows affected (0.11 sec)

mysql>flush privileges;

4,crm配置:图形化界面运行 hb_gui &(需要创建用户并设置密码)

在需要运行的节点上:

useradd hacluster

echo “root”|passwd –stdin h acluster


Resources资源配置:

定义组资源:myservices

组内添加资源,依照顺序:

web网页ip地址:webip        IPaddr –>192.168.0.199 24 eth0

httpd服务:        webserver    httpd –>httpd

NFS共享挂载:    mysql_store    Filesystem–>device:192.168.0.202:/mydata/data directory: /mysql/data fstype:nfs 

mysql服务:        mysqld        mysqld

Colocations配置:

webserver依据webip规则

mysqld服务依据mysql_store规则

orders顺序约束配置:详情参考说明(Description)

最后如下所示:

5,wordpress配置(在活动节点node1)

tar zxvf wordpress-4.3.1-zh_CN.tar.gz -C /var/www/html/

打开网页http://192.168.0.199:/wordpress

依据内容进行配置

配置完成后:

scp -r /var/www/html/wordpress 192.168.0.201:/var/www/html/

6,测试

node1发表文章,切换到node2也可以看到node1节点:发表文章如下:

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”7.png” alt=”wKioL1YpxAKgCZLaAAFn9zOaiOI138.jpg” d=”4287986″ s=”a62_bae” t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” style=”float:none;” title=”9.png” alt=”wKiom1Ypw9WS7r0kAAFuE7rfbDw190.jpg” d=”4287988″ s=”56f_86f” t=”jpg”>

Leave a Comment

Your email address will not be published.