撒的阿坎努斯 发表于 2019-1-7 13:45:47

heartbeat(v2)实现LAMP提供wordpress博客站点高可用模型实践

              友情提醒:本文实验环境 vmware 10 + Centos 6.6 X86_64,文中涉及到的命令和方式请谨慎使用
  内容概括:
  1)实验思路
  2)实验环境和拓扑
  3)实验步骤
  4)实验后的思考
  一 实验思路
  LAMP的高可用的实现要解决2个问题:
            (1)提供的域名对应的IP资源能够随着资源运行节点的改变而正确漂移。

            (2)各个节点间提供的web资源内容要一致。
        在这个实验这样来实现:
              各个节点均配置有相同的lamp组合,但是amp的组合只在资源运行节点上启动,非资源运行节点不可自行启动amp组合。
               资源运行节点的mariadb库和httpd的站点文档根目录内容,均有后端共享存储提供。
               资源运行在哪个节点上,那个节点就挂载后端共享存储,然后启动amp组合服务。非资源运行节点,不得自动挂载共享存储,不得自动启动amp组合。
               将论坛wordpress内容和需要的库均放置在共享存储上,这样当不同节点挂载时,可保障内容一致。

  

  二 实验环境与拓扑
  实验环境设定:

节点名称
对应的IP地址
角色
说明
Test01.lijun.com
  eth1:192.168.100.1/24
  eth0:172.16.34.1/16

共享存储服务器
该主机通过NFS提供共享,做共享存储使用
Test02.lijun.com
  eth1:192.168.100.2/24
  eth0:172.16.34.2/16

LAMP组合节点
配置有LAMP组合,参与heartbeat高可用集群
Test03.lijun.com  eth1:192.168.100.3/24
eth0:172.16.34.3/16LAMP组合节点配置有LAMP组合,参与heartbeat高可用集群Test04.lijun.com  eth1:192.168.100.4/24
eth0:172.16.34.4/16LAMP组合节点配置有LAMP组合,参与heartbeat高可用集群win7.lijun.com
192.168.100.100/24
client
验证LAMP集群节点高可用
共享服务器
172.16.0.1
  NTP时间服务器
  yum安装源

  提供ntp服务,供集群节点对时
  提供yum repo,供集群节点安装软件

  通过集群资源提供的IP资源为192.168.100.10

  各节点eth0网卡接入vmware虚拟机vmnet0,用来连接共享服务器

  各节点eth1网卡接入vmware虚拟机vmnet8,用来连接客户测试机

  

  (ps:有童鞋会问为啥要用3个LAMP节点,2个LAMP节点+1个仲裁节点不行吗?那是因为在我的vmware虚拟机环境中使用2个LAMP节点+1个仲裁节点的形式,总是出现脑裂的现象,只好用3个LAMP节点了,海盗哥也不想开那么多虚拟机,可怜我的ThinkpadR400掌托处热的可以煎鸡蛋啦!!)
  实验拓扑:

http://s3.运维网.com/wyfs02/M00/6D/DF/wKioL1VuavTB2CnzAAYDX5Si_gI929.jpg
  三 实验步骤:
  各节点上IP配置,网卡桥接,yum配置文件设定这里就不演示了,自行解决。

  3.1)Test01上提供共享存储:
  添加2块新磁盘,做贡献分区使用:
http://s3.运维网.com/wyfs02/M01/6D/DF/wKioL1VubR6RXrreAAP1bTNR45A705.jpg
  新磁盘分别系统识别为/dev/sdb和/dev/sdc,分别被分区为/dev/sdb1和/dev/sdc1,格式化为ext4文件系统,过程略。
  通过nfs实现共享:

#mkdir /mydata/
#mkdir /web
#vim /etc/fstab
添加:
/dev/sdb1               /mydata               ext4    defaults      0 0
/dev/sdc1               /web               ext4    defaults      0 0
#mount -a
#mkdir /mydata/data
# groupadd -g 27 mysql
# useradd -g 27 -u 27 -r mysql
# 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配置:
  3.3.1)关闭防火墙和selinux,防止干扰实验进行
