基于corosync+pacemaker实现主从高可用集群
本实验由两个节点组成高可用主从集群,在实际中不常用,目的是通过实验来加深对corosync的认识和理解。
- node1:node1.magedu.com
- ip 172.16.14.10
- node2:node2.magedu.com
- ip 172.16.14.11
- VIP 172.16.14.2
1、DNS域名解析
- 用uname -n的结果来识别对方的名字
- 使node1,node2的uname -n分别为:
- node1.magedu.com
- node2.magedu.com
- node1:
- # sed -i 's@\(HOSTNAME=\).*@\1node1.magedu.com@g' /etc/sysconfig/network
- # hostname node1.magedu.com
- node2:
- # sed -i 's@\(HOSTNAME=\).*@\1node2.magedu.com@g' /etc/sysconfig/network
- # hostname node2.magedu.comm
- 在/etc/hosts添加:
- 172.16.14.10 node1.magedu.com node1
- 172.16.14.11 node2.magedu.com node2
- 在node1上:
- ssh-keygen -t rsa -P ''
- ssh-copy-id -i ~/.ssh/id_rsa root@node2
- 命令测试:
- ssh node2 'ifconfig'
- 然后再实现node2对node1的通信
- [root@node2 ~]# date 112822022012;ssh node1 'date 112822022012'
- Fri Nov 28 22:02:00 CST 2012
- Fri Nov 28 22:02:00 CST 2012
4、在node1,node2上安装httpd
- # yum -y install httpd
- 建立测试页面,为了便于区分,将页面结果设置为不同内容
- node1上:
- 编辑/var/www/html/index.html写入:
- <h1>node1</h1>
- node2:
- 编辑/var/www/html/index.html写入:
- <h1>node2</h1>
- service httpd stop
- chkconfig httpd off
- 关闭selinux
- setenforce 0
- cluster-glue
- cluster-glue-libs
- heartbeat
- openaislib
- resource-agentsyyu
- corosync
- heartbeat-libs
- pacemaker
- corosynclib
- libesmtp
- pacemaker-libs
- # yum -y --nogpgcheck localinstall *.rpm
- # cd /etc/corosync
- # cp corosync.conf.example corosync.conf
- # vim corosync.conf
- 作如下修改:
- version: 2 ##版本
- secauth: on
- threads: 1 ##线程数
- bindnetaddr: 172.16.0.0 ##绑定的网段
- mcastaddr: 226.94.14.14 ##使用的组播地址
- to_syslog: no ##是否将日志发送到日志文件系统
- //添加这个service可以实现pacemaker随corosync的启动而自动启动
- service {
- ver: 0
- name: pacemaker
- }
- //定义ais的辅助运行用户和组的
- aisexec {
- name: root
- group: root
- }
- # corosync-keygen
- 将corosync和authkey复制至node2:
- # scp -p corosync.conf authkey node2:/etc/corosync/
- 分别为两个节点创建corosync生成的日志所在的目录:
- # mkdir /var/log/cluster
- # ssh node2 'mkdir /var/log/cluste
- # service corosync start
- #tail -50 /var/log/messages ##查看日志信息
- # ssh node2 -- /etc/init.d/corosync start ##启动node2
- [root@node1 corosync]# crm
- crm(live)# status
- Current DC: node1.magedu.com - partition with quorum
- Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
- 2 Nodes configured, 2 expected votes
- 0 Resources configured.
- ============
- Online: [ node1.magedu.com node2.magedu.com ]
- [root@node1 ~]# crm
- crm(live)# help
- This is the CRM command line interface program.
- Available commands: ##crm使用的子命令
- cib manage shadow CIBs ##集群信息库
- resource resources management ##资源管理
- configure CRM cluster configuration ##集群配置
- node nodes management ##节点管理
- options user preferences
- ra resource agents information center ##资源代理
- status show cluster status ##显示集群状态信息
- quit,bye,exit exit the program ##退出程序
- help show help ##帮助信息
- end,cd,up go back one level ##返回上一层
- 最常用的有:
- 1、集群的配置用configure:
- crm(live)# configure ##进入资源配置命令
- crm(live)configure# help
- primitive define a resource ##定义资源
- group define a group ##定义组
- location a location preference ##位置约束
- colocation colocate resources ##排列约束
- order order resources ##顺序约束
- show display CIB objects ##显示信息
- edit edit CIB objects ##进入编辑模式
- delete delete CIB objects ##删除cib对象
- commit commit the changes to the CIB ##提交信息
- verify verify the CIB with crm_verify ##检查语法错误
- 2、资源代理RA的信息:
- crm(live)configure# cd
- crm(live)# ra
- crm(live)ra# help
- Available commands:
- classes list classes and providers ##资源代理的类别
- list list RA for a class (and provider) ##显示每个类别的所有RA
- meta show meta data for a RA ##资源代理的元数据
- providers show providers for a RA and a class ##资源代理的提供者
- quit exit the program
- help show help
- end go back one level
- crm(live)ra# classes ##显示四种资源代理类别
- heartbeat ##heartbaet V1版本
- lsb ## linux标准库
- ocf / heartbeat pacemaker ##Open cluster Framework 开放集群架构
- stonith ##专为配置stonith设备而用
- crm(live)ra# list lsb ##用list可以查看每个类别的
- crm(live)ra# list ocf
- AoEtarget AudibleAlarm CTDB
- ClusterMon Delay Dummy
- crm(live)ra# list ocf heartbeat ##查看ocf下的子类别
- AoEtarget AudibleAlarm CTDB
- ClusterMon Delay Dummy
- EvmsSCC Evmsd Filesystem
- ICP IPaddr IPaddr2
- //只显示部分;IPaddr是ocf类别下heartbeat子类别的资源代理;用于IP的代理;下面我们将用到
- crm(live)ra# meta ocf:heartbeat:IPaddr ##用meta查看某个具体资源代理的属性
- ##使用方式 类别:子类别:资源代理
- Parameters (* denotes required, [] the default): ##*表示必选的,[]表示默认值
- ip* (string): IPv4 address ##使用的参数;*表示必选的
- The IPv4 address to be configured in dotted quad notation, for example
- "192.168.1.1".
- ...............
- Operations' defaults (advisory minimum): ##默认的操作
- start timeout=20s ##启动超时时间
- stop timeout=20s ##停止超时时间
- monitor interval=5s timeout=20s ##每隔5s监视一次,20s是超时时间
- 配置1个全局属性:
- crm
- configure
- property stonith-enabled=false ##是否启用stonish设备
- verify ##检查语法
- commit ##提交
- 接下来开始配置资源了:
- 定义资源用primitive,help一下:
- crm(live)configure# help primitive
- Usage:
- ...............
- primitive <rsc> [<class>:[<provider>:]]<type>
- 资源 RA类别:提供者:哪个类型的RA
- [params attr_list] ##params是关键字,指定参数
- [meta attr_list] ##元数据属性
- [utilization attr_list]
- [operations id_spec] ##操作
- [op op_type [<attribute>=<value>...] ...] ##指定额外的属性;如超时时长
- crm(live)configure# primitive WebIP ocf:heartbeat:IPaddr params ip="172.16.14.2"
- crm(live)configure# verify
- crm(live)configure# commit
- crm(live)configure# show
- node node1.magedu.com
- node node2.magedu.com
- primitive WebIP ocf:heartbeat:IPaddr \
- params ip="172.16.14.2"
- property $id="cib-bootstrap-options" \
- dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
- cluster-infrastructure="openais" \
- expected-quorum-votes="2" \
- stonith-enabled="false"
- crm(live)configure# cd
- crm(live)# status ##状态查看
- ============
- Last updated: Sat Dec 1 11:12:19 2012
- Stack: openais
- Current DC: node1.magedu.com - partition with quorum
- Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
- 2 Nodes configured, 2 expected votes
- 1 Resources configured.
- ============
- Online: [ node1.magedu.com node2.magedu.com ]
- WebIP (ocf::heartbeat:IPaddr): Started node1.magedu.com
- //发现WebIP运行在node1上
- //ifconfig查看;172.16.14.2在node1上
- [root@node1 ~]# ifconfig
- eth0:0 Link encap:Ethernet HWaddr 00:0C:29:76:E9:56
- inet addr:172.16.14.2 Bcast:172.16.255.255 Mask:255.255.0.0
- UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
- Interrupt:67 Base address:0x2000
- crm(live)configure# primitive WebServer lsb:httpd
- crm(live)configure# verify
- crm(live)configure# commit
- crm(live)configure# show
- node node1.magedu.com
- node node2.magedu.com
- primitive WebIP ocf:heartbeat:IPaddr \
- params ip="172.16.14.2"
- primitive WebServer lsb:httpd ##显示WebServe
- property $id="cib-bootstrap-options" \
- dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
- cluster-infrastructure="openais" \
- expected-quorum-votes="2" \
- stonith-enabled="false"
- crm(live)configure# cd
- crm(live)# status
- WebIP (ocf::heartbeat:IPaddr): Started node1.magedu.com
- WebServer (lsb:httpd): Started node2.magedu.com
- //发现WebServer在node2上;默认资源是负载均衡模式的。多个
- 资源运行在多个节点上的,我们要想把资源运作在一个节点上;
- 可以通过定义组来实现:
- 下面将WebIP,WebServer定义在一个Webservice组中;
- crm(live)configure# group Webservice WebIP WebServer
- crm(live)configure# cd
- crm(live)# status
- Resource Group: Webservice ##发现Webservice
- WebIP (ocf::heartbeat:IPaddr): Started node1.magedu.com
- WebServer (lsb:httpd): Started node1.magedu.com
- //有上面得知,定义组后WebIP, WebServer都运行在node1上了
- //通过访问172.16.14.2,只显示node1的页面内容;
- 把node1为standby:
- [root@node1 ~]# crm node standby
- [root@node1 ~]# crm status
- ============
- Last updated: Sat Dec 1 11:46:27 2012
- Stack: openais
- Current DC: node1.magedu.com - partition with quorum
- Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
- 2 Nodes configured, 2 expected votes
- 1 Resources configured.
- ============
- Node node1.magedu.com: standby ##node1已为standby
- Online: [ node2.magedu.com ]
- Resource Group: Webservice
- WebIP (ocf::heartbeat:IPaddr): Started node2.magedu.com
- WebServer (lsb:httpd): Started node2.magedu.com
- //说明资源都转移到node2上面了
- //此时页面也显示为node2的测试内容了
- 这样就完成了角色转换了
- 下面让node2为standby:node1为online:
- [root@node1 ~]# crm node online
- [root@node1 ~]# crm status
- ============
- Last updated: Sat Dec 1 12:12:56 2012
- Stack: openais
- Current DC: node1.magedu.com - partition with quorum ##没有达到法定票数
- Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
- 2 Nodes configured, 2 expected votes
- 1 Resources configured.
- ============
- Node node2.magedu.com: standby
- Online: [ node1.magedu.com ]
- Resource Group: Webservice
- WebIP (ocf::heartbeat:IPaddr): Started node1.magedu.com
- WebServer (lsb:httpd): Started node1.magedu.com
- //对于两个节点的集群,不具备法定票数也允许运行;有以下措施:
- crm(live)configure# property no-quorum-policy=ignore ##不具备法定票数忽略
- crm(live)configure# verify
- crm(live)configure# commit
- crm(live)resource# stop Webservice ##停止资源运行
- crm(live)resource# cd
- crm(live)# configure
- crm(live)configure# delete Webservice
- 提交查看结果;
- WebIP,WebServer又以独立资源运行起来了
- 1)、定义排序约束;(两个资源必须在一起或不在一起)
- crm(live)configure# colocation WebServer_with_WebIP inf:
- WebServer WebIP
- 提交后查看:
- crm(live)configure# show xml
- <rsc_colocation id="WebServer_with_WebIP" rsc="WebServer"
- score="INFINITY" with-rsc="WebIP"/>
- //说明这两个资源必须在一起
- crm(live)# status
- Online: [ node1.magedu.com node2.magedu.com ]
- WebIP (ocf::heartbeat:IPaddr): Started node1.magedu.com
- WebServer (lsb:httpd): Started node1.magedu.com
- // 两个资源在一个节点运行
- //通过浏览去访问为node1的页面
- 让节点1为standby:
- crm(live)# node standby
- crm(live)# status
- WebIP (ocf::heartbeat:IPaddr): Started node2.magedu.com
- WebServer (lsb:httpd): Started node2.magedu.com
- //资源转移到node2上
- 2)、用顺序约束可以让资源按一前一后顺序启动:
- crm(live)configure# order WebServer_after_webIP mandatory: WebIP
- WebServer
- crm(live)configure# verify
- crm(live)configure# commit
- crm(live)configure# show xml
- <rsc_order first="WebIP" id="WebServer_after_webIP"
- score="INFINITY" then="WebServer"/>
- //先启动WebIP;再启动WebServe
- 3)、用位置约束定义一个资源停留在一个节点上的倾向性有多大
- crm(live)configure# location WebIP_on_node1 WebIP 500:
- node1.magedu.com
- //WebIP停留在node1的倾向值为500;
- crm(live)configure# verify
- crm(live)configure# commit
- crm(live)configure# show
- crm(live)# node standby ##节点1standby
- crm(live)# status
- Node node1.magedu.com: standby
- Online: [ node2.magedu.com ]
- WebIP (ocf::heartbeat:IPaddr): Started node2.magedu.com
- WebServer (lsb:httpd): Started node2.magedu.com
- //资源转移到node2上
- crm(live)# node online ##node1为online;发现资源回到node1上
- crm(live)configure# show
- node node1.magedu.com \
- attributes standby="off"
- node node2.magedu.com \
- attributes standby="off"
- primitive WebIP ocf:heartbeat:IPaddr \
- params ip="172.16.14.2"
- primitive WebServer lsb:httpd
- location WebIP_on_node1 WebIP 500: node1.magedu.com
- colocation WebServer_with_WebIP inf: WebServer WebIP
- order WebServer_after_webIP inf: WebIP WebServer
- property $id="cib-bootstrap-options" \
- dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
- cluster-infrastructure="openais" \
- expected-quorum-votes="2" \
- stonith-enabled="false" \
- no-quorum-policy="ignore"
转载于:https://blog.51cto.com/51880526/1075734
基于corosync+pacemaker实现主从高可用集群相关推荐
- corosync+pacemaker+crmsh配置高可用集群。
实验环境: admin1.tuchao.com 192.168.18.100 ansible管理节点 admin2.tuchao.com 192.168.18.101 集群节点一 admin3.t ...
- 基于rhcs套件实现的高可用集群
1.基于rhcs套件实现nginx平台的高可用集群 实验环境: 1> server1 server5 集群节点为了节省节点我们还用了server1作为管理节点安装了luci图形管理: 2> ...
- keepalived+MHA实现mysql主从高可用集群
本节索引 原理分析 实验环境准备 主从复制集群 安装MHA包 初始化MHA 配置Keepalived 故障出现 故障恢复 总结 一 原理分析 1 MHA简介: MHA(Master High Avai ...
- docker mysql 高可用_使用docker 基于pxc镜像搭建mysql高可用集群
前置条件 docker已安装: 第一步:拉取镜像 docker pull percona/percona-xtradb-cluster:5.7.21 第二步:复制重命名镜像(可选) docker ta ...
- 基于Centos+Docker+Kubeadm的高可用集群设计
- 【K8SRockyLinux】基于开源操作系统搭建K8S高可用集群(详细版)
文章目录 一.实验节点规划表
- nfs mysql_heatbeat-gui实现基于nfs的mysql高可用集群
一.简述HA高可用集群 高可用集群就是当集群中的一个节点发生各种软硬件及人为故障时,集群中的其他节点能够自动接管故障节点的资源并向外提供服务.以实现减少业务中断时间,为用户提供更可靠,更高效的服务. ...
- 高可用集群技术之heartbeat应用详解(一)
一.高可用集群基本概念 什么是高可用技术呢?在生产环境中我既要保证服务不间断的服务又要保证服务器稳定不down机,但是异常还是会发生,比如说:服务器硬件损坏...导致服务器down机,我该如何保证 ...
- Linux: CentOS 7下搭建高可用集群
转载: http://linux.cn/article-3963-1.html 本文以两台机器实现双集热备高可用集群,主机名node1的IP为192.168.122.168 ,主机名node2的IP为 ...
最新文章
- 先发制人!Waymo将首推商用载人自动驾驶服务,Uber们怕不怕?
- 这三个Python小技巧你要知道
- python在日常工作处理中的应用-近期工作中应用Python的一些经验总结
- 【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)
- Angularjs切换网站配色模式简单示例1(切换css文件)
- 什么是网络计算机有什么优点,ISDN是什么?它有什么优点?
- QA:Golang抽象nil问题
- 下载全球高清卫星影像地图
- 人工智能资源下载2024G
- VAX/VMS虚拟内存系统
- 第21章 分层架构软件测试
- 2023年上半年信息系统项目管理师考试时间你知道吗?
- JWT 避坑指南:nbf 验签失效问题的解决
- 自适应页界面HTML源码
- GO语言————2、GO语言环境安装
- 支持服务器CPU的ITX主板,广积科技发布支持英特尔Xeon E处理器的Mini-ITX主板--MI995...
- BlackBerry 代码签名工具申请及安装介绍
- vue3 ts 使用 pinia
- 计算型存储: 异构计算的下一个关键应用
- 周杰伦:他们只顾嘲讽,却不知眼前是神的降生