CentOS6.9:corosync + pacemaker
test2: 192.168.10.162 主机名:test2
test3: 192.168.10.163 主机名:test3
test2、test3的/etc/hosts文件中添加:
192.168.10.162 test2
192.168.10.163 test3
test2、test3节点时间要同步。
一、corosync安装配置
1、test2、test3安装corosync 、pacemaker
[root@test2 ~]# yum install corosync pacemaker -y
[root@test3 ~]# yum install corosync pacemaker -y
2、corosync配置
在test2节点上配置corosync
[root@test2 ~]# cd /etc/corosync/
[root@test2 corosync]# cp corosync.conf.example corosync.conf
[root@test2 corosync]# vim corosync.conf
compatibility: whitetank
totem {
version: 2
secauth: on
threads: 0
interface {
ringnumber: 0
bindnetaddr: 192.168.10.0
mcastaddr: 239.255.21.1
mcastport: 5405
ttl: 1
}
}
logging {
fileline: off
to_stderr: no
to_logfile: yes
logfile: /var/log/cluster/corosync.log
to_syslog: no
debug: off
timestamp: on
logger_subsys {
subsys: AMF
debug: off
}
}
service {
ver: 0
name: pacemaker
}
3、生成密钥文件
[root@test2 corosync]# corosync-keygen
4、将配置好的corosync.conf文件和密钥文件authkey发给test3放在/etc/corosync/目录下
[root@test2 corosync]# scp -p corosync.conf authkey test3:/etc/corosync/
5、test2、test3启动corosync服务:
[root@test2 ~]# service corosync start
[root@test3~]# service corosync start
二、pcs安装配置
1、test2、test3节点安装启动pcs
[root@test2 ~]# yum install pcs -y
[root@test3~]# yum install pcs -y
[root@test2 ~]# service pcsd start
[root@test3 ~]# service pcsd start
[root@test2 ~]# chkconfig pcsd on
[root@test3~]# chkconfig pcsd on
2、使用ansible批量设置密码:
2.1下载安装ansible:
[root@test2 ~]# yum install ansible -y
ansible的配置文件hosts
[root@test2 ~]# vim /etc/ansible/hosts
[ha]
192.168.10.162
192.168.10.163
2.2 集群用户密码设置:
[root@test2 ~]# ansible ha -m shell -a 'echo 123456 | passwd –stdin hacluster'
3、验证集群
[root@test2 ~]# pcs cluster auth test2 test3 -u hacluster
test2、test3两个节点认证通过。
三、安装httpd
test2、test3安装httpd:
[root@test2 ~]# ansible ha -m yum -a 'name=httpd state='present'
测试页:
[root@test2 ~]# echo "<h1> Test Page On test2…</h1>" > /var/www/html/index.html
[root@test3 ~]# echo "<h1> Test Page On test3…</h1>" > /var/www/html/index.html
[root@test2 ~]# ansible ha -m shell -a 'chkconfig httpd off'
四、集群构建
1、新建集群(名称为:tcluster)
[root@test2 ~]# pcs cluster setup –name tcluster test2 test3
[root@test2 ~]# pcs property set stonith-enabled=false
[root@test2 ~]# pcs property set no-quorum-policy=ignore
2、集群资源配置
webip:192.168.10.55
[root@test2 ~]# pcs resource create webip ocf:heartbeat:IPaddr params ip=192.168.10.55 op monitor interval=10s timeout=20s
webserver:httpd
[root@test2 ~]# pcs resource create webserver lsb:httpd op monitor interval=20s timeout=30s
查看资源状态:
资源平均分配在两个节点上,所以必须设置资源约束。
3、资源约束
colocation排列约束:webserver必须跟webip在同一节点
[root@test2 ~]# pcs constraint colocation add webserver with webip
order顺序约束:先有webip,再启动webserver
[root@test2 ~]# pcs constraint order webip then webserver
location位置约束:资源对节点的倾向性
[root@test2 ~]# pcs constraint location webip prefers test2
查看资源约束:
[root@test2 ~]# pcs constraint location show
[root@test2 ~]# pcs constraint colocation show
[root@test2 ~]# pcs constraint order show
移除位置约束:
pcs constraint location remove 资源id
资源id可以使用pcs config查看
节点下线:
[root@test3 ~]# pcs cluster unstandby test3
节点上线:
[root@test3 ~]# pcs cluster unstandby test3