#service iptables stop
#setenforce 0  3.3.2)配置ntp时间同步:
# ntpdate 172.16.0.1
31 May 23:39:06 ntpdate: adjust time server 172.16.0.1 offset 0.001768 sec
# crontab -e
*/5 * * * * /usr/sbin/ntpdate 172.16.0.1  3.3.3)配置/etc/hosts文件,实现集群节点间域名和IP的互相解析
# vim /etc/hosts
192.168.100.1    Test01.lijun.com    Test01
192.168.100.2    Test02.lijun.com    Test02
192.168.100.3    Test03.lijun.com    Test03
192.168.100.4    Test04.lijun.com    Test04  3.3.4)配置集群节点间SSH互信

# ssh-keygen -t rsa -P ''
#ssh-copy-id -i /root/.ssh/id_rsa.pubTest03
#ssh-copy-id -i /root/.ssh/id_rsa.pubTest04  3.3.5)安装httpd和php软件
#yum -y install httpd php php-mysql
#chkconfig --add httpd
#chkconfig httd off  3.3.6)修改httpd的配置文件
# cd /etc/httpd/conf
# scp httpd.conf{,.bak}
# vim httpd.conf
#增加:
ServerName 127.0.0.1:80
#修改:
DirectoryIndex index.php index.html index.html.var  3.3.7)安装mariadb:
# groupadd -g 27 mysql
# useradd -g 27 -u 27 -r mysql#mkdir /mydata
#mount -t nfs 192.168.100.1:/mydata /mydata# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.43-linux-x86_64'
# cd mysql/
# chown -R root.mysql ./*
# ./scripts/mysql_install_db --datadir=/mydata/data/ --user=mysql#mkdir /etc/mysql
# cp support-files/my-medium.cnf/etc/mysql/my.cnf

#添加
datadir = /mydata/data
innodb_file_per_table = on
# cp support-files/mysql.server /etc/init.d/mariadb
# chmod +x /etc/init.d/mariadb
# /etc/init.d/mariadb start
Starting MySQL...                                          
# service mariadb stop
Shutting down MySQL.                                       
# chkconfig --add httpd
# chkconfig --add mariadb
# chkconfig httpd off
# chkconfig mariadboff  3.3.8)wordpress程序的安装
#mount -t nfs 192.168.100.1:/web /var/www/html
#cd/var/www/html
# unzip wordpress-3.0.4-zh_CN.zip
# mv wordpress/* .
# scp wp-config-sample.php wp-config.php 修改文件如下
# vim wp-config.php
define('DB_NAME', 'wordpress');^M
^M
/** MySQL 数据库用户名 */^M
define('DB_USER', 'wordpress');^M
^M
/** MySQL 数据库密码 */^M
define('DB_PASSWORD', 'redhat');^M
^M
/** MySQL 主机 */^M
define('DB_HOST', '127.0.0.1');^M# /etc/init.d/mariadb start
Starting MySQL...                                          
# mysql
mysql> create database wordpress;
Query OK, 1 row affected (0.03 sec)
mysql> grant all on wordpress.* to wordpress@localhost identified by 'redhat';
Query OK, 0 rows affected (0.03 sec)
mysql> grant all on wordpress.* to wordpress@127.0.0.1 identified by 'redhat';
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.02 sec)
mysql> quit
Bye# service httpd start
Starting httpd:                                          
#  3.3.9)client上浏览器测试

