设为首页 收藏本站
查看: 1021|回复: 0

[经验分享] heartbeat(v2)实现LAMP提供wordpress博客站点高可用模型实践

[复制链接]
发表于 2019-1-7 13:45:47 | 显示全部楼层 |阅读模式
              友情提醒:本文实验环境 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/16
LAMP组合节点配置有LAMP组合,参与heartbeat高可用集群
Test04.lijun.com  eth1:192.168.100.4/24
eth0:172.16.34.4/16
LAMP组合节点配置有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掌托处热的可以煎鸡蛋啦!!)
  实验拓扑:


  三 实验步骤:
  各节点上IP配置,网卡桥接,yum配置文件设定这里就不演示了,自行解决。

  3.1)Test01上提供共享存储:
  添加2块新磁盘,做贡献分区使用:

  新磁盘分别系统识别为/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
[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配置:
  3.3.1)关闭防火墙和selinux,防止干扰实验进行
[root@Test02 ~]#service iptables stop
[root@Test02 ~]#setenforce 0  3.3.2)配置ntp时间同步:
[root@Test02 ~]# ntpdate 172.16.0.1
31 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)配置/etc/hosts文件,实现集群节点间域名和IP的互相解析
[root@Test02 ~]# 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互信

[root@Test02 ~]# ssh-keygen -t rsa -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)安装httpd和php软件
[root@Test02 ~]#yum -y install httpd php php-mysql
[root@Test02 ~]#chkconfig --add httpd
[root@Test02 ~]#chkconfig httd off  3.3.6)修改httpd的配置文件
[root@Test02 ~]# cd /etc/httpd/conf
[root@Test02 conf]# scp httpd.conf{,.bak}
[root@Test02 conf]# 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[root@Test02 source]# 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@Test02 mysql]#mkdir /etc/mysql
[root@Test02 mysql]# cp support-files/my-medium.cnf  /etc/mysql/my.cnf
[mysqld]
#添加
datadir = /mydata/data
innodb_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 start
Starting MySQL...                                          [  OK  ]
[root@Test02 mysql]# service mariadb stop
Shutting 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程序的安装
[root@Test02 mysql]#mount -t nfs 192.168.100.1:/web /var/www/html
[root@Test02 mysql]#cd  /var/www/html
[root@Test02 html]# unzip wordpress-3.0.4-zh_CN.zip
[root@Test02 html]# mv wordpress/* .
[root@Test02 html]# scp wp-config-sample.php wp-config.php 修改文件如下
[root@Test02 html]# 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[root@Test02 www]# /etc/init.d/mariadb start
Starting MySQL...                                          [  OK  ]
[root@Test02 www]# 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[root@Test02 www]# service httpd start
Starting httpd:                                            [  OK  ]
[root@Test02 www]#  3.3.9)client上浏览器测试





[root@Test02 html]# /etc/init.d/mariadb stop
Shutting down MySQL.                                       [  OK  ]
[root@Test02 html]# service httpd stop
Stopping httpd:                                            [  OK  ]
[root@Test02 html]#  3.3.10)安装heartbeat相关组件
[root@Test02 html]#yum -y install net-snmp-libs libnet PyXML libtool-ltdl
[root@Test02 html]#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 heartbeat2]#  3.3.11)配置heartbeat
[root@Test02 heartbeat2]#cd /etc/ha.d
[root@Test02 ha.d]#cp -a /usr/share/doc/heartbeat-2.1.4/ha.cf   .
[root@Test02 ha.d]#cp -a /usr/share/doc/heartbeat-2.1.4/authkeys    .[root@Test02 ha.d]#openssl rand -hex 8
50c60f2f91918f4d
[root@Test02 ha.d]#vim authkeys
#修改如下
auth 2
2 sha1 50c60f2f91918f4d
[root@Test02 ha.d]#chmod 600 authkeys[root@Test02 ha.d]# 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防止干扰
[root@Test03 ~]#service iptables stop
[root@Test03 ~]#setenforce 0  3.4.2)同步时间
[root@Test03 ~]# ntpdate 172.16.0.1
31 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)配置/etc/hosts文件,实现域名与IP的本地解析
[root@Test03 ~]# 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互信
[root@Test03 ~]# ssh-keygen -t rsa -P ''
[root@Test03 ~]#ssh-copy-id -i /root/.ssh/id_rsa.pub Test02
[root@Test03 ~]#ssh-copy-id -i /root/.ssh/id_rsa.pub Test04  3.4.5)安装httpd和php组件
[root@Test03 ~]#yum -y install httpd php php-mysql
[root@Test03 ~]#chkconfig --add httpd
[root@Test03 ~]#chkconfig httpd off  3.4.6)设定httpd配置文件
[root@Test03 ~]#cd /etc/httpd/conf
[root@Test03 conf]#rm -rf httpd.conf
[root@Test03 conf]#scp Test02:/etc/httpd/conf/httpd.conf  .  3.4.7)安装mariadb数据库
[root@Test03 conf]#cd /root/source
[root@Test03 source]# groupadd -g 27 mysql
[root@Test03 source]# useradd -g 27 -u 27 -r mysql
[root@Test03 source]# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local[root@Test03 source]# cd /usr/local/
[root@Test03 local]# ln -sv mariadb-5.5.43-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.43-linux-x86_64'
[root@Test03 local]# cd mysql/
[root@Test03 mysql]# chown -R root.mysql ./*[root@Test03 mysql]# mkdir /etc/mysql
[root@Test03 mysql]# scp Test02:/etc/mysql/my.cnf /etc/mysql/
my.cnf                                             100% 4963     4.9KB/s   00:00   
[root@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)安装heartbeat组件
[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 heartbeat2]#  3.4.9)为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)Test04上配置
  3.5.1)关闭iptables和selinux防止干扰实验
