Heartbeat (V2) implementation LAMP provides WordPress blog site high availability model practice

Friendly reminder: The experimental environment of this article is vmware 10 + Centos 6.6 X86_64, which is involved in the article Please be cautious to use the commands and methods of

Content summary:

1) Experimental ideas

2) Experimental environment and topology

< p> 3) Experimental steps

4) Thoughts after the experiment

An experimental idea

The high-availability implementation of LAMP must solve two problems:

(1) The IP resource corresponding to the provided domain name can drift correctly as the resource operation node changes.

(2) Provided between each node The content of web resources must be consistent.

In this experiment, implement it like this:

Each node is configured with the same lamp combination, but the combination of amp only Start on the resource running node, and the non-resource running node cannot start the amp combination by itself.

The mariadb library of the resource running node and httpd site documentation The contents of the root directory are provided by back-end shared storage.

On which node the resource runs, that node hangs Load the back-end shared storage, and then start the amp combination service. Non-resource running nodes must not automatically mount shared storage, and must not automatically start the amp combination.

Place the forum wordpress content and required libraries in On shared storage, this ensures that the content is consistent when different nodes are mounted.

Two experimental environment and topology

Experimental environment setting:

< td rowspan="1" colspan="1" valign="top">Verify the high availability of LAMP cluster nodes

node name
The corresponding IP address
Characters
Description
Test01.lijun.com

eth1:192.168.100.1/24

eth0:172.16.34.1/16

Shared storage server
The host provides sharing through NFS, which is used as shared storage
Test02.lijun.com

eth1:192.168.100.2/24

eth0:172.16.34.2/16

LAMP combination node
LAMP combination is configured to participate in the heartbeat high-availability cluster
Test03.lijun.com

eth1:192.168.1 00.3/24

eth0:172.16.34.3/16

LAMP combination node LAMP combination is configured to participate in the heartbeat high-availability cluster
Test04.lijun.com< /span>

eth1:192.168.100.4/24

eth0:172.16.34.4/16 td>

LAMP combination node< /td>

LAMP combination is configured to participate in heartbeat High availability cluster
win7.lijun.com
192.168.100.100/24
client
Shared server
172.16.0.1

NTP time server

yum Installation source

Provide ntp service for cluster node time synchronization

Provide yum repo for cluster nodes to install software

The IP resource provided by the cluster resource is 192.168.100.10

Each node eth0 network card is connected to the vmware virtual machine vmnet0, which is used to connect to the shared server

Each node eth1 network card is connected to the vmware virtual machine vmnet8, which is used to connect to the customer test machine

(ps: Some children’s shoes will ask why they need 3 LAMP nodes, 2 LAMP nodes + 1 arbitration node is not enough? That’s because in my vmware virtual machine environment using 2 LAMP nodes + 1 arbitration node, there is always a split brain phenomenon, so I have to use 3 LAMP nodes, and the pirate does not want to open so many virtual machines. Poor my Thinkpad R400 palm rest can be fried eggs hot! ! )

Experimental topology:

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” title=”1111.png” alt=”wKioL1VubR6RXrreAAP1bTNR45A705. jpg” d=”4488520″ s=”d48_f7f” t=”jpg”>

The new disk is recognized by the system as /dev/sdb and /dev/sdc, and partitioned as /dev/sdb1 and /dev/sdc1, formatted as ext4 file system, the process is omitted.

Share through nfs:

#mkdir/mydata/#mkdir/web#vim/etc/fstab add: / dev / sdb1 / mydata ext4 defaults 0 0 / dev / sdc1 / web ext4 defaults 0 0 # mount -a # mkdir / mydata / data [root @ Test01 /] # groupadd -g 27 mysql [root @ Test01 /] # useradd -g 27 -u 27 -r mysql[root@Test01/]#chown -R mysql.mysql /mydata/data#vim/etc/exporfs/mydata 192.168.100.0/24(rw,no_root_squash)/web 192.168.100.0/ 24(rw,no_root_squash)#service nfs start

3.3) Test02 configuration:

3.3.1) Turn off the firewall and selinux to prevent interference Experimenting

[root@Test02~]#service iptables stop[root@Test02~]#setenforce 0

3.3.2) Configure ntp time synchronization:

[root@Test02~]# ntpdate 172.16.0.131 May 23:39:06 ntpdate[3093]: adjust time server 172.16. 0.1 offset 0.001768 sec[root@Test02~]# crontab -e*/5****/usr/sbin/ntpdate 172.16.0.1

