基于corosync+pacemaker 实现web的高可用

简介:

温馨提示:

一篇博文己经介绍过了corosync+pacemaker基本用法,这篇将重点介绍基于corosync+pacemaker的web高可用

---本文大纲

  • 资源分配及拓扑图

  • 实现过程

  • 测试

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

一、资源分配及拓扑图

1、资源分配

系统 主机名 角色 ip地址 关系
Centos 6.5x86_64 essun.maridb1.org 数据库+NFS 192.168.1.110
为两个web节点存储数据与站点
Centos 6.5x86_64 essun.web1.org web 192.168.1.109 apache+php 站点位于1.110
Centos 6.5x86_64 essun.web2.org web 192.168.1.108 apache+php 站点位于1.110

2、拓扑图

wKioL1NgRdvx42TqABVemL9qGC0752.bmp

二、实现过程

注:

主机名(与uname -n相同,节点之间可以解析主机名)

时间同步

无密码登录

1、node1配置过程

  • 己安装的包组

1
2
#yum groupinstall -y "Development tools" "Server Platform Development"
# yum install -y crmsh-1.2.6-4.el6.x86_64.rpm pssh-2.3.1-2.el6.x86_64.rpm
1
2
3
4
5
6
[root@essun . ssh ] # curl -I http://192.168.1.108
HTTP /1 .1 200 OK
Date: Wed, 30 Apr 2014 06:05:04 GMT
Server: Apache /2 .4.9 (Unix)
X-Powered-By: PHP /5 .4.26
Content-Type: text /html

  • 连接数据库测试

1
2
3
4
5
6
7
8
<?php
$link = mysql_connect( '192.168.1.110' , 'root' , 'mysql' );
      if  ($link)
        echo  "Success..." ;
      else
        echo  "Failure..." ;
      mysql_close();
    ?>
1
2
[root@essun web] # curl http://192.168.1.108
Success...
  • 安装corosync、pacemaker

1
#yum install corosync pacemaker

以上步骤出需要在节点web2上执行。

  • 修改corosync的配置文件(/etc/corosync/corosync),增加service区域

1
2
3
4
5
6
[root@localhost download] # cd /etc/corosync/
[root@localhost corosync] # ls
corosync.conf.example       service.d
corosync.conf.example.udpu  uidgid.d
[root@localhost corosync] # cp corosync.conf.example corosync.conf
[root@localhost corosync] # vim corosync.conf
  • 配置结果

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# Please read the corosync.conf.5 manual page
compatibility: whitetank
totem {
     version: 2
     secauth: on
     threads: 0
     interface {
         ringnumber: 0
         bindnetaddr: 192.168.1.1
         mcastaddr: 226.94.1.1
         mcastport: 5405
         ttl: 1
     }
}
logging {
     fileline: off
     to_stderr: no
     to_logfile:  yes
     to_syslog: no
     logfile:  /var/log/cluster/corosync .log
     debug: off
     timestamp: on
     logger_subsys {
         subsys: AMF
         debug: off
     }
}
service {
     ver:0
     name:pacemaker
}
aisexec {
     user :root
     group:root
}
amf {
     mode: disabled
}
  • 生成密钥

1
2
3
4
5
6
7
8
9
[root@localhost corosync] # mv /dev/random /dev/xrandom
[root@localhost corosync] # mv /dev/urandom /dev/random
[root@localhost corosync] # corosync-keygen
Corosync Cluster Engine Authentication key generator.
Gathering 1024 bits  for  key from  /dev/random .
Press keys on your keyboard to generate entropy.
Writing corosync key to  /etc/corosync/authkey .
[root@localhost corosync] # mv /dev/random /dev/urandom
[root@localhost corosync] # mv /dev/xrandom /dev/random
  • 查看一下生成后的文件属性(authkey的属性必须的600否则corosync无法启动)

1
2
3
4
[root@localhost corosync] # ll
total 24
-r-------- 1 root root  128 Apr 30 09:25 authkey
-rw-r--r-- 1 root root  480 Apr 30 09:21 corosync.conf
  • 将配置好的文件复制到节点web2上

