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

[经验分享] 搭建高可用集群drbd同步存储和apache服务

[复制链接]

尚未签到

发表于 2018-11-27 09:59:49 | 显示全部楼层 |阅读模式
  pacemaker介绍: pacemaker是一个集群资源管理器.它检测集群节点和恢复节点来保证集群服务的高可用性,它可以结合corosync或heartbeat来实现通信和关系管理
Pacemaker包​含​以​下​的​关​键​特​性​ :
     · 监​测​并​恢​复​节​点​和​服​务​级​别​的​故​障​
     · 支​持​使​用​STONITH来​保​证​数​据​一​致​性​。​
     · clusters支​持​quorate(法​定人​数​)或​ resource(资​源​ )驱​动​的​集​群​
     · 支​持​任​何​的​冗​余​配​置​
     · 自​动​同​步​各​个​节​点​的​配​置​文​件​
     · 统​ 一​的​ ,可​脚​本​控​制​的​cluster shell

Pacemaker本​身​由​四​个​关​键​组​件​组​成​ :
     · CIB (aka. 集​群​信​息​基​础​)
     · CRMd (aka. 集​群​资​源​管​理​守​护​进​程​)
     · PEngine (aka. PE or 策​略​引​擎​ )
     · STONITHd
     ·
搭建高可用平台
station41.example.com  192.168.10.41 主节点
station42.example.com  192.168.10.42 备用节点
在 RHEL5.4里没有pacemaker和corosync套件,所以得下载
下载在线yum 仓库,直接用yum命令安装
wget -O /etc/repos.d/pacemaker.repo  http://clusterlabs.org/rpm/
epel-5/clusterlabs.repo
pacemaker.repo的内容如下
[clusterlabs]
name=High Availability/Clustering server
baseurl=http://www.clusterlabs.org/rpm/epel-5
gpgcheck=0

yum install pacemaker corosync --skip-broken -y
会发现如下错误,导致pacemaker不能安装
Missing Dependency: libesmtp.so.5 is needed by package
pacemaker-1.0.11-1.2.el5.i386 (clusterlabs)
安装libesmtp套件
wget ftp://ftp.univie.ac.at/systems/linux/fedora/epel/5/i386/
libesmtp-1.0.4-5.el5.i386.rpm
rpm -ivh libesmtp-1.0.4-5.el5.i386.rpm
yum install pacemaker corosync -y
(以上步骤在主/备节点上完成)
corosync-keygen生成authkey,用来节点间的通信,它会告诉你authkey文件
生成在/etc/corosync目录下
  scp /etc/corosync/authkey  station42:/etc/corosync
