搭建Pacemaker + Corosync高可用集群

来源:互联网 发布:js无限下拉页面瀑布流 编辑:程序博客网 时间:2024/06/05 18:36

高可用集群Pacemaker+Corosync介绍

这是一个十分成熟的高可用集群架构,网络上各种资料十分详尽。此处提供几个链接参考学习

  • pacemaker:http://www.linuxidc.com/Linux/2013-08/89037.htm
  • corosync:http://www.linuxidc.com/Linux/2013-08/88733.htm
  • 安装配置教程 http://www.linuxidc.com/Linux/2013-08/88733p2.htm
    https://www.iyunv.com/thread-78873-1-1.html

搭建前准备工作

  • 操作系统: CentOS 7 (之前使用的CentOS 6 存在依赖库问题,有时间还要查看问题所在)
  • VMware创建两个虚拟机,作为测试节点。

    特别提示:使用华硕主板小伙伴,BIOS可能默认的的是Intel虚拟技术关闭,这样是不能创建虚拟机的,记得修改BIOS设置
  • 修改两个节点的/etc/hosts/文件,使得各自可以解析对方的IP地址,使用ping命令测试。hosts文件修改后内容如下:

172.16.73.128 CentOS1 node1172.16.73.129 CentOS2 node2
  • 保证两个节点的时间同步。

    设置集群内时间服务器,其他的机器都和时间服务器校对
  • 关闭各自防火墙和SELinux

    问题记录:双机同时启动却都认为对方offline
    特别提醒CentOS7默认的防火墙是firewall,所以同时解决firewall,iptables,SELinux
  • 双机互信ssh

安装Pacemaker + Corosync + crmsh

讲道理按照诸多资料教程步骤,安装过程只有三条命令那么简单。

sudo yum install pacemakersudo yum install corosyncsudo yum install crmsh

但是中间遇到了各种问题,主要是依赖问题十分头疼
比如CentOS 6 提示依赖libcoroipcc.so.4( ), libconfdb.so.4( ), 但是被依赖程序已经包含在corosynclib-2.3.3-1.1中提示Not Found。类似的问题出现在CentOS 7中,安装crmsh时提示依赖Python 2.6, 但是已经安装至Python 2.7。

无奈之下选择问题相对好解决的CentOS 7系统,重新在虚拟机上安装节点,安装pacemaker + corosync + crmsh

  • pacemaker依赖于corosync中的一些组件,而且先安装corosync会导致安装pacemaker出现一些问题。所以一定先安装pacemaker,corosync会被yum自动安装好,一箭双雕
  • 安装pacemaker 和corosync 时推荐使用CentOS 7 自带的镜像
  • 安装crmsh就没这么顺利了,最后事实证明一个好的yum源真的很重要,这次使用的是一个专用源
    http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-7/network:ha-clustering:Stable.repo
  • 更新好源之后,安装crmsh

根据集群情况修改corosync配置文件

  • 在这里在下犯了一个十分低级的错误,将注释写在了每一行的后面。问题就出现在注释内容和注释之间的几个空格。记得在初次使用linux的时候,创建.desktop文件复制了网上的代码,但是每一行的结尾都多了一个空格,结果这个快捷方式就是不起作用。所以以后写注释一定写在语句的前一行上。
# Please read the corosync.conf.5 manual pagetotem {    version: 2    # crypto_cipher and crypto_hash: Used for mutual node authentication.    # If you choose to enable this, then do remember to create a shared    # secret with "corosync-keygen".    # enabling crypto_cipher, requires also enabling of crypto_hash.    crypto_cipher: none    crypto_hash: none    token: 10000    #token_retransmits_before_loss_const: 5    #join:6000    #consensus:600    interface {                member {                    memberaddr: node1                }                member {                    memberaddr: node2                }                ringnumber: 0  #回环表示码,防止本机发出的心跳被本机另一个网卡接收                bindnetaddr: 172.16.73.0  #集群工作所在网络                mcastport: 4000  #组播端口                ttl: 1  #只进行一跳        }        transport: udpu}#有关节点的配置nodelist {          node {          name: node2          nodeid: 2          quorum_votes: 1  #投票机制,持有票数          ring0_addr: CentOS2  #地址,已经在hosts文件中设置过  }          node {          name: one          nodeid: 1          quorum_votes: 1          ring0_addr: CentOS1         }}   logging {    # Log the source file and line where messages are being    # generated. When in doubt, leave off. Potentially useful for    # debugging.    fileline: off    # Log to standard error. When in doubt, set to no. Useful when    # running in the foreground (when invoking "corosync -f")    to_stderr: no    # Log to a log file. When set to "no", the "logfile" option    # must not be set.    to_logfile: yes    logfile: /var/log/cluster/corosync.log    # Log to the system log daemon. When in doubt, set to yes.    #to_syslog: no    # Log debug messages (very verbose). When in doubt, leave off.    debug: off    # Log messages with time stamps. When in doubt, set to on    # (unless you are only logging to syslog, where double    # timestamps can be annoying).    #timestamp: on    #logger_subsys {    #   subsys: QUORUM    #   debug: off    #}}quorum {           provider: corosync_votequorum       two_node: 1           #expected_votes: 2}service{    ver:1    name:pacemaker}

启动corosync服务

  • 各节点之间ssh互信
# ssh-keygen  -t rsa -f ~/.ssh/id_rsa  -P ''   # ssh-copy-id -i .ssh/id_rsa.pub root@node1.test.com
  • 生成authkey文件
# corosync-keygenCorosync Cluster Engine Authentication key generator.Gathering 1024 bits for key from /dev/random.Press keys on your keyboard to generate entropy.Press keys on your keyboard to generate entropy (bits = 208).Press keys on your keyboard to generate entropy (bits = 272).Press keys on your keyboard to generate entropy (bits = 336).Press keys on your keyboard to generate entropy (bits = 400).
  • 把配置文件和刚才所生成的authkey文件发给另一个节点
# scp -p /etc/corosync/authkey node2.star.com:/etc/corosync/# scp -p /etc/corosync/corosync.conf node2.star.com:/etc/corosync/
  • 启动corosync并查看
# service corosync start# service corosync status -lRedirecting to /bin/systemctl status  -l corosync.service● corosync.service - Corosync Cluster Engine   Loaded: loaded (/usr/lib/systemd/system/corosync.service; disabled; vendor preset: disabled)   Active: active (running) since 三 2017-09-27 14:07:37 CST; 24s ago     Docs: man:corosync           man:corosync.conf           man:corosync_overview  Process: 3777 ExecStart=/usr/share/corosync/corosync start (code=exited, status=0/SUCCESS) Main PID: 3791 (corosync)   CGroup: /system.slice/corosync.service           └─3791 corosync ... ...          

看见Active: active (running)心里莫名激动

原创粉丝点击