corosync+pacemaker部署高可用集群

前期准备,各个节点时间同步。

各个节点可以基于服务器名称互相访问

yum安装corosync和pacemaker

编辑配置corosync配置文件:

totem {
        version: 2
        crypto_cipher: none
        crypto_hash: none
interface {
                ringnumber: 0 #定义ringnumber从0开始,一个ringnumber等于一条心跳链路
                bindnetaddr: 192.168.1.0 #使用的地址段
                mcastaddr: 239.255.61.1 #组播地址
                mcastport: 5405  #主播UDP端口,
                ttl: 1#ttl存活时间为1
        }
}

logging {
        fileline: off
        to_stderr: no #不进行标准输出
        to_logfile: yes #记录log文件
        logfile: /var/log/cluster/corosync.log #日志文件位置
        to_syslog: no #不开启syslog记录
        debug: off #不开启调试模式
        timestamp: on #记录时间戳
        logger_subsys {
                subsys: QUORUM
                debug: off
        }
}

quorum {
     
        provider: corosync_votequorum #开启投票子系统并设置具体方式,默认为关闭
}

nodelist {
        node {
                ring0_addr:192.168.1.61
                nodeid:1
        }
        node {
                ring0_addr:192.168.1.62
                nodeid:2
        }
        node {
                ring0_addr:192.168.1.63
                nodeid:3
        }
}

service {  #定义一个服务来启动pacemaker
    ver: 0    #定义版本
    name: pacemaker  #这个表示启动corosync时会自启动
}    

使用corosync-keygen生成/etc/corosync/authkey文件,这里可以使用-l选项,

corosync-keygen -l -k /etc/corosync/authkey

将/etc/corosync/目录下的authkey corosync.conf同步到其他节点上。

各个节点启动corosync服务。

执行crm_mon

Stack: corosync
Current DC: node63.colinshi.top (version 1.1.18-11.el7_5.2-2b07d5c5a9) - partition with quorum
Last updated: Wed Jun 27 14:38:14 2018
Last change: Wed Jun 27 13:40:48 2018 by root via crm_attribute    on node61.colinshi.top

3 nodes configured
0 resources configured

Online: [ node61.colinshi.top node62.colinshi.top node63.colinshi.top ]

No active resources

可以看到3个节点均上线online状态。

接下来就可以定义资源

这里是使用了crmsh这个软件。用于配置相关资源等。

具体安装参见:https://www.cnblogs.com/colinshi/p/9019804.html

我这边准备配置2组资源一个是,每组资源有一个IP地址和一个服务组成

第一组为IP+nginx

定义2个资源:

  crm configure primitive nginx_ip ocf:heartbeat:IPaddr ip='192.168.1.69'

  crm configure primitive nginx_server systemd:nginx

2个资源合并到一个组内

  crm configure group nginx_group nginx_server systemd:nginx

Stack: corosync
Current DC: node63.colinshi.top (version 1.1.18-11.el7_5.2-2b07d5c5a9) - partition with quorum
Last updated: Thu Jun 28 15:44:19 2018
Last change: Thu Jun 28 15:41:53 2018 by root via cibadmin on node61.colinshi.top

3 nodes configured
2 resources configured

Online: [ node61.colinshi.top node62.colinshi.top node63.colinshi.top ]

Full list of resources:

 Resource Group: nginx_group
     nginx_ip    (ocf::heartbeat:IPaddr):    Started node61.colinshi.top
     nginx_server    (systemd:nginx):    Started node61.colinshi.top

第二组为IP+mysql+文件挂载

定义3个资源

  crm configure primitive mysql_ip ocf:heartbeat:IPaddr ip='192.168.1.68'

  crm configure primitive mysql_server systemd:mysqld

  crm configure primitive mysql_filesystem ocf:heartbeat:Filesystem device='192.168.1.2:/volume1/mydata' directory='/mydata' fstype='nfs' 

定义colocation排列约束确保3个资源在一起

  crm configure colocation mysql_file_with_server inf: mysql_filesystem mysql_server

  crm configure colocation mysql_ip_with_server inf: mysql_ip mysql_server

定义order顺序约束

  crm configure order mysql_file_order_server Serialize: mysql_ip mysql_filesystem mysql_server

搞定:

Stack: corosync
Current DC: node63.colinshi.top (version 1.1.18-11.el7_5.2-2b07d5c5a9) - partition with quorum
Last updated: Fri Jun 29 16:11:54 2018
Last change: Fri Jun 29 16:11:34 2018 by root via crm_attribute on node61.colinshi.top

3 nodes configured
5 resources configured

Online: [ node61.colinshi.top node62.colinshi.top node63.colinshi.top ]

Full list of resources:

 Resource Group: nginx_group
     nginx_ip    (ocf::heartbeat:IPaddr):    Started node62.colinshi.top
     nginx_server    (systemd:nginx):    Started node62.colinshi.top
 mysql_filesystem    (ocf::heartbeat:Filesystem):    Started node61.colinshi.top
 mysql_ip    (ocf::heartbeat:IPaddr):    Started node61.colinshi.top
 mysql_server    (systemd:mysqld):    Started node61.colinshi.top

猜你喜欢

转载自www.cnblogs.com/colinshi/p/9234261.html