3.3.3) Set the /etc/hosts file to realize the mutual resolution of domain names and IPs between cluster nodes

[root@Test02 ~]# vim /etc/hosts192.168.100. 1 Test01.lijun.com Test01192.168.100.2 Test02.lijun.com Test02192.168.100.3 Test03.lijun.com Test03192.168.100.4 Test04.lijun.com Test04

3.3.4) SSH mutual trust between nodes

[root@Test02~]# ssh-keygen-trsa-P''[root@Test02~]#ssh -copy-id -i /root/.ssh/id_rsa.pub Test03[root@Test02~]#ssh-copy-id -i/root/.ssh/id_rsa.pub Test04

3.3.5 )Install httpd and php software

[root@Test02 ~]#yum -y install httpd php php-mysql[root@Test02 ~]#chkconfig-- add httpd[root@Test02~]#chkconfig httd off

3.3.6) Modify httpd configuration file

[root@Test02 ~]#cd/etc/httpd/conf[root@Test02conf]#scp httpd.conf{,.bak}[root@Test02conf]#vim httpd.conf#Add: ServerName 127.0.0.1:80#Modify: DirectoryIndex index.php index.html index.html.var

3.3.7) Install mar iadb:

#groupadd-g27mysql#useradd-g27-u27-rmysql
#mkdir/mydata#mount-t nfs 192.168.100.1:/mydata/mydata
[root@Test02source]#tar-xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local[root@Test02 source]# cd /usr/local/[root@Test02 local]# ln-sv mariadb-5.5.43-linux- x86_64 mysql`mysql' -> `mariadb-5.5.43-linux-x86_64'[root@Test02 local]# cd mysql/[root@Test02 mysql]#chown-R root.mysql./*[root@Test02 mysql] #./Scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql
[root@Test02mysql]#mkdir/etc/mysql [root@Test02 mysql]# cp support-files/my-medium.cnf /etc/mysql/my.cnf[mysqld]#Add datadir = /mydata/datainnodb_file_per_table = on[root@Test02 mysql]# cp support-files/ mysql.server /etc/init.d/mariadb[root@Test02 mysql]# chmod +x /etc/init.d/mariadb [root@Test02 mysql]# /etc/init.d/mariadb startStar ting MySQL ... [OK] [root @ Test02 mysql] # service mariadb stopShutting down MySQL. [OK] [root @ Test02 mysql] # chkconfig --add httpd [root @ Test02 mysql] # chkconfig --add mariadb [root @Test02 mysql]# chkconfig httpd off[root@Test02 mysql]# chkconfig mariadb off

3.3.8) WordPress program installation

[root@Test02 mysql]#mount-t nfs 192.168.100.1:/web/var/www/html[root@Test02 mysql]#cd/var/www/html[root@Test02html]#unzip wordpress-3.0. 4-zh_CN.zip[root@Test02html]#mvwordpress/*.[root@Test02html]#scpwp-config-sample.phpwp-config.php
 Modify the file as follows[root@Test02 html]# vim wp-config.php define('DB_NAME','wordpress');^M^M/** MySQL database user name*/^Mdefine('DB_USER ','Wordpress');^M^M/** MySQL database password*/^Mdefine('DB_PASSWORD','redhat');^M^M/** MySQL host*/^Mdefine('DB_HOST',' 127.0.0.1');^M
[roo t@Test02 www]#/etc/init.d/mariadb startStarting MySQL... mysql... Query mysql> 1 create mysql[root@Test02 www]#Queryaffected mysql> 1 wordpress.* to wordpress@localhost identified by'redhat';Query OK, 0 rows affected (0.03 sec)mysql> grant all on wordpress.* to [email protected] identified by'redhat';Query OK, 0 rows affected ( 0.00sec)mysql>flushprivileges;QueryOK,0rowsaffected (0.02sec)mysql>quitBye
[root@Test02www]#servicehttpdstartStartinghttpd : [OK][root@Test02 www]#

3.3.9) Browser test on client

this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” title=”5620.png” alt=”wKioL1Vud3SBAj-sAAN_1IegU28965.jpg” d= “4488521” s=”926_773″ t=”jpg”>

650) this.width=650;” src=”/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png” title =”56315.png” alt=”wKioL1VueBuSjGDYAAPbfnNWEvc804.jpg” d=”4488523″ s=”670_efd” t=”jpg”>

[root@Test02 html]#/etc/init.d/mariadb stopShutting down MySQL[ OK ][root@Test02 html]# service httpd stopStopping httpd: bash related components [root@Test02 html]#