1
2
3
4
5
6
7
[root@localhost corosync] # scp authkey corosync.conf essun.web2.org:/etc/corosync/
The authenticity of host  'essun.web2.org (192.168.1.109)'  can't be established.
RSA key fingerprint is b8:9d:cb:7b:4d:ad:c2:fb:a4:00:23:b0:f2:6b:3f:ad.
Are you sure you want to  continue  connecting ( yes /no )?  yes
Warning: Permanently added  'essun.web2.org'  (RSA) to the list of known hosts.
authkey                          100%  128     0.1KB /s    00:00
corosync.conf                    100%  480     0.5KB /s    00:00
  • 启动服务

1
2
3
4
root@essun web] # service pacemaker start
Starting Pacemaker Cluster Manager                         [  OK  ]
[root@essun web] # service corosync start
Starting Corosync Cluster Engine (corosync):               [  OK  ]
  • 查看在线节点

1
2
3
4
5
6
7
8
9
10
[root@essun web] # crm
crm(live) # status
Last updated: Wed Apr 30 15:16:37 2014
Last change: Wed Apr 30 14:21:31 2014 via crmd on essun.web1.org
Stack: classic openais (with plugin)
Current DC: essun.web2.org - partition with quorum
Version: 1.1.10-14.el6_5.3-368c726
2 Nodes configured, 2 expected votes
0 Resources configured
Online: [ essun.web1.org essun.web2.org ]

2、编译mariadb(此文中有详细的介绍)

  • 安装nfs

1
#yum install -y nfs*
  • 指定共享目录

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#mkdir -p /web/share
#vim /etc/exports
/web/share *(insecure,rw,async,no_root_squash)
# exportfs -rav
exporting *:/web/share
# service nfs restart
Shutting down NFS daemon:                                  [  OK  ]
Shutting down NFS mountd:                                  [  OK  ]
Shutting down NFS quotas:                                  [  OK  ]
Shutting down NFS services:                                [  OK  ]
Shutting down RPC idmapd:                                  [  OK  ]
Starting NFS services:                                     [  OK  ]
Starting NFS quotas:                                       [  OK  ]
Starting NFS mountd:                                       [  OK  ]
Starting NFS daemon:                                       [  OK  ]
Starting RPC idmapd:                                       [  OK  ]
  • 安装Discuz

1
2
3
# unzip Discuz_X3.1_SC_UTF8.zip
# mv readme/ upload/ utility/ /web/share/
# chmod -R 777 upload/
  • 挂载到web1上

1
[root@essun download] # mount -t nfs 192.168.1.110:/web/share /www/web/
  • 使用网页访问安装Discuz

    • 第一步

wKiom1NgrjzQ8_0sAAR2CN88M20591.jpg

    • 第二步

wKioL1NgriXRaPF2AAK6qaY44Fw607.jpg

    • 第三步

wKioL1NgrjTRWpd3AAIkOXUVs3U666.jpg

    • 第四步

wKiom1NgrnKBmicnAAJjIbCllvI303.jpg

    • 第五步

wKioL1Ngrl_CzzQ3AANp8a33TC0480.jpg

    • 第六步

wKiom1Ngrpmgdl6xAAMWx75M9QA461.jpg

这样在web1上可以访问了,在web2上只要挂载nfs(1.110:/web/share),在站点目录就可以访问了

3、实现 web高可用

  • 禁用stonith及忽略投票功能

1
2
3
4
5
6
7
8
9
10
11
12
13
crm(live)configure # property stonith-enabled=false
  crm(live)configure # property no-quorum-policy=ignore
crm(live)configure # verify
crm(live)configure # commit
crm(live)configure # show
node essun.web1.org
node essun.web2.org
property $ id = "cib-bootstrap-options"  \
     dc -version= "1.1.10-14.el6_5.3-368c726"  \
     cluster-infrastructure= "classic openais (with plugin)"  \
     expected-quorum-votes= "2"  \
     stonith-enabled= "false"  \
     no-quorum-policy= "ignore"
  • 定义vip

1
2
3
crm(live)configure # primitive webip ocf:heartbeat:IPaddr params ip=192.168.1.100
crm(live)configure # verify
crm(live)configure # commit
  • 挂载文件系统

