本实验由两个节点组成高可用主从集群,在实际中不常用,目的是通过实验来加深对corosync的认识和理解。

环境设置:
  1. node1:node1.magedu.com
  2. ip 172.16.14.10
  3. node2:node2.magedu.com
  4. ip 172.16.14.11
  5. VIP 172.16.14.2
一:准备工作
1、DNS域名解析
  1. 用uname -n的结果来识别对方的名字
  2. 使node1,node2的uname -n分别为:
  3. node1.magedu.com
  4. node2.magedu.com
  5. node1:
  6. # sed -i 's@\(HOSTNAME=\).*@\1node1.magedu.com@g'  /etc/sysconfig/network
  7. # hostname node1.magedu.com
  8. node2:
  9. # sed -i 's@\(HOSTNAME=\).*@\1node2.magedu.com@g' /etc/sysconfig/network
  10. # hostname node2.magedu.comm
  11. 在/etc/hosts添加:
  12. 172.16.14.10 node1.magedu.com node1
  13. 172.16.14.11 node2.magedu.com node2
2、node1,node2可以远程通信
  1. 在node1上:
  2. ssh-keygen -t rsa -P ''
  3. ssh-copy-id -i ~/.ssh/id_rsa root@node2
  4. 命令测试:
  5. ssh node2 'ifconfig'
  6. 然后再实现node2对node1的通信
3、两个节点时间同步
  1. [root@node2 ~]# date 112822022012;ssh node1 'date 112822022012'
  2. Fri Nov 28 22:02:00 CST 2012
  3. Fri Nov 28 22:02:00 CST 2012

4、在node1,node2上安装httpd

  1. # yum -y install httpd
  2. 建立测试页面,为了便于区分,将页面结果设置为不同内容
  3. node1上:
  4. 编辑/var/www/html/index.html写入:
  5. <h1>node1</h1>
  6. node2:
  7. 编辑/var/www/html/index.html写入:
  8. <h1>node2</h1>
测试完成后;将两个节点的httpd服务关闭,并使之开机不能自动启动
  1. service httpd stop
  2. chkconfig httpd off
  3. 关闭selinux
  4. setenforce 0
二:安装配置corosync
1、安装以下rpm包:

  1. cluster-glue
  2. cluster-glue-libs
  3. heartbeat
  4. openaislib
  5. resource-agentsyyu
  6. corosync
  7. heartbeat-libs
  8. pacemaker
  9. corosynclib
  10. libesmtp
  11. pacemaker-libs
下载至本地/root后安装:
  1. # yum -y --nogpgcheck localinstall *.rpm
2、配置corosync(以下命令在node1.magedu.com上执行) 
  1. # cd /etc/corosync
  2. # cp corosync.conf.example corosync.conf
  3. # vim corosync.conf
  4. 作如下修改:
  5. version: 2          ##版本
  6. secauth: on
  7. threads: 1          ##线程数
  8. bindnetaddr: 172.16.0.0    ##绑定的网段
  9. mcastaddr: 226.94.14.14   ##使用的组播地址
  10. to_syslog: no   ##是否将日志发送到日志文件系统
  11. //添加这个service可以实现pacemaker随corosync的启动而自动启动
  12. service {
  13. ver:    0
  14. name:   pacemaker
  15. }
  16. //定义ais的辅助运行用户和组的
  17. aisexec {
  18. name:   root
  19. group:  root
  20. }

3、生成节点间通信时用到的认证密钥文件:
  1. # corosync-keygen
  2. 将corosync和authkey复制至node2:
  3. # scp -p corosync.conf  authkey  node2:/etc/corosync/
  4. 分别为两个节点创建corosync生成的日志所在的目录:
  5. # mkdir /var/log/cluster
  6. # ssh node2  'mkdir /var/log/cluste
4、启动corosync
  1. # service corosync start
  2. #tail -50 /var/log/messages      ##查看日志信息
  3. # ssh node2 -- /etc/init.d/corosync start   ##启动node2
5、查看状态:
  1. [root@node1 corosync]# crm
  2. crm(live)# status
  3. Current DC: node1.magedu.com - partition with quorum
  4. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
  5. 2 Nodes configured, 2 expected votes
  6. 0 Resources configured.
  7. ============
  8. Online: [ node1.magedu.com node2.magedu.com ]
