https://blog.51cto.com/9652359/2109398

https://blog.csdn.net/abel_dwh/article/details/78475630

2018-05-01 11:37:44

实验目的:使用corosync作为集群消息事务层(Massage Layer),pacemaker作为集群资源管理器(Cluster Resource Management),pcs作为CRM的管理接口工具。要求实现httpd的高可用功能。

准备工作:

  1. 配置SSH双机互信;
  2. 配置主机名解析/etc/hosts文件;
  3. 关闭防火墙:service iptables stop
  4. 关闭selunux:setenforce 0
  5. 关闭networkmanager: chkconfig NetworkManager off 、service NetworkManager stop

一、 软件安装
使用yum源可以直接安装corosync pacemaker以及pcs软件:
yum install corosync pacemaker pcs -y

二、 开启pcsd服务,两台都要开启(不然认证会失败)

systemctl  start  pcsd.service

三、 设置hacluster账号的密码,两台都要设置
为hacluster设置一个密码,用于pcs与pcsd通信
[root@node1 ~]# grep "hacluster" /etc/passwd

echo 'hacluster'|passwd hacluster --stdin

集群节点认证

pcs cluster auth node1 node2  -u hacluster

node1: Authorized
node2: Authorized

四、在node1和node2上分别执行下面命令创建集群,配置文件会保存在/etc/corosync

pcs cluster setup --name mycluster node1 node2 --force

  • enable我们创建的集群
# pcs cluster enable --name webha
# pcs cluster  start --all
# pcs status

[root@node-1 ~]# crm_verify -L -V ##crm_verify命令用来验证当前的集群配置是否有错误
error: unpack_resources: Resource start-up disabled since no STONITH resources have been defined
error: unpack_resources: Either configure some or disable STONITH with the stonith-enabled option
error: unpack_resources: NOTE: Clusters with shared data need STONITH to ensure data integrity
Errors found during check: config not valid
[root@node-1 ~]# pcs property set stonith-enabled=false

[root@node-1 ~]# pcs property list ##查看已经更改过的集群属性

如果是全局的,使用pcs property --all