http://s3.运维网.com/wyfs02/M00/6D/E0/wKioL1Vud3SBAj-sAAN_1IegU28965.jpg
http://s3.运维网.com/wyfs02/M01/6D/E0/wKioL1Vud4vAwUK3AATYmlNsm70311.jpg
http://s3.运维网.com/wyfs02/M01/6D/E0/wKioL1VueBuSjGDYAAPbfnNWEvc804.jpg
http://s3.运维网.com/wyfs02/M02/6D/E0/wKioL1VueOLQrcaCAAOzG6583QY048.jpg
# /etc/init.d/mariadb stop
Shutting down MySQL.                                       
# service httpd stop
Stopping httpd:                                          
#  3.3.10)安装heartbeat相关组件
#yum -y install net-snmp-libs libnet PyXML libtool-ltdl
#cd /root/source/heartbeat2/
# rpm -ivh /root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-2.1.4-12.el6.x86_64.rpm
#  3.3.11)配置heartbeat
#cd /etc/ha.d
#cp -a /usr/share/doc/heartbeat-2.1.4/ha.cf   .
#cp -a /usr/share/doc/heartbeat-2.1.4/authkeys    .#openssl rand -hex 8
50c60f2f91918f4d
#vim authkeys
#修改如下
auth 2
2 sha1 50c60f2f91918f4d
#chmod 600 authkeys# vim /etc/ha.d/ha.cf
#修改如下
logfile    /var/log/ha-log
#logfacility    local0
mcast eth1 236.0.0.1 694 1 0
auto_failback on
node Test02.lijun.com
node Test03.lijun.com
node Test04.lijun.com
crm on  

  3.4)Test03上配置

  3.4.1)关闭iptables和selinux防止干扰
#service iptables stop
#setenforce 0  3.4.2)同步时间
# ntpdate 172.16.0.1
31 May 23:39:06 ntpdate: adjust time server 172.16.0.1 offset 0.001768 sec
# crontab -e
*/5 * * * * /usr/sbin/ntpdate 172.16.0.1  3.4.3)配置/etc/hosts文件,实现域名与IP的本地解析
# vim /etc/hosts
192.168.100.1    Test01.lijun.com    Test01
192.168.100.2    Test02.lijun.com    Test02
192.168.100.3    Test03.lijun.com    Test03
192.168.100.4    Test04.lijun.com    Test04  3.4.4)配置集群间ssh互信
# ssh-keygen -t rsa -P ''
#ssh-copy-id -i /root/.ssh/id_rsa.pub Test02
#ssh-copy-id -i /root/.ssh/id_rsa.pub Test04  3.4.5)安装httpd和php组件
#yum -y install httpd php php-mysql
#chkconfig --add httpd
#chkconfig httpd off  3.4.6)设定httpd配置文件
#cd /etc/httpd/conf
#rm -rf httpd.conf
#scp Test02:/etc/httpd/conf/httpd.conf.  3.4.7)安装mariadb数据库
#cd /root/source
# groupadd -g 27 mysql
# useradd -g 27 -u 27 -r mysql
# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local# cd /usr/local/
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.43-linux-x86_64'
# cd mysql/
# chown -R root.mysql ./*# mkdir /etc/mysql
# scp Test02:/etc/mysql/my.cnf /etc/mysql/
my.cnf                                             100% 4963   4.9KB/s   00:00   
# scp Test02:/etc/init.d/mariadb /etc/init.d/
mariadb                                          100%   12KB11.9KB/s   00:00   
# mkdir /mydata# chkconfig --add mariadb
# chkconfig mariadboff  3.4.8)安装heartbeat组件
#yum -y install net-snmp-libs libnet PyXML libtool-ltdl
#cd /root/source/heartbeat2/
# rpm -ivh /root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-2.1.4-12.el6.x86_64.rpm
#  3.4.9)为heartbeat准备配置文件
#scp -p Test02:/etc/ha.d/ha.cf/etc/ha.d/
#scp -p Test02:/etc/ha.d/authkeys/etc/ha.d/  3.5)Test04上配置
  3.5.1)关闭iptables和selinux防止干扰实验