三:crm用法--crm是一个交互式的shell接口
  1. [root@node1 ~]# crm
  2. crm(live)# help
  3. This is the CRM command line interface program.
  4. Available commands:         ##crm使用的子命令
  5. cib              manage shadow CIBs                    ##集群信息库
  6. resource         resources management                  ##资源管理
  7. configure        CRM cluster configuration             ##集群配置
  8. node             nodes management                      ##节点管理
  9. options          user preferences
  10. ra               resource agents information center    ##资源代理
  11. status           show cluster status                   ##显示集群状态信息
  12. quit,bye,exit    exit the program                      ##退出程序
  13. help             show help                             ##帮助信息
  14. end,cd,up        go back one level                     ##返回上一层
  15. 最常用的有:
  16. 1、集群的配置用configure:
  17. crm(live)# configure                  ##进入资源配置命令
  18. crm(live)configure# help
  19. primitive        define a resource      ##定义资源
  20. group            define a group       ##定义组
  21. location         a location preference  ##位置约束
  22. colocation       colocate resources     ##排列约束
  23. order            order resources        ##顺序约束
  24. show             display CIB objects    ##显示信息
  25. edit             edit CIB objects       ##进入编辑模式
  26. delete           delete CIB objects     ##删除cib对象
  27. commit           commit the changes to the CIB   ##提交信息
  28. verify           verify the CIB with crm_verify  ##检查语法错误
  29. 2、资源代理RA的信息:
  30. crm(live)configure# cd
  31. crm(live)# ra
  32. crm(live)ra# help
  33. Available commands:
  34. classes          list classes and providers             ##资源代理的类别
  35. list             list RA for a class (and provider)     ##显示每个类别的所有RA
  36. meta             show meta data for a RA             ##资源代理的元数据
  37. providers        show providers for a RA and a class   ##资源代理的提供者
  38. quit             exit the program
  39. help             show help
  40. end              go back one level
  41. crm(live)ra# classes                ##显示四种资源代理类别
  42. heartbeat                           ##heartbaet V1版本
  43. lsb                                 ## linux标准库
  44. ocf / heartbeat pacemaker         ##Open cluster Framework 开放集群架构
  45. stonith                             ##专为配置stonith设备而用
  46. crm(live)ra# list lsb               ##用list可以查看每个类别的
  47. crm(live)ra# list ocf
  48. AoEtarget           AudibleAlarm        CTDB
  49. ClusterMon          Delay               Dummy
  50. crm(live)ra# list ocf heartbeat      ##查看ocf下的子类别
  51. AoEtarget           AudibleAlarm        CTDB
  52. ClusterMon          Delay               Dummy
  53. EvmsSCC             Evmsd               Filesystem
  54. ICP                 IPaddr              IPaddr2
  55. //只显示部分;IPaddr是ocf类别下heartbeat子类别的资源代理;用于IP的代理;下面我们将用到
  56. crm(live)ra# meta ocf:heartbeat:IPaddr        ##用meta查看某个具体资源代理的属性
  57. ##使用方式  类别:子类别:资源代理
  58. Parameters (* denotes required, [] the default):   ##*表示必选的,[]表示默认值
  59. ip* (string): IPv4 address                    ##使用的参数;*表示必选的
  60. The IPv4 address to be configured in dotted quad notation, for example
  61. "192.168.1.1".
  62. ...............
  63. Operations' defaults (advisory minimum):       ##默认的操作
  64. start         timeout=20s                  ##启动超时时间
  65. stop          timeout=20s                  ##停止超时时间
  66. monitor       interval=5s timeout=20s      ##每隔5s监视一次,20s是超时时间
  67. 配置1个全局属性:
  68. crm
  69. configure
  70. property stonith-enabled=false       ##是否启用stonish设备
  71. verify   ##检查语法
  72. commit    ##提交
  73. 接下来开始配置资源了:
  74. 定义资源用primitive,help一下:
  75. crm(live)configure# help primitive
  76. Usage:
  77. ...............
  78. primitive  <rsc>  [<class>:[<provider>:]]<type>
  79. 资源        RA类别:提供者:哪个类型的RA
  80. [params attr_list]                        ##params是关键字,指定参数
  81. [meta attr_list]                          ##元数据属性
  82. [utilization attr_list]
  83. [operations id_spec]                     ##操作
  84. [op op_type [<attribute>=<value>...] ...]   ##指定额外的属性;如超时时长