七、 配置服务

  1. 配置VIP服务

  2. 配置VIP服务
    pcs resource create vip ocf:heartbeat:IPaddr2 ip=192.168.110.150 cidr_netmask=24 op monitor interval=30s
    pcs status 查看资源是否启动,注意这里测试发现掩码需要配置为与网卡同掩码,否则资源启动不了

  3. 配置httpd服务
    这里有两种方式,使用ocf:heartbeat:apache或者使用lsb:httpd方式,前者需要手工在两台服务器上将httpd服务启动,而后者服务由pacemaker集群启动。
    pcs resource create web lsb:httpd op monitor interval=20s
    pcs status 可以看到资源已经启动。
  4. 同时,可以在对应的节点上面直接service httpd status查看服务是否启动,以及ip addr 查看VIP是否获取到。

    八、 资源约束配置

  5. 配置资源的启动顺序:order,要求vip先启动,web后启动。
    pcs constraint order vip then web
  6. 配置位置约束,希望资源优先在node1节点上运行,设置vip/web对node1节点的优先级为150,对node2节点的优先级为50:
    pcs constraint location web prefers node1=150
    pcs constraint location vip prefers node1=150
    pcs constraint location web prefers node2=50
    pcs constraint location vip prefers node2=50
    [root@node1 ~]# pcs constraint
  7. Location Constraints:
    Resource: vip
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)
    Resource: web
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)

    注意:如果多个资源分布在不同的设备上,而这些资源又必须共同在同一个设备上才能够正常的对外提供服务,那么这个集群将不能正常工作。
    可以看到只有web以及vip对node1的优先级都调整为150后,集群才能够正常对外提供服务,否则会出现两个资源分布在不同的设备而导致不能对外提供服务

  8. 配置资源组,只有两者对节点的位置优先级调整为一样后,资源组同时切换:
    pcs resource group add mygroup vip web
    [root@node2 ~]# pcs status groups
    mygroup: vip web
    [root@node1 ~]# pcs resource
    Resource Group: httpgroup
    vip (ocf::heartbeat:IPaddr2): Started node1
    web (lsb:httpd): Started node1
  9. 配置排列约束,让vip与web 资源运行在一起,分数为100
    [root@node1 ~]# pcs constraint colocation add vip with web 100
    [root@node1 ~]# pcs constraint show
    Location Constraints:
    Resource: httpgroup
    Enabled on: node1 (score:200)
    Enabled on: node2 (score:100)
    Resource: vip
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)
    Resource: web
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)
    Ordering Constraints:
    start vip then start web (kind:Mandatory)
    Colocation Constraints:
    vip with web (score:100)
    Ticket Constraints:
  10. 九、 将资源切换到node2上面
    pcs constraint location web prefers node1=100 //将web资源对node1的位置优先级调整为100,可以看到资源从node2转换到node1,注意可以调整httpgroup,也可以同时调整web以及vip对node2的优先级。
    May 1 09:43:02 node1 crmd[2965]: notice: State transition S_IDLE -> S_POLICY_ENGINE | input=I_PE_CALC cause=C_FSA_INTERNAL origin=abort_transition_graph
    May 1 09:43:02 node1 pengine[2964]: warning: Processing failed op monitor for web on node2: not running (7)
    May 1 09:43:02 node1 pengine[2964]: notice: Move web#011(Started node2 -> node1)
    May 1 09:43:02 node1 pengine[2964]: notice: Calculated transition 4, saving inputs in /var/lib/pacemaker/pengine/pe-input-57.bz2
    May 1 09:43:02 node1 crmd[2965]: notice: Initiating stop operation web_stop_0 on node2 | action 6
    May 1 09:43:02 node1 crmd[2965]: notice: Initiating start operation web_start_0 locally on node1 | action 7
    May 1 09:43:03 node1 lrmd[2962]: notice: web_start_0:3682:stderr [ httpd: Could not reliably determine the server's fully qualified domain name, using node1.yang.com for ServerName ]
    May 1 09:43:03 node1 crmd[2965]: notice: Result of start operation for web on node1: 0 (ok) | call=12 key=web_start_0 confirmed=true cib-update=42
    May 1 09:43:03 node1 crmd[2965]: notice: Initiating monitor operation web_monitor_20000 locally on node1 | action 8
    May 1 09:43:03 node1 crmd[2965]: notice: Transition 4 (Complete=4, Pending=0, Fired=0, Skipped=0, Incomplete=0, Source=/var/lib/pacemaker/pengine/pe-input-57.bz2): Complete
    May 1 09:43:03 node1 crmd[2965]: notice: State transition S_TRANSITION_ENGINE -> S_IDLE | input=I_TE_SUCCESS cause=C_FSA_INTERNAL origin=notify_crmd

    [root@node1 ~]# crm_simulate -sL

    Current cluster status:
    Online: [ node1 node2 ]

    Resource Group: httpgroup
    vip (ocf::heartbeat:IPaddr2): Started node1
    web (lsb:httpd): Started node1

    Allocation scores:
    group_color: httpgroup allocation score on node1: 0
    group_color: httpgroup allocation score on node2: 0
    group_color: vip allocation score on node1: 100
    group_color: vip allocation score on node2: 50
    group_color: web allocation score on node1: 100
    group_color: web allocation score on node2: 50
    native_color: web allocation score on node1: 200
    native_color: web allocation score on node2: 100
    native_color: vip allocation score on node1: 400
    native_color: vip allocation score on node2: 150

    也可以将整个资源组作为整体调整优先级,如下:
    pcs constraint location httpgroup prefers node2=100
    pcs constraint location httpgroup prefers node1=200

    [root@node1 ~]# pcs constraint
    Location Constraints:
    Resource: httpgroup
    Enabled on: node1 (score:200)
    Enabled on: node2 (score:100)
    Resource: vip
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)
    Resource: web
    Enabled on: node1 (score:100)
    Enabled on: node2 (score:50)
    Ordering Constraints:
    start vip then start web (kind:Mandatory)