1
2
3
crm(live)configure # primitive webnfs ocf:heartbeat:Filesystem params device="192.168.1.110://web/share" directory="/www/web" fstype="nfs"  op monitor interval=60s timeout=60s op start timeout=60s op stop timeout=60s
crm(live)configure # verify
crm(live)configure # commit
  • 定义web、php-fpm服务

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
crm(live)configure #  primitive webserver lsb:httpd24
crm(live)configure # verify
crm(live)configure # commit
crm(live)configure # primitive webphp lsb:php-fpm
crm(live)configure # verify
crm(live)configure # commit
crm(live)configure # show
node essun.web1.org
node essun.web2.org
primitive webip ocf:heartbeat:IPaddr \
     params ip= "192.168.1.100"
primitive webnfs ocf:heartbeat:Filesystem \
     params device= "192.168.1.110://web/share"  directory= "/www/web"  fstype= "nfs"  \
     op  monitor interval= "60s"  timeout= "60s"  \
     op  start timeout= "60s"  interval= "0"  \
     op  stop timeout= "60s"  interval= "0"
primitive webphp lsb:php-fpm
primitive webserver lsb:httpd24
property $ id = "cib-bootstrap-options"  \
     dc -version= "1.1.10-14.el6_5.3-368c726"  \
     cluster-infrastructure= "classic openais (with plugin)"  \
     expected-quorum-votes= "2"  \
     stonith-enabled= "false"  \
     no-quorum-policy= "ignore"
  • 将多个资源整合在一起(此处也可以使用排列约束)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
crm(live)configure #  group webservice webip webnfs webserver webphpcrm(live)configure# verify
crm(live)configure # commit
crm(live)configure # show
node essun.web1.org
node essun.web2.org
primitive webip ocf:heartbeat:IPaddr \
     params ip= "192.168.1.100"
primitive webnfs ocf:heartbeat:Filesystem \
     params device= "192.168.1.110:/web/share"  directory= "/www/web"  fstype= "nfs"  \
     op  monitor interval= "60s"  timeout= "60s"  \
     op  start timeout= "60s"  interval= "0"  \
     op  stop timeout= "60s"  interval= "0"
primitive webphp lsb:php-fpm
primitive webserver lsb:httpd24
group webservice webip webnfs webserver webphp
property $ id = "cib-bootstrap-options"  \
     dc -version= "1.1.10-14.el6_5.3-368c726"  \
     cluster-infrastructure= "classic openais (with plugin)"  \
     expected-quorum-votes= "2"  \
     stonith-enabled= "false"  \
     no-quorum-policy= "ignore"

注:

集群内节点资源都不要开机自动启动。

  • 在web1测试一下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
crm(live) # status
Last updated: Wed Apr 30 16:32:55 2014
Last change: Wed Apr 30 16:32:47 2014 via cibadmin on essun.web1.org
Stack: classic openais (with plugin)
Current DC: essun.web2.org - partition with quorum
Version: 1.1.10-14.el6_5.3-368c726
2 Nodes configured, 2 expected votes
4 Resources configured
Online: [ essun.web1.org essun.web2.org ]
  Resource Group: webservice
      webip  (ocf::heartbeat:IPaddr):    Started essun.web1.org
      webnfs (ocf::heartbeat:Filesystem):    Started essun.web1.org
      webserver  (lsb:httpd24):  Started essun.web1.org
      webphp (lsb:php-fpm):  Started essun.web1.org
crm(live) #

三、测试

  • 访问192.168.1.100/upload

wKiom1NgtsnCdMRlAAMpwO-lSa4949.jpg

  • 模拟节点web1故障,看看所有的资源是不是能够转移

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
crm(live)node # standby essun.web1.org
crm(live)node # cd ..
crm(live) # status
Last updated: Wed Apr 30 16:38:07 2014
Last change: Wed Apr 30 16:38:02 2014 via crm_attribute on essun.web1.org
Stack: classic openais (with plugin)
Current DC: essun.web2.org - partition with quorum
Version: 1.1.10-14.el6_5.3-368c726
2 Nodes configured, 2 expected votes
4 Resources configured
Node essun.web1.org: standby
Online: [ essun.web2.org ]
  Resource Group: webservice
      webip  (ocf::heartbeat:IPaddr):    Started essun.web2.org
      webnfs (ocf::heartbeat:Filesystem):    Started essun.web2.org
      webserver  (lsb:httpd24):  Started essun.web2.org
      webphp (lsb:php-fpm):  Started essun.web2.org
  • 结果完全无影响