#service iptables stop
#setenforce 0  3.5.2)时间同步
# ntpdate 172.16.0.1
31 May 23:39:06 ntpdate: adjust time server 172.16.0.1 offset 0.001768 sec
# crontab -e
*/5 * * * * /usr/sbin/ntpdate 172.16.0.1  3.5.3)配置集群节点IP与域名的本地互相解析
# vim /etc/hosts
192.168.100.1    Test01.lijun.com    Test01
192.168.100.2    Test02.lijun.com    Test02
192.168.100.3    Test03.lijun.com    Test03
192.168.100.4    Test04.lijun.com    Test04  3.5.4)配置集群节点间互信
# ssh-keygen -t rsa -P ''
#ssh-copy-id -i /root/.ssh/id_rsa.pub Test03
#ssh-copy-id -i /root/.ssh/id_rsa.pub Test02  3.5.5)安装httpd和php组件
#yum -y install httpd php php-mysql
#chkconfig --add httpd
#chkconfig httpd off  3.5.6)设定httpd配置文件
#cd /etc/httpd/conf
#rm -rf httpd.conf
#scp Test02:/etc/httpd/conf/httpd.conf.  3.5.7)安装mariadb:
## groupadd -g 27 mysql
## useradd -g 27 -u 27 -r mysql#cd /root/source
# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local
# cd /usr/local/
# ln -sv mariadb-5.5.43-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.43-linux-x86_64'
# cd mysql/
# chown -R root.mysql ./*# mkdir /etc/mysql
# scp Test02:/etc/mysql/my.cnf /etc/mysql/
my.cnf                                             100% 4963   4.9KB/s   00:00   
# scp Test02:/etc/init.d/mariadb /etc/init.d/
mariadb                                          100%   12KB11.9KB/s   00:00   
# mkdir /mydata# chkconfig --add mariadb
# chkconfig mariadboff  3.5.8)安装heartbeat组件
#yum -y install net-snmp-libs libnet PyXML libtool-ltdl
#cd /root/source/heartbeat2/
# rpm -ivh /root/source/heartbeat2/heartbeat-pils-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-stonith-2.1.4-12.el6.x86_64.rpm
#rpm -ivh /root/source/heartbeat2/heartbeat-2.1.4-12.el6.x86_64.rpm
#  3.5.9)为heartbeat准备配置文件
#scp -p Test02:/etc/ha.d/ha.cf/etc/ha.d/
#scp -p Test02:/etc/ha.d/authkeys/etc/ha.d/  3.6)Test02上安装heartbeat-gui包进行图形化配置

# rpm -ivh /root/source/heartbeat-gui-2.1.4-12.el6.x86_64.rpm
#echo 'redhat' | passwd --stdin hacluster  3.7)在集群节点上启动heartbeat服务
# service heartbeat start ; ssh Test03 'service heartbeat start';ssh Test04 'service heartbeat start'  3.8)在集群节点上观察端口
#ss -tulpn | egrep --color '(694|5560)'
udp    UNCONN   0      0            236.0.0.1:694                   *:*      users:(("heartbeat",3012,7),
("heartbeat",3013,7))
tcp    LISTEN   0      10                     *:5560                  *:*      users:(("mgmtd",3026,10))  3.9)在Test02上通过heartbeat-gui程序观察
http://s3.运维网.com/wyfs02/M02/6D/E3/wKioL1VurKXylPc0AAKDtZk5d3M131.jpg
http://s3.运维网.com/wyfs02/M02/6D/E7/wKiom1VuqzzDnb3eAAJUoOu1I-c828.jpg
http://s3.运维网.com/wyfs02/M01/6D/E3/wKioL1VurPSTDmu_AALoRV934Ts160.jpg
  

  3.10)借助heartbeat-gui工具进行资源和约束配置
  *这里借助资源类型为“组”的进行建立。一定要先建立“组”再建立相应的资源。
   “组”中资源的建立顺序默认情况下带有order和colocation约束,一定要注意建立的先后顺序。