pacemaker+corosync+pcs实验相关推荐

  1. mfs分布式文件系统,分布式存储,高可用(pacemaker+corosync+pcs),磁盘共享(iscsi),fence解决脑裂问题

    一.MFS概述 MooseFS是一个分布式存储的框架,其具有如下特性: (1)通用文件系统,不需要修改上层应用就可以使用(那些需要专门api的dfs很麻烦!). (2)可以在线扩容,体系架构可伸缩性极 ...

  2. 【PostgreSQL基于Pacemaker+Corosync+pcs的高可用】

    地址信息 172.20.10.6 pg01 172.20.10.7 pg02 172.20.10.8 pg03 172.20.10.9 vip-master 172.20.10.10 vip-slav ...

  3. pacemaker+corosync+pcs

    1.Corosync和pacemaker的了解: Corosync是集群管理套件的一部分,它在传递信息的时候可以通过一个简单的配置文件来定义信息传递的方式和协议等.也就是说,corosync是Mess ...

  4. pacemaker+corosync 搭建一主两从PG集群

    一.OS配置 1.1环境规划 环境:centos 7 数据库:pg11.5 ip地址: node1  10.122.166.120  node2  10.122.166.127  node3  10. ...

  5. postgresql 高可用 pacemaker + corosync 之二 setup vip-mas ,vip-sla 均绑定在 master

    os: ubuntu 16.04 db: postgresql 9.6.8 pacemaker: Pacemaker 1.1.14 Written by Andrew Beekhof corosync ...

  6. 利用pcs+pacemaker+corosync实现(HA)高可用集群

    实验环境搭建 创建一台操作系统是rhel7.6的虚拟机node,配置好网络仓库,解析,网卡设置,关闭火墙和selinux后封装 克隆node虚拟机,虚拟机域名为node1,node2,node3,主机 ...

  7. Pacemaker,Corosync和PCS搭建高可用性负载均衡linux 集群(httpd)

    Pacemaker,Corosync和PCS搭建高可用性负载均衡linux 集群(httpd) 一.高可用性的概念: 1.一种机制来定义哪些系统可以被用作集群节点 2.哪些服务或者应用可以在节点间作失 ...

  8. Pacemaker+Corosync+Mfs+Iscsi+Fence实现高可用和Fence管理

    前言: 分布式文件系统(DIstributed File System)     时值文件系统管理的物理存储资源不一定直接连接在本地 的节点上,而是通过计算机网络与节点相连,简单的来讲,就是把一些分散 ...

  9. Pacemaker+Corosync PostgreSQL流复制HA的部署(pha4pgsql)

    简介 在众多的PostgreSQL HA方案中,流复制HA方案是性能,可靠性,部署成本等方面都比较好的,也是目前被普遍采用的方案.而用于管理流复制集群的工具中,Pacemaker+Corosync又是 ...

最新文章

  1. nginx产生【413 request entity too large】错误的原因与解决方法
  2. 【数理知识】《矩阵论》方保镕老师-第6章-广义逆矩阵及其应用
  3. 搜索功能:洞悉产品的绝佳入口
  4. WPF Image Source 设置相对路径图片
  5. nignx解决vue部署服务器刷新页面出现404问题
  6. HDU-1013-Digital root
  7. Unity MRTK(二)常见操作
  8. 《阿里巴巴Java开发手册》版本演进历史
  9. CentOS 7 安裝FastDFS V6.0.3
  10. wsimport命令
  11. 微课在小学计算机教学中的应用,微课技术在小学信息技术课堂中的应用
  12. 该内存不能为written或read的解决方案(比较全)
  13. 电子工程师的自我修养 - 恒流源电路分析
  14. 【高等数学笔记】多元向量值函数的导数与微分
  15. 报错: EBUSY: resource busy or locked, lstat ‘C:\hiberfil.sys‘
  16. 平面设计构图是什么,平面设计基本构图原则和形式是什么:夏雨老师
  17. 掌阅群分享技术点收集(app性能优化专攻)
  18. ASSERT(FALSE)
  19. C/C++常用函数汇总
  20. 简单实用 铃铛运动动画制作AE教程

热门文章

  1. Get智能写作 | 掌握这5个小技巧,让你的写作飞起来
  2. vba 之判断工作表是否处于保护状态:Worksheets.ProtectContents
  3. android动态改变布局,Android 动态添加布局的两种方式
  4. 计算机网络之(4):DNS
  5. Excel把符合条件的数据全部提取出来
  6. pcs for linux7下载,centos7上实现corosync V2 + pacemaker + pcs | crmsh备忘录
  7. 计算机实训应用,计算机应用基础及实训
  8. python 爬虫 关于requests的基础知识及常用的一些User-Agent
  9. Matlab之随机森林TreeBagger
  10. LQR控制器——简单实现与仿真