四:集群资源配置:
1、下面来配置一个web IP的集群资源:
  1. crm(live)configure# primitive WebIP ocf:heartbeat:IPaddr  params ip="172.16.14.2"
  2. crm(live)configure# verify
  3. crm(live)configure# commit
  4. crm(live)configure# show
  5. node node1.magedu.com
  6. node node2.magedu.com
  7. primitive WebIP ocf:heartbeat:IPaddr \
  8. params ip="172.16.14.2"
  9. property $id="cib-bootstrap-options" \
  10. dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
  11. cluster-infrastructure="openais" \
  12. expected-quorum-votes="2" \
  13. stonith-enabled="false"
  14. crm(live)configure# cd
  15. crm(live)# status                     ##状态查看
  16. ============
  17. Last updated: Sat Dec  1 11:12:19 2012
  18. Stack: openais
  19. Current DC: node1.magedu.com - partition with quorum
  20. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
  21. 2 Nodes configured, 2 expected votes
  22. 1 Resources configured.
  23. ============
  24. Online: [ node1.magedu.com node2.magedu.com ]
  25. WebIP     (ocf::heartbeat:IPaddr):     Started node1.magedu.com
  26. //发现WebIP运行在node1上
  27. //ifconfig查看;172.16.14.2在node1上
  28. [root@node1 ~]# ifconfig
  29. eth0:0    Link encap:Ethernet  HWaddr 00:0C:29:76:E9:56
  30. inet addr:172.16.14.2  Bcast:172.16.255.255  Mask:255.255.0.0
  31. UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
  32. Interrupt:67 Base address:0x2000
2、添加WebServe资源:
  1. crm(live)configure# primitive WebServer lsb:httpd
  2. crm(live)configure# verify
  3. crm(live)configure# commit
  4. crm(live)configure# show
  5. node node1.magedu.com
  6. node node2.magedu.com
  7. primitive WebIP ocf:heartbeat:IPaddr \
  8. params ip="172.16.14.2"
  9. primitive WebServer lsb:httpd           ##显示WebServe
  10. property $id="cib-bootstrap-options" \
  11. dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
  12. cluster-infrastructure="openais" \
  13. expected-quorum-votes="2" \
  14. stonith-enabled="false"
  15. crm(live)configure# cd
  16. crm(live)# status
  17. WebIP     (ocf::heartbeat:IPaddr):     Started node1.magedu.com
  18. WebServer     (lsb:httpd):     Started node2.magedu.com
  19. //发现WebServer在node2上;默认资源是负载均衡模式的。多个
  20. 资源运行在多个节点上的,我们要想把资源运作在一个节点上;
  21. 可以通过定义组来实现:
  22. 下面将WebIP,WebServer定义在一个Webservice组中;
  23. crm(live)configure# group Webservice WebIP WebServer
  24. crm(live)configure# cd
  25. crm(live)# status
  26. Resource Group: Webservice             ##发现Webservice
  27. WebIP     (ocf::heartbeat:IPaddr):     Started node1.magedu.com
  28. WebServer     (lsb:httpd):     Started node1.magedu.com
  29. //有上面得知,定义组后WebIP, WebServer都运行在node1上了
  30. //通过访问172.16.14.2,只显示node1的页面内容;
  31. 把node1为standby:
  32. [root@node1 ~]# crm node standby
  33. [root@node1 ~]# crm status
  34. ============
  35. Last updated: Sat Dec  1 11:46:27 2012
  36. Stack: openais
  37. Current DC: node1.magedu.com - partition with quorum
  38. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
  39. 2 Nodes configured, 2 expected votes
  40. 1 Resources configured.
  41. ============
  42. Node node1.magedu.com: standby          ##node1已为standby
  43. Online: [ node2.magedu.com ]
  44. Resource Group: Webservice
  45. WebIP     (ocf::heartbeat:IPaddr):     Started node2.magedu.com
  46. WebServer     (lsb:httpd):     Started node2.magedu.com
  47. //说明资源都转移到node2上面了
  48. //此时页面也显示为node2的测试内容了
  49. 这样就完成了角色转换了
  50. 下面让node2为standby:node1为online:
  51. [root@node1 ~]# crm node online
  52. [root@node1 ~]# crm status
  53. ============
  54. Last updated: Sat Dec  1 12:12:56 2012
  55. Stack: openais
  56. Current DC: node1.magedu.com - partition with quorum    ##没有达到法定票数
  57. Version: 1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f
  58. 2 Nodes configured, 2 expected votes
  59. 1 Resources configured.
  60. ============
  61. Node node2.magedu.com: standby
  62. Online: [ node1.magedu.com ]
  63. Resource Group: Webservice
  64. WebIP     (ocf::heartbeat:IPaddr):     Started node1.magedu.com
  65. WebServer     (lsb:httpd):     Started node1.magedu.com
  66. //对于两个节点的集群,不具备法定票数也允许运行;有以下措施:
  67. crm(live)configure# property no-quorum-policy=ignore    ##不具备法定票数忽略
  68. crm(live)configure# verify
  69. crm(live)configure# commit