http://s3.运维网.com/wyfs02/M00/6D/E8/wKiom1VurI2jfuKAAAMQh8PrnS8661.jpg
  

http://s3.运维网.com/wyfs02/M01/6D/E3/wKioL1VurkfgXZIlAAKmk1wJpgc080.jpg
http://s3.运维网.com/wyfs02/M01/6D/E8/wKiom1VurNGymnXmAARcQCeusCY653.jpg
http://s3.运维网.com/wyfs02/M02/6D/E3/wKioL1Vurm6Bz9_ZAARM1mWl5Uo286.jpg
http://s3.运维网.com/wyfs02/M02/6D/E8/wKiom1VurNWhow76AAO1nyNpNus320.jpg
http://s3.运维网.com/wyfs02/M00/6D/E3/wKioL1VurnHiBGMlAAOI6nMnCMk734.jpg
http://s3.运维网.com/wyfs02/M00/6D/E8/wKiom1VurNfz31QzAAK338YawWI467.jpg
http://s3.运维网.com/wyfs02/M01/6D/E3/wKioL1VurnKxqVRbAAI2DXOM9Lg576.jpg
  3.11)启动资源组并进行观察
http://s3.运维网.com/wyfs02/M01/6D/E4/wKioL1VurxijdfrXAALGrrXPAFE312.jpg
http://s3.运维网.com/wyfs02/M01/6D/E8/wKiom1VurYCwQV_IAAQmvcTjTFw929.jpg
http://s3.运维网.com/wyfs02/M02/6D/E4/wKioL1Vurxyyr2ZSAAWfwHRnzJk186.jpg
http://s3.运维网.com/wyfs02/M02/6D/E8/wKiom1VurYXwU480AAUO34iAt-Y607.jpg
  3.12)进行高可用测试:将Test04节点转变状态为standby状态
http://s3.运维网.com/wyfs02/M00/6D/E4/wKioL1Vur-vhVneJAAQvZjsdMPo975.jpg
http://s3.运维网.com/wyfs02/M01/6D/E4/wKioL1Vur-2h3DPvAANqP9AyzO4795.jpg
http://s3.运维网.com/wyfs02/M01/6D/E8/wKiom1VurlTj1BH1AAON-vLytiA692.jpg
  

  现在Test03,Test04都处于standby状态,那么资源只有转移到Test02上,写篇新博文

http://s3.运维网.com/wyfs02/M02/6D/E8/wKiom1Vurlux9-2mAAWfyHhpqLg582.jpg
  

  3.13)切换Test04位active状态,并观察资源是否会转移,还有在Test02上写的博文是否还在
http://s3.运维网.com/wyfs02/M00/6D/E8/wKiom1VuryaS_Y44AAO_itESIfA157.jpg
http://s3.运维网.com/wyfs02/M01/6D/E4/wKioL1VusMKSdbtKAANX9tAGSpQ766.jpg
http://s3.运维网.com/wyfs02/M01/6D/E8/wKiom1VuryjCQ3FUAAN_s3w5sbE250.jpg
  

  

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

  4.1)这种实验模型纯粹是验证heartbeat的用法,没实际意义。
  4.2)实际中httpd,php,mariadb一定会是分离存在,不会集中于一台服务器上,不然像上面实验模型中的构架,没有丁点的扩展余地。
  (ps:有童鞋问:为啥子你不搞个牛X的实验模型,海盗哥只能说:实验平台不给力,陪我6年的ThinkpadR400支撑不起来那么多虚拟机,求赞助)

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

  

  五 上传下海盗哥的ThinkpadR400私照,这位默默陪了我6年伙计
http://s3.运维网.com/wyfs02/M02/6D/E5/wKioL1VuvkLhvo_ZAATDJeDZbRk871.jpg
  

  




页: [1]
查看完整版本: heartbeat(v2)实现LAMP提供wordpress博客站点高可用模型实践