[root@Test04 ~]#service iptables stop
[root@Test04 ~]#setenforce 0  3.5.2)时间同步
[root@Test04 ~]# ntpdate 172.16.0.1
31 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)配置集群节点IP与域名的本地互相解析
[root@Test04 ~]# 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)配置集群节点间互信
[root@Test04 ~]# 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)安装httpd和php组件
[root@Test04 ~]#yum -y install httpd php php-mysql
[root@Test04 ~]#chkconfig --add httpd
[root@Test04 ~]#chkconfig httpd off  3.5.6)设定httpd配置文件
[root@Test04 ~]#cd /etc/httpd/conf
[root@Test04 conf]#rm -rf httpd.conf
[root@Test04 conf]#scp Test02:/etc/httpd/conf/httpd.conf  .  3.5.7)安装mariadb:
[root@Test04 ~]## groupadd -g 27 mysql
[root@Test04 ~]## useradd -g 27 -u 27 -r mysql[root@Test04 ~]#cd /root/source
[root@Test04 source]# tar -xf mariadb-5.5.43-linux-x86_64.tar.gz -C /usr/local
[root@Test04 source]# cd /usr/local/
[root@Test04 local]# ln -sv mariadb-5.5.43-linux-x86_64 mysql
`mysql' -> `mariadb-5.5.43-linux-x86_64'
[root@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                                             100% 4963     4.9KB/s   00:00   
[root@Test04 mysql]# scp Test02:/etc/init.d/mariadb /etc/init.d/
mariadb                                            100%   12KB  11.9KB/s   00:00   
[root@Test04 mysql]# mkdir /mydata[root@Test04 mysql]# chkconfig --add mariadb
[root@Test04 mysql]# chkconfig mariadb  off  3.5.8)安装heartbeat组件
[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@Test04 heartbeat2]#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)为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)Test02上安装heartbeat-gui包进行图形化配置

[root@Test02 ha.d]# rpm -ivh /root/source/heartbeat-gui-2.1.4-12.el6.x86_64.rpm
[root@Test02 ha.d]#echo 'redhat' | passwd --stdin hacluster  3.7)在集群节点上启动heartbeat服务
[root@Test02 ha.d]# 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程序观察



  

  3.10)借助heartbeat-gui工具进行资源和约束配置
  *这里借助资源类型为“组”的进行建立。一定要先建立“组”再建立相应的资源。
   “组”中资源的建立顺序默认情况下带有order和colocation约束,一定要注意建立的先后顺序。

  








  3.11)启动资源组并进行观察




  3.12)进行高可用测试:将Test04节点转变状态为standby状态



  

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


  

  3.13)切换Test04位active状态,并观察资源是否会转移,还有在Test02上写的博文是否还在



  

  

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

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

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

  

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

  

  





运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-660395-1-1.html 上篇帖子: debian8下配置postgresql9.5.2、pgpool3.5.2、heartbeat3.0.5的HA热备 下篇帖子: ESXI 丛集出现HA HEARTBEAT DATASTORES数量错误, 但找不到VSPHERE HA ADVANCED OPTION按钮? 用POWERCL
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表