3、下面通过约束关系来管理资源;这需要删除前面定义的组:
    需先停止资源运行,再删除组
  1. crm(live)resource# stop Webservice  ##停止资源运行
  2. crm(live)resource# cd
  3. crm(live)# configure
  4. crm(live)configure# delete Webservice
  5. 提交查看结果;
  6. WebIP,WebServer又以独立资源运行起来了
  7. 1)、定义排序约束;(两个资源必须在一起或不在一起)
  8. crm(live)configure# colocation WebServer_with_WebIP inf:
  9. WebServer WebIP
  10. 提交后查看:
  11. crm(live)configure# show xml
  12. <rsc_colocation id="WebServer_with_WebIP" rsc="WebServer"
  13. score="INFINITY" with-rsc="WebIP"/>
  14. //说明这两个资源必须在一起
  15. crm(live)# status
  16. Online: [ node1.magedu.com node2.magedu.com ]
  17. WebIP     (ocf::heartbeat:IPaddr):     Started node1.magedu.com
  18. WebServer     (lsb:httpd):     Started node1.magedu.com
  19. // 两个资源在一个节点运行
  20. //通过浏览去访问为node1的页面
  21. 让节点1为standby:
  22. crm(live)# node standby
  23. crm(live)# status
  24. WebIP     (ocf::heartbeat:IPaddr):     Started node2.magedu.com
  25. WebServer     (lsb:httpd):     Started node2.magedu.com
  26. //资源转移到node2上
  27. 2)、用顺序约束可以让资源按一前一后顺序启动:
  28. crm(live)configure# order WebServer_after_webIP mandatory: WebIP
  29. WebServer
  30. crm(live)configure# verify
  31. crm(live)configure# commit
  32. crm(live)configure# show xml
  33. <rsc_order first="WebIP" id="WebServer_after_webIP"
  34. score="INFINITY" then="WebServer"/>
  35. //先启动WebIP;再启动WebServe
  36. 3)、用位置约束定义一个资源停留在一个节点上的倾向性有多大
  37. crm(live)configure# location WebIP_on_node1 WebIP 500:
  38. node1.magedu.com
  39. //WebIP停留在node1的倾向值为500;
  40. crm(live)configure# verify
  41. crm(live)configure# commit
  42. crm(live)configure# show
  43. crm(live)# node standby        ##节点1standby
  44. crm(live)# status
  45. Node node1.magedu.com: standby
  46. Online: [ node2.magedu.com ]
  47. WebIP     (ocf::heartbeat:IPaddr):     Started node2.magedu.com
  48. WebServer     (lsb:httpd):     Started node2.magedu.com
  49. //资源转移到node2上
  50. crm(live)# node online    ##node1为online;发现资源回到node1上

资源配置的结果:
  1. crm(live)configure# show
  2. node node1.magedu.com \
  3. attributes standby="off"
  4. node node2.magedu.com \
  5. attributes standby="off"
  6. primitive WebIP ocf:heartbeat:IPaddr \
  7. params ip="172.16.14.2"
  8. primitive WebServer lsb:httpd
  9. location WebIP_on_node1 WebIP 500: node1.magedu.com
  10. colocation WebServer_with_WebIP inf: WebServer WebIP
  11. order WebServer_after_webIP inf: WebIP WebServer
  12. property $id="cib-bootstrap-options" \
  13. dc-version="1.1.5-1.1.el5-01e86afaaa6d4a8c4836f68df80ababd6ca3902f" \
  14. cluster-infrastructure="openais" \
  15. expected-quorum-votes="2" \
  16. stonith-enabled="false" \
  17. no-quorum-policy="ignore"

