corosync是高可用集群中的Cluster Messaging Layer(集群信息层),是主要传递发集群信息与心跳信息的,并没有资源管理功能,资源管理还得依赖于上层的crm(Cluster resource Manager,集群资源管理器),最著名的资源管理器,就是pacemaker,现在corosync+pacemaker成了高可用集群中的最佳组合.
pacemaker的配置命令行接口有两种,一是crmsh,另一个是pcs,这里主里以crmsh的使用为例
实例:
准备两台主机192.168.0.188, 192.168.0.150 环境都为CentOS7.2
准备工作:
1.时间同步ntp
[root@node3 ~]# ntpdate 192.168.0.111
20 Aug 10:29:12 ntpdate[4861]: step time server 192.168.0.111 offset -48.870862 sec
###都使用同步至时间服务器
[root@node3 ~]# crontab -e
*/5 * * * * /usr/sbin/ntpdate 192.168.0.111 &> /dev/null ###每5分钟与时间服务器同步一次
2.dns解析文件需能互相解析主机名
配置/etc/hosts文件实现
[root@node1 ~]# cat /etc/hosts
192.168.0.188 node1.xiao.com node1
192.168.0.150 node2.xiao.com node2
两台都需配置。
3.主机名需与配置文件保持一致,修改主机名
[root@node1 ~]# hostname set-hostname node1.xiao.com
至此开始安装
[root@node1 ~]# yum install pacemaker -y ###安装会依赖于corosync
[root@node1 ~]# cd /etc/corosync/
[root@node1 corosync]# cp corosync.conf.example corosync.conf ###使用此示例模板为配置文件
totem{}:节点间的通信方式,通信协议,加密与否...
logging{}:日志系统,日志记录方式及存储位置
quorum{}:投票系统
nodelist{}:节点列表
[root@node1 dylan]# corosync-keygen -l ###传递心跳信息时的预共享密钥,生成密钥时需要用到 /dev/random 一共需要1024位的长度,此处使用简单方式生成-l
生成的密钥文件权限为400
[root@node1 corosync]# grep -v "^[[:space:]]*#" corosync.conf |grep -v "^$" ###配置示例
totem {
version: 2
cluster_name: mycluster
crypto_cipher: aes128
crypto_hash: sha1
interface {
ringnumber: 0
bindnetaddr: 192.168.0.0
mcastaddr: 239.255.10.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: yes
debug: off
timestamp: on
logger_subsys {
subsys: QUORUM
debug: off
}
}
quorum {
provider: corosync_votequorum
}
nodelist {
node {
ring0_addr: 192.168.0.188
nodeid: 1
}
node {
ring0_addr: 192.168.0.150
nodeid: 2
}
}
[root@node1 corosync]# scp corosync.conf authkey root@node2:/etc/corosync/ ###相同的配置文件复制一份到node2 节点
[root@node1 ~]# systemctl start corosync.service
[root@node1 ~]# ss -unl
UNCONN 0 0 239.255.10.1:5405 *:*
UNCONN 0 0 192.168.0.188:5405 *:*
[root@node1 ~]# tail /var/log/cluster/corosync.log ###查看日志信息
Aug 21 08:14:32 [19049] node1.xiao.com corosync notice [QUORUM] Members[1]: 1
Aug 21 08:14:32 [19049] node1.xiao.com corosync notice [MAIN ] Completed service synchr
onization, ready to provide service.Aug 21 08:15:09 [19049] node1.xiao.com corosync notice [TOTEM ] A new membership (192.16
8.0.150:20) was formed. Members joined: 2Aug 21 08:15:09 [19049] node1.xiao.com corosync notice [QUORUM] This node is within the
primary component and will provide service.Aug 21 08:15:09 [19049] node1.xiao.com corosync notice [QUORUM] Members[2]: 2 1
Aug 21 08:15:09 [19049] node1.xiao.com corosync notice [MAIN ] Completed service synchr
onization, ready to provide service.
[root@node1 corosync]# systemctl start pacemaker.service ###启动pacemaker
[root@node1~]# crm_mon###查看状态
Stack: corosync
Current DC: node1.xiao.com (version 1.1.15-11.el7_3.5-e174ec8) - partition with quorum
Last updated: Mon Aug 21 08:27:10 2017 Last change: Mon Aug 21 08:26:03 2017 by
hacluster via crmd on node1.xiao.com
2 nodes and 0 resources configured
Online: [ node1.xiao.com node2.xiao.com ] ###两台都在线
No active resources
要使用crmsh
[root@node1 ~]# yum localinstall crmsh-2.1.4-1.1.x86_64.rpm pssh-2.3.1-4.2.x86_64.rpm python-pssh-2.3.1-4.2.x86_64.rpm
###安装这三个包,crmsh会依赖于pssh-2.3.1-4.2.x86_64.rpm python-pssh-2.3.1-4.2.x86_64.rpm
转载于:https://blog.51cto.com/rylan/1957954