wKiom1NguQ3gsoBQAAJA1bHTPNU308.jpg











本文转自 jinlinger 51CTO博客,原文链接:http://blog.51cto.com/essun/1405124,如需转载请自行联系原作者
目录
相关文章
|
12月前
|
存储 Apache
Centos7.7下建立无共享存储的WEB集群(pcs+pacemaker+corosync)
Centos7.7下建立无共享存储的WEB集群(pcs+pacemaker+corosync)
42 0
|
Kubernetes NoSQL 开发工具
一寸宕机一寸血,十万容器十万兵|Win10/Mac系统下基于Kubernetes(k8s)搭建Gunicorn+Flask高可用Web集群
2023年,君不言容器技术则已,欲言容器则必称Docker,毫无疑问,它是当今最流行的容器技术之一,但是当我们面对海量的镜像与容器时,怎样快速精准的对海量容器进行管理和编排就又成了新的课题,此时,由Google开源的Kubernetes(读音\[kubə'netis\],业界也有称其k8s的,但k8s其实就是文盲版的Kubernetes,只是因为k和s之间有8个字母)就应时而生了,它是一个开源的用于多个主机虚拟成一个云平台后进行容器资源管理和应用编排引擎,致力于让部署容器化应用简单并且高效,提供了应用的全生命周期管理,如应用部署,规划,更新,维护等机制。本次我们尝试在Win10/Mac系统下,
一寸宕机一寸血,十万容器十万兵|Win10/Mac系统下基于Kubernetes(k8s)搭建Gunicorn+Flask高可用Web集群
|
测试技术 iOS开发
Flutter Web网站之最简方式实现暗黑主题无缝切换
Flutter Web网站之最简方式实现暗黑主题无缝切换
273 0
Flutter Web网站之最简方式实现暗黑主题无缝切换
|
消息中间件 网络协议 前端开发
SpringBoot轻松整合WebSocket,实现Web在线聊天室
前面为大家讲述了 Spring Boot的整合Redis、RabbitMQ、Elasticsearch等各种框架组件;随着移动互联网的发展,服务端消息数据推送已经是一个非常重要、非常普遍的基础功能。今天就和大家聊聊在SpringBoot轻松整合WebSocket,实现Web在线聊天室,希望能对大家有所帮助。
SpringBoot轻松整合WebSocket,实现Web在线聊天室
|
JSON 算法 数据安全/隐私保护
Python:使用PyJWT实现JSON Web Tokens加密解密
Python:使用PyJWT实现JSON Web Tokens加密解密
251 0
|
Python
Python 实现Web隐藏目录扫描
**Web隐藏目录扫描:** 首先你需要自己寻找一个靠谱的字典,放入脚本根目录并命名为`dict.log`每行一个路径名称.
140 0
|
安全 算法 生物认证
Python 实现Web容器指纹识别
当今的Web安全行业在进行渗透测试时普遍第一步就是去识别目标网站的指纹,从而进一步根据目标框架进行针对性的安全测试,指纹识别的原理其实很简单,目前主流的识别方式有下面这几种。
470 0
Python 实现Web容器指纹识别
|
前端开发 JavaScript API
借助 Web Animations API 实现一个鼠标跟随偏移动画
借助 Web Animations API 实现一个鼠标跟随偏移动画
233 0
借助 Web Animations API 实现一个鼠标跟随偏移动画
|
机器学习/深度学习 传感器 人工智能
web端实现AR人脸特效
直播、短视频、在线会议等应用越来越多地进入人们的生活,随之诞生的是丰富的各类创意玩法与新鲜体验,其中大量应用了以AI检测和图形渲染为基础的AR技术。
232 0
web端实现AR人脸特效
|
Java Maven 开发工具
毕业设计:基于Web实现多用户宿舍管理系统
毕业设计:基于Web实现多用户宿舍管理系统
119 0
毕业设计:基于Web实现多用户宿舍管理系统