10 10

;toolbar:false”>[root@Test02 html]#yum -y install net-snmp-libs libnet PyXML libt ool-ltdl[root@Test02html]#cd/root/source/heartbeat2/[root@Test02heartbeat2]#rpm-ivh/root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm [root@Test02 heartbeat2]#rpm-ivh/root/source/heartbeat2/heartbeat-stonith-2.1.4-12.el6.x86_64.rpm [root@Test02 heartbeat2]#rpm-ivh/root/source/heartbeat2/heartbeat -2.1.4-12.el6.x86_64.rpm[root@Test02 heartbeat2]#

3.3.11) Configure heartbeat

 [root@Test02 heartbeat2]#cd/etc/ha.d[[email protected]]#cp-a/usr/share/doc/heartbeat-2.1.4/ha.cf.[[email protected] ]#cp-a/usr/share/doc/heartbeat-2.1.4/authkeys.
[[email protected]]#opensslrand- hex 850c60f2f91918f4d[[email protected]]#vim authkeys #Modify as follows auth 22 sha1 50c60f2f91918f4d[[email protected]]#chmod 600 authkeys
 [[email protected]]#vim/etc/ha.d/ha.cf#Modify the following logfile/var/log/ha-log#logfacility local0mcast eth1 236.0.0.1 694 1 0auto_failback onnode Test02.lijun.comnode Test03.lijun.comnode Test04.lijun.comcrm on

3.4) Configuration on Test03

3.4 .1) Turn off iptables and selinux to prevent interference

[root@Test03 ~]#service iptables stop[root@Test03~]#setenforce 0

3.4.2) Synchronization time

[root@Test03~]# ntpdate 172.16.0.131 May 23:39:06 ntpdate[3093]: adjust time server 172.16.0.1 offset 0.001768 sec[root@Test03 ~]# crontab -e */5 ** ** /usr/sbin/ntpdate 172.16.0.1

3.4.3) Configuration /etc/hosts File to achieve local resolution of domain name and IP

[root@Test03~]# vim/etc/hosts192.168.100.1 Test01.lijun.com Test01192. 168.100.2 Test02.lijun.com Test02192.168.100.3 Test03.lijun.com Test03192.168.100.4 Test04.lijun.com Test04

3.4.4) Configure SSH mutual trust between clusters

< pre class="brush:bash;toolbar:false">[root@Test03~]#ssh-keygen-trsa-P”[root@Test03~]#ssh-copy-id-i/root/.ssh/ id_rsa.pub Test02[root@Test03~]#ssh-copy-id-i/roo t/.ssh/id_rsa.pub Test04

3.4.5) Install httpd and php components

[root@Test03~]# yum -y install httpd php-mysql[root@Test03~]#chkconfig--add httpd[root@Test03~]#chkconfig httpd off

3.4.6) Set the httpd configuration file

[root@Test03~]#cd/etc/httpd/conf[root@Test03conf]#rm-rf httpd.conf[root@Test03conf]#scp Test02:/etc/httpd/conf/httpd.conf.

3.4.7) Install mariadb database

[root@Test03conf ]#cd/root/source[root@Test03source]#groupadd-g27mysql[root@Test03source]#useradd-g27-u27-rmysql[root@Test03source]#tar-xfmariadb-5.5. 43-linux-x86_64.tar.gz -C /usr/local
[root@Test03 source]# cd/usr/local/[root@Test03 local]#ln-svmariadb-5.5.43-linux-x86_64mysql`mysql'->`mariadb-5.5.43-linux-x86_64'[root@Test03local]#cdmysql/[root@Test03mysql]#chown -R root.mysql./*
[r oot@Test03 mysql]# mkdir /etc/mysql[root@Test03 mysql]# scp Test02:/etc/mysql/my.cnf /etc/mysql/my.cnf s 496 KB 100% 100% Test03 mysql] # scp Test02: /etc/init.d/mariadb /etc/init.d/mariadb 100% 12KB 11.9KB / s 00:00 [root @ Test03 mysql] # mkdir / mydata  
[root@Test03 mysql]# chkconfig--add mariadb [root@Test03 mysql]# chkconfig mariadb off

3.4.8) Install the heartbeat component

