搭建Pacemaker + Corosync高可用集群

高可用集群Pacemaker+Corosync介绍

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

搭建前准备工作

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

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

172.16.73.128 CentOS1 node1
172.16.73.129 CentOS2 node2
  • 保证两个节点的时间同步。

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

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

安装Pacemaker + Corosync + crmsh

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

sudo yum install pacemaker
sudo yum install corosync
sudo 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

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

  • 在这里在下犯了一个十分低级的错误,将注释写在了每一行的后面。问题就出现在注释内容和注释之间的几个空格。记得在初次使用linux的时候,创建.desktop文件复制了网上的代码,但是每一行的结尾都多了一个空格,结果这个快捷方式就是不起作用。所以以后写注释一定写在语句的前一行上。
# Please read the corosync.conf.5 manual page
totem {
    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-keygen
Corosync 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 -l
Redirecting 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)心里莫名激动
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
您好!要搭建KVM高可用集群,您可以按照以下步骤进行操作: 1. 安装KVM和相关组件:在每个节点上安装KVM虚拟化软件和相关工具,如libvirt、qemu等。您可以使用包管理工具,如apt、yum等来安装这些软件。 2. 配置共享存储:为了实现高可用,您需要将虚拟机的磁盘镜像文件放置在共享存储上,以便节点间可以访问。您可以选择使用网络存储技术,如NFS、iSCSI、GlusterFS等来搭建共享存储。 3. 设置网络:确保每个节点都有正确的网络配置,包括IP地址、子网掩码、网关等。您还可以使用负载均衡器来实现虚拟机的访问流量分发。 4. 配置群集管理工具:选择适合您需求的群集管理工具,如Pacemaker、Corosync等,并进行相应的配置。这些工具可以监控节点的状态,并在故障发生时自动迁移虚拟机到其他正常节点上。 5. 配置虚拟机迁移:启用虚拟机的迁移功能,以实现在节点间自动迁移虚拟机。这可以通过配置libvirt和相关工具来完成,例如设置节点间的共享存储和网络。 6. 测试高可用集群:在搭建完成后,进行集群的测试和验证。您可以模拟节点故障、网络异常等情况,观察集群的行为是否符合预期。 这是一个基本的框架来搭建KVM高可用集群,具体的实施步骤可能因环境和需求略有不同。希望对您有所帮助!如果您有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值