前提:
本配置共有两个测试节点,分别node1和node2,相的IP地址分别为202.207.178.6和202.207.178.7
(为避免影响,先关闭防火墙和SElinux)
一、安装配置corosync及相关软件包
1、准备工作
1)节点名称必须跟uname -n命令的执行结果一致
node1:
# hostname node1
# vim /etc/sysconfig/network
HOSTNAME=node1
node2:
# hostname node2
# vim /etc/sysconfig/network
HOSTNAME=node2
2)节点之间必须通过ssh互信通信
[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘
[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
[[email protected] ~]# ssh-keygen -t rsa -f ~/.ssh/id_rsa -P ‘‘
[[email protected] ~]# ssh-copy-id -i .ssh/id_rsa.pub [email protected]
3)集群各节点之间时间必须同步
使用ntp服务器同步时间
ntpdate ip(配置了ntp服务的主机地址)
4)配置本地解析:
[[email protected] ~]# vim /etc/hosts
202.207.178.6 node1
202.207.178.7 node2
[[email protected] ~]# scp /etc/hosts node2:/etc/
2、安装如下rpm包:
cluster-glue,cluster-glue-libs
corosync,corosynclib
heartbeat,heartbeat-libs
libesmtp
pacemaker,pacemaker-cts,pacemaker-libs
resource-agents
# yum install cluster-glue
# yum install --nogpgcheck *.rpm(将heartbeat-3.0.4-2.el6.i686.rpm和heartbeat-libs-3.0.4-2.el6.i686.rpm复制到主目录下进行)
# yum install corosync
# yum -y install libesmtp
# yum install pacemaker
# yum install pacemaker-cts
3.配置corosync,(以下命令在node1上执行)
# cd /etc/corosync
# cp corosync.conf.example corosync.conf
接着编辑corosync.conf,添加如下内容:
修改以下语句:
bindnetaddr: 202.207.178.0 #网络地址,节点所在的网络地址段
secauth: on #打开安全认证
threads: 2 #启动的线程数
to_syslog: no (不在默认位置记录日志)
timestamp: no(这里为了提高系统性能,不记录时间戳,因为记录时间=戳需要系统调用,浪费资源)
添加如下内容,定义pacemaker随corosync启动,并且定义corosync的工作用户和组:
service {
ver: 0
name: pacemaker
}
aisexec {
user: root
group: root
}
生成节点间通信时用到的认证密钥文件:
# corosync-keygen
将corosync和authkey复制至node2:
# scp -p corosync authkey node2:/etc/corosync/
4、尝试启动,(以下命令在node1上执行):
# service corosync start
注意:启动node2需要在node1上使用如上命令进行,不要在node2节点上直接启动
# ssh node2 ‘/etc/init.d/corosync start‘
5、测试是否正常
查看corosync引擎是否正常启动:
# grep -e "Corosync Cluster Engine" -e "configuration file" /var/log/cluster/corosync.log
Oct 23 00:38:06 corosync [MAIN ] Corosync Cluster Engine (‘1.4.7‘): started and ready to provide service.
Oct 23 00:38:06 corosync [MAIN ] Successfully read main configuration file ‘/etc/corosync/corosync.conf‘
查看初始化成员节点通知是否正常发出:
# grep TOTEM /var/log/cluster/corosync.log
Oct 23 00:38:06 corosync [TOTEM ] Initializing transport (UDP/IP Multicast).
Oct 23 00:38:06 corosync [TOTEM ] Initializing transmit/receive security: libtomcrypt SOBER128/SHA1HMAC (mode 0).
Oct 23 00:38:06 corosync [TOTEM ] The network interface [202.207.178.6] is now up.
Oct 23 00:39:35 corosync [TOTEM ] A processor joined or left the membership and a new membership was formed.
检查启动过程中是否有错误产生:
# grep ERROR: /var/log/messages | grep -v unpack_resources
查看pacemaker是否正常启动:
# grep pcmk_startup /var/log/cluster/corosync.log
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: CRM: Initialized
Oct 23 00:38:06 corosync [pcmk ] Logging: Initialized pcmk_startup
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Maximum core file size is: 4294967295
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Service: 9
Oct 23 00:38:06 corosync [pcmk ] info: pcmk_startup: Local hostname: node1
使用如下命令查看集群节点的启动状态:
# crm status
Last updated: Tue Oct 25 17:28:10 2016 Last change: Tue Oct 25 17:21:56 2016 by hacluster via crmd on node1
Stack: classic openais (with plugin)
Current DC: node1 (version 1.1.14-8.el6_8.1-70404b0) - partition with quorum
2 nodes and 0 resources configured, 2 expected votes
Online: [ node1 node2 ]
从上面的信息可以看出两个节点都已经正常启动,并且集群已经处于正常工作状态。
二、配置资源及约束
1、安装crmsh软件包:
pacemaker本身只是一个资源管理器,我们需要一个接口才能对pacemker上的资源进行定义与管理,而crmsh即是pacemaker的配置接口,从pacemaker 1.1.8开始,crmsh 发展成一个独立项目,pacemaker中不再提供。crmsh提供了一个命令行的交互接口来对Pacemaker集群进行管理,它具有更强大的管理功能,同样也更加易用,在更多的集群上都得到了广泛的应用,类似软件还有 pcs;
在/etc/yum.repo.d/ 下的配置文件中添加以下内容
[ewai]
name=aaa
baseurl=http://download.opensuse.org/repositories/network:/ha-clustering:/Stable/CentOS_CentOS-6/
enabled=1
gpgcheck=0
# yum clean all
# yum makecache
[[email protected] yum.repos.d]# yum install crmsh
2、检查配置文件有无语法错误
crm(live)configure# verify
我们里可以通过如下命令先禁用stonith:
# crm configure property stonith-enabled=false
或 crm(live)configure# property stonith-enabled=false
crm(live)configure# commit
3、配置资源(配置一个web服务集群。前提已经安装了httpd服务,并使其不能开机自动启动)
crm(live)configure# primitive webip ocf:heartbeat:IPaddr params ip=202.207.178.4 nic=eth0 cidr_netmask=24
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# primitive httpd lsb:httpd
crm(live)configure# commit
crm(live)configure# group webservice webip httpd
crm(live)configure# commit
至此,资源配置完毕,现在可以启动测试了!
欢迎批评指正!