转载于:https://blog.51cto.com/51880526/1075734

基于corosync+pacemaker实现主从高可用集群相关推荐

  1. corosync+pacemaker+crmsh配置高可用集群。

    实验环境: admin1.tuchao.com 192.168.18.100  ansible管理节点 admin2.tuchao.com 192.168.18.101  集群节点一 admin3.t ...

  2. 基于rhcs套件实现的高可用集群

    1.基于rhcs套件实现nginx平台的高可用集群 实验环境: 1> server1 server5 集群节点为了节省节点我们还用了server1作为管理节点安装了luci图形管理: 2> ...

  3. keepalived+MHA实现mysql主从高可用集群

    本节索引 原理分析 实验环境准备 主从复制集群 安装MHA包 初始化MHA 配置Keepalived 故障出现 故障恢复 总结 一 原理分析 1 MHA简介: MHA(Master High Avai ...

  4. docker mysql 高可用_使用docker 基于pxc镜像搭建mysql高可用集群

    前置条件 docker已安装: 第一步:拉取镜像 docker pull percona/percona-xtradb-cluster:5.7.21 第二步:复制重命名镜像(可选) docker ta ...

  5. 基于Centos+Docker+Kubeadm的高可用集群设计

  6. 【K8SRockyLinux】基于开源操作系统搭建K8S高可用集群(详细版)

    文章目录 一.实验节点规划表

  7. nfs mysql_heatbeat-gui实现基于nfs的mysql高可用集群

    一.简述HA高可用集群 高可用集群就是当集群中的一个节点发生各种软硬件及人为故障时,集群中的其他节点能够自动接管故障节点的资源并向外提供服务.以实现减少业务中断时间,为用户提供更可靠,更高效的服务. ...

  8. 高可用集群技术之heartbeat应用详解(一)

    一.高可用集群基本概念   什么是高可用技术呢?在生产环境中我既要保证服务不间断的服务又要保证服务器稳定不down机,但是异常还是会发生,比如说:服务器硬件损坏...导致服务器down机,我该如何保证 ...

  9. Linux: CentOS 7下搭建高可用集群

    转载: http://linux.cn/article-3963-1.html 本文以两台机器实现双集热备高可用集群,主机名node1的IP为192.168.122.168 ,主机名node2的IP为 ...

最新文章

  1. 先发制人!Waymo将首推商用载人自动驾驶服务,Uber们怕不怕?
  2. 这三个Python小技巧你要知道
  3. python在日常工作处理中的应用-近期工作中应用Python的一些经验总结
  4. 【HDU - 5187】zhx's contest (快速幂+ 快速乘,模板)
  5. Angularjs切换网站配色模式简单示例1(切换css文件)
  6. 什么是网络计算机有什么优点,ISDN是什么?它有什么优点?
  7. QA:Golang抽象nil问题
  8. 下载全球高清卫星影像地图
  9. 人工智能资源下载2024G
  10. VAX/VMS虚拟内存系统
  11. 第21章 分层架构软件测试
  12. 2023年上半年信息系统项目管理师考试时间你知道吗?
  13. JWT 避坑指南:nbf 验签失效问题的解决
  14. 自适应页界面HTML源码
  15. GO语言————2、GO语言环境安装
  16. 支持服务器CPU的ITX主板,广积科技发布支持英特尔Xeon E处理器的Mini-ITX主板--MI995...
  17. BlackBerry 代码签名工具申请及安装介绍
  18. vue3 ts 使用 pinia
  19. 计算型存储: 异构计算的下一个关键应用
  20. 周杰伦:他们只顾嘲讽,却不知眼前是神的降生

热门文章

  1. 桂林哪些职校可以学计算机,桂林市有几个中等职业学校
  2. tomcat怎么平滑更新项目_SpringBoot内置tomcat启动原理
  3. 简述使用混合传递参数时的基本原则_JUnit 5参数化方法测试(一)
  4. IC/FPGA校招笔试题分析(一)
  5. Hyperbola(双曲线)
  6. 乘法器专题研究(内含所有类型乘法器)
  7. 2. VS使用---HelloWorld
  8. 总结android项目的基本开发步骤(转帖)
  9. 强化学习之贝尔曼方程中文解释
  10. 人眼是具有插帧能力的