修改配置文件corosync.conf
cd /etc/corosync
cp corosync.conf.example  corosync.conf
vi /etc/corosync/corosync.conf
# Please read the corosync.conf. 5 manual page
compatibility:whitetank
totem {
version: 2
secauth: off
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168. 10.0(根据具体情况修改)
mcastaddr: 226. 94.1. 1
mcastport: 5405(根据具体情况修改)
}
}
logging {
fileline: off
to_stderr: yes
to_logfile: yes
to_syslog: yes
logfile: /var/log/corosync.log (/var/log/cluster/corosync.log)
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
amf {
mode: disabled
}
service {
# Load the Pacemaker Cluster Resource Manager
ver: 0
name: pacemaker
use_mgmtd: yes
}
scp corosync.conf  station43:/etc/corosync/
在主/备节点上启动启动 corosync
/etc/init.d/corosync start
  注意:
  1.配置文件里的logfile参数如果是/var/log/cluster/corosync.log,则会启动不了,
原因就是没有建立/var/log/cluster目录
2. 启动后查看日志文件,会发现corosync[2200]:  [SERV ] Service failed to load pacemaker'.加载 pacemaker 失败. 看了好多其他文档,都没有这个错误.弄了一个上午,才发现没有安装 net-snmp 套件(它不会自动安装)

到这里平台搭建好了,来浏览一下现有配置
介绍 crm 工具
当我们键入命令crm时,会进入一个交互式shell模式,它跟 linux的shell相似, 不了解命令时使用help命令查看帮助,如configure help
以下步骤在主节点上进行
#crm configure show
node station41.example.com
node station42.example.com
property $id="cib-bootstrap-options" \
    dc-version="1.1.5bdd89e69ba545404d02445be1f3d72e6a203ba2f" \
    cluster-infrastructure="openai s" \
    expected-quorum-votes="2"
检查配置文件
#crm_verify -L
crm_verify[2195]: 2011/08/24_ 16:57: 12 ERROR: unpack_resources: Resource
start-up disabled since no STONITH resources have been defined
crm_verify[2195]: 2011/08/24_ 16: 57:12 ERROR: unpack_resources: Ei ther
configure some or disable STONITH with the stonith-enabled option
crm_verify[2195]: 2011/08/24_ 16: 57: 12 ERROR: unpack_resources: NOTE:
Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid -V may provide more detail s
这里出现错误正常,原因是 stonith,这里禁用它,如果要配置 stonith,可参考网站
http://www.clusterlabs.org/doc/zh-CN/Pacemaker/1.1/html/Clusters_ from_Scratch/index. html
#crm (进入交互模式)
crm(live)# configure property stonith-enabled=false, 再检查配置文件就没有错误了
  
添加一个VIP资源(虚拟 ip,不能被占用,用于外界的访问)
crm (进入交互模式)
crm(live)#configure(进入配置资源模式)
crm(live)configure#primitive clusterip ocf:heartbeat:IPaddr2 \
params ip=192.168.10.2 cidr_ netmask=32 nic=eth0:0 \
op monitor interval=30s(定义资源,名称是clusterip,ocf:heartbeat:Ipaddr2
调用脚本/usr/lib/ocf/resource.d/heartbeat/IPaddr2, 虚拟ip 192.168.10. 2, 每 30s检查一次)
  使用 ifconfig 查看多了一个虚拟ip
做一次失效备援
/etc/init.d/corosync stop
crm status 会发现服务没被备用节点接管, 是因为集群没有达到法定人数.为了数据避免 遭到破坏,当 pacemaker 发现集群达不到法定人数时,就会停止所有资源
当&#8203;有&#8203;半&#8203;数&#8203;以&#8203;上&#8203;的&#8203;节&#8203;点&#8203;在&#8203;线&#8203;时&#8203; ,这&#8203;个&#8203;集&#8203;群&#8203;就&#8203;认&#8203;为&#8203;自&#8203;己&#8203;拥&#8203;有&#8203;法&#8203;定&#8203;人&#8203;数&#8203;了&#8203; ,是&#8203;“&#8203;合&#8203; 法&#8203;”&#8203;的&#8203; ,换&#8203; 而&#8203;言&#8203;之&#8203;就&#8203;是&#8203;公&#8203;式&#8203;: total_nodes < 2*active_nodes
因&#8203;此&#8203;在&#8203;双&#8203;节&#8203;点&#8203;的&#8203;集&#8203;群&#8203;中&#8203;,只有当&#8203;两&#8203;者&#8203;都&#8203;在&#8203;线&#8203;时&#8203;才&#8203;是&#8203;合&#8203;法&#8203;的&#8203; .&#8203;这&#8203;个&#8203;规&#8203;则&#8203;会&#8203;让&#8203;双&#8203;节点&#8203;的&#8203;集&#8203; 群&#8203;毫&#8203;无&#8203;意&#8203;义&#8203; ,但&#8203;是&#8203;我&#8203;们&#8203;可&#8203;以&#8203;控&#8203;制&#8203;Pacemaker发&#8203;现&#8203;集&#8203;群&#8203;达&#8203;不&#8203;到&#8203;法&#8203;定&#8203;人&#8203;数&#8203;时&#8203;候&#8203;的&#8203;行&#8203; 为&#8203;. 简&#8203;单&#8203;来&#8203;说&#8203; ,我&#8203;们&#8203;告&#8203;诉&#8203;集&#8203;群&#8203;忽&#8203;略&#8203;它&#8203; 。&#8203;
crm configure property no-quorum-policy=ignore
crm configure show(显示配置)
crm status(查看运行状态)
... ...
clusterip (ocf::heartbeat:IPaddr): Started station42.example.com
此时服务迁移过去了
/etc/init.d/corosync start
crm status
... ...
clusterip (ocf::heartbeat:IPaddr): Started station41.example.com
当主节点恢复时, 资源自动迁移到主节点
当然了,也可以使用这条命令来阻止支援在节点恢复后的移动
crm configure rsc_defaults resource-stickiness=100
(最好不要这样做)
  
添加apache服务资源
在主/备节点上进行
yum install httpd -y
echo `hostname` >/var/www/html/index.html
为了监控 apache 的健康状况,需修改apache配置文件
将注释去掉

      SetHandler server-status
      Order deny,allow
      Deny from all
      Allow from 127.0.0.1

在主节点上配置
crm configure primitive website ocf:heartbeat:apache \
params configfile=/etc/httpd/conf/httpd.conf op monitor interval=1min
添加一个资源,名称是 website,调用叫 做 apache 的 ocf 脚本,在 heartbeat 名字空间里, 指定配置文件,每 60s 检查一次
crm status
  ......
clusterip      (ocf::heartbeat:IPaddr):    Started station41.example.com
website       (ocf::heartbeat:apache):    Started station42.example.com
会发现资源没有在同一主机上运行,为了确保资源在同一台主机上运行,运行下面命令
crm configure colocation website-with-ip inf: website clusterip
crm status
... ...
clusterip   (ocf::heartbeat:IPaddr):    Started station41.example.com
website     (ocf::heartbeat: apache):  Started station41.example.com
此时发现资源在同一主机上运行
可以打开浏览器来测试下,输入vip 192.168. 10.2,显示station41.example. com
/etc/ini t. d/corosync stop,显示的是 station42.example.com
控制资源的启动停止顺序
crm configure order apache-after-ip inf: clusterip website
(开启从左到右,关闭时从右到左)
指定优先 l ocation(机器配置不一样时,可以指定资源优先在处理性能好的机器上)
crm configure location prefer-pcmk-1 website 50: pcmk-1
  
添加 DRBD 同步存储资源
配置 DRBD 的步骤可参考《使用 DRBD 同步磁盘》这篇文档
在集群中配置 DRBD
crm
crm(live)#configure primitive webdata ocf:linbit:drbd \
params drbd_resource=r0 \
op monitor interval=60s
crm(live)#configure ms webdataclone webdata meta master-max=1 master-node-max=1 \
        clone-max=2 clone-node-max=1 notify=true
crm(live)#configure show
crm(live)#commit
crm status
……
Master/Slave Set: WebDataClone
Masters: [ station41.example.com ]
Sl aves: [ station42.example.com]
  
配置一个 Filesystem 资源来使用drbd
crm
crm(live)#configure primitive webfs ocf:heartbeat:Filesystem \
params device=&quot;/dev/drbd1&quot; directory=&quot;/var/www/html&quot; fstype= &quot;ext3&quot;
  crm(live)# configure colocation fs_on_drbd inf: webfs webdataclone:Master
crm(live)#configure order webfs-after-webdata inf: webdataclone:promote webfs:start
crm(live)# configure colocation website-with-webfs inf: website webfs
crm(live)# configure order website-after- webfs inf: webfs website
  crm(live)# configure commi t
  测试
  crm node standby
  crm status
  ... ...
  Node station41.example.com: standby
  Online: [station42.example.com]
  clusterip  (ocf::heartbeat:IPaddr):  Started station42.example.com
  website (ocf::heartbeat:apache):
  Started station42.example.com
  Master/Slave Set: webdataclone
  Masters: [ station42.example.com]
  Stopped: [ webdata:1 ]
  webfs(ocf::heartbeat:Filesystem):     Started station42.example.com
  
  crm node online
  crm status
  ... ...
  Node station42.example.com: standby
  Online: [station41.example.com]
  clusterip  (ocf::heartbeat:IPaddr):  Started station41.example.com
  website (ocf:: heartbeat: apache):   Started station41.example.com
  Master/Slave Set:webdataclone
  Masters: [ station41.example.com]
  Stopped: [ webdata:1]
  webfs (ocf::heartbeat:Filesystem):   Started station41.example.com
  参考网站
  http://www.clusterlabs.org/doc/zh-CN/Pacemaker/1.1/html/Clusters_ from_Scratch/index.html




运维网声明 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-640162-1-1.html 上篇帖子: apache的多站点虚拟主机配置方法 下篇帖子: Apache两种常用工作模式比较:prefork和worker
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

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

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

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

扫描微信二维码查看详情

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


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


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


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



合作伙伴: 青云cloud

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