[root@Test03 mysql]#yum-y install net-snmp-libs libnet PyXML libtool-ltdl[root@Test02 mysql]#cd/root/source/heartbeat2 /[root@Test02 heartbeat2]# rpm -ivh /root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm [root@Test02 heartbeat2]#rpm-ivh/root/source/heartbeat2/ heartbeat-stonith-2.1.4-12.el6.x86_64.rpm [root@Test02 heartbeat2]#rpm -ivh/root/source/heartbeat2/heartbeat-2.1.4-12.el6.x86_64.rpm[root@Test02 heartbe at2]#

3.4.9) Prepare configuration files for heartbeat

[root@Test02 Heartbeat2]#scp-p Test02:/ etc/ha.d/ha.cf /etc/ha.d/[root@Test02 heartbeat2]#scp-p Test02:/etc/ha.d/authkeys /etc/ha.d/

3.5) Configuration on Test04

3.5.1) Close iptables and selinux to prevent interference experiments

[root@Test04~]#service iptables stop[root@Test04~]#setenforce 0

3.5.2) Time synchronization

[root@Test04~]#ntpdate 172.16 .0.131 May 23:39:06 ntpdate[3093]: adjust time server 172.16.0.1 offset 0.001768 sec[root@Test04 ~]# crontab -e */5*****/usr/sbin/ntpdate 172.16.0.1 

3.5.3) Configure local mutual resolution between cluster node IP and domain name

[root@Test04~]#vim/etc/hosts192. 168.100.1 Test01.lijun.com Test01192.168.100.2 Test02.lijun.com Test02192.168.100.3 Test03.lijun.com Test03192.168.100.4 Test04.lijun.com Test04

3.5.4) Configure mutual trust between cluster nodes

[root@T est04~]#ssh-keygen-t rsa-P''[root@Test04~]#ssh-copy-id-i/root/.ssh/id_rsa.pub Test03[root@Test04~]#ssh-copy-id -i /root/.ssh/id_rsa.pub Test02

3.5.5) Install httpd and php components

[root@Test04 ~]#yum -y install httpd php php-mysql[root@Test04~]#chkconfig--add httpd[root@Test04~]#chkconfig httpd off

3.5.6) Set the httpd configuration file

[root@Test04~]#cd/etc/httpd/conf[root@Test04conf]#rm-rfhttpd.conf[root@Test04conf] ]#scp Test02:/etc/httpd/conf/httpd.conf.

3.5.7) Install mariadb:

[root @Test04~]##groupadd-g27mysql[root@Test04~]##useradd-g27-u27-rmysql
[root@ Test04~]#cd/root/source[root@Test04source]#tar-xfmariadb-5.5.43-linux-x86_64.tar.gz-C/usr/local[root@Test04source]#cd/usr/local /[root@Test04local]#ln-svmariadb-5.5.43-linux-x86_64mysql`mysql'->`mariadb-5.5.43-linux-x86_64'[ro ot@Test04 local]# cd mysql/[root@Test04 mysql]# chown-R root.mysql./*
[root@Test04 mysql]# mkdir /etc/mysql[root@Test04 mysql]# scp Test02:/etc/mysql/my.cnf /etc/mysql/my.cnf s mysql# 4963 cp mysql test 00:00 scp/ mysql# 100% :/etc/init.d/mariadb /etc/init.d/mariadb bashing 100% 12KB 11.9KB/s pre 00:00 mysql/ mysql] #root@Test04 toolbar:false">[root@Test04 mysql]# chkconfig--add mariadb [root@Test04 mysql]# chkconfig mariadb off

3.5.8) Install the heartbeat component

[root@Test04 mysql]#yum -y install net-snmp-libs libnet PyXML libtool-ltdl[root@Test04 mysql]#cd/root/source/heartbeat2/[root@Test04 heartbeat2 ]#Rpm-ivh/root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm[root@Test04heartbeat2]#rpm-ivh/root/source/heartbeat2/heartbeat-stonith-2.1. 4-12.el6.x86 _64.rpm [root@Test04 heartbeat2]#rpm -ivh /root/source/heartbeat2/heartbeat-2.1.4-12.el6.x86_64.rpm[root@Test04 heartbeat2]#

3.5.9 )Prepare configuration files for heartbeat

[root@Test04 Heartbeat2]#scp-p Test02:/etc/ha.d/ha.cf/etc/ha .d/[root@Test04 heartbeat2]#scp-p Test02:/etc/ha.d/authkeys/etc/ha.d/

3.6) Install the heartbeat-gui package on Test02 for graphical configuration

[[email protected]]#rpm-ivh/root/source/heartbeat-gui-2.1.4-12.el6. x86_64.rpm [[email protected]]#echo'redhat'|passwd--stdinhacluster

3.7)Start the heartbeat service on the cluster nodes

[root@Test02 ha.d]# service heartbeat start; ssh Test03'service heartbeat start';ssh Test04'service heartbeat start'

3.8) Observe ports on cluster nodes< /p>

#ss-tulpn|egrep--color'(694|5560)'udp UNCONN 0 (user: 236.0.0.1:694*: 694* heartbeat",3012,7),("heartbeat",3013,7))tc p LISTEN 0 10 10 *:5560 *:* Users: (("mgmtd",3026,10) on the heartbeat program Observation: (("mgmtd",3026,10) on the heartbeat program)

3.9 onload="if(this.width>650) this.width=650;" src="/wp-content/uploadshttp:/img.voidcn.com/vcimg/static/loading.png" title="561.png" alt="wKioL1VurKXylPc0AAKDtZk5d3M131.jpg" d="4488525" s="d65_5f1" t="jpg">

wKiom1VuqzzDnb3eAAJUoOu1I-c828.jpg

wKioL1VurPSTDmu_AALoRV934Ts160.jpg

< /p>

3.10) Use the heartbeat-gui tool to configure resources and constraints

*Here, use the resource type as "group" To build. You must first create a "group" and then create the corresponding resources.

The creation order of resources in the "group" is bound by order and colocation by default, so we must pay attention to the creation order Priority.

wKiom1VurI2jfuKAAAMQh8PrnS8661.jpg

wKioL1VurkfgXZIlAAKmk1wJpgc080.jpg

wKiom1VurNGymnXmAARcQCeusCY653. jpg

wKioL1Vurm6Bz9_ZAARM1mWl5Uo286.jpg

wKiom1VurNWhow76AAO1nyNpNus320.jpg

wKioL1VurnHiBGMlAAOI6nMnCMk734.jpg

wKiom1VurNfz31QzAAK338YawWI467.jpg

wKioL1VurnKxqVRbAAI2DXOM9Lg576.jpg

3.11) Start the resource group and observe it

< img onload="if(this.width>650) this.width=650;" src="/wp-content/uploadshttp:/img.v oidcn.com/vcimg/static/loading.png" style="float:none;" title="5638.png" alt="wKioL1VurxijdfrXAALGrrXPAFE312.jpg" d="4488536" s="2c6_771" t="jpg">

wKiom1VurYCwQV_IAAQmvcTjTFw929.jpg

wKioL1Vurxyyr2ZSAAWfwHRnzJk186.jpg

 wKiom1VurYXwU480AAUO34iAt-Y607.jpg

3.12) Perform a high-availability test: Change the Test04 node to a standby state

wKioL1Vur-vhVneJAAQvZjsdMPo975.jpg

wKioL1Vur-2h3DPvAANqP9AyzO4795.jpg

wKiom1VurlTj1BH1AAON-vLytiA692.jpg

Now Test03 and Test04 are in standby state, so the resources can only be transferred to Test02 and write a new blog post

wKiom1Vurlux9-2mAAWfyHhpqLg582 .jpg

3.13) Switch to the active state of Test04 bit and observe whether the resource will be transferred , There is still Is the blog post written on Test02 still?

wKiom1VuryaS_Y44AAO_itESIfA157.jpg

wKioL1VusMKSdbtKAANX9tAGSpQ766.jpg

wKiom1VuryjCQ3FUAAN_s3w5sbE250.jpg

四实验后的思考

     实验已经做完了,但是还有诸多东东要思考的

    4.1)这种实验模型纯粹是验证heartbeat的用法,没实际意义。

    4.2)实际中httpd,php,mariadb一定会是分离存在,不会集中于一台服务器上,不然像上面实验模型中的构架,没有丁点的扩展余地。

(ps:有童鞋问:为啥子你不搞个牛X的实验模型,海盗哥只能说:实验平台不给力,陪我6年的ThinkpadR400支撑不起来那么多虚拟机,求赞助)

    4.3)后端的共享存储会成为系统瓶颈和单点故障处,要考虑缓存和drbd的使用,当然“同城异地备份”“两地三中心”这种模式需要银子支持的,还要把光纤埋得够深,不然挖掘机一铲子下去,你懂的。

    4.4)会话保存的问题。

五 上传下海盗哥的ThinkpadR400私照,这位默默陪了我6年伙计

wKioL1VuvkLhvo_ZAATDJeDZbRk871.jpg

Leave a Comment

Your email address will not be published.