Corosync是集群管理套件的一部分,他在传递信息的时候通过一个简单的配置文件来定义信息传递的方式和协议等,其中最主要的是可以提供心跳信息传输。
pacemaker是一个集群资源管理器,他利用集群的基础结构,例如corosync提供的信息he成员管理能力,来探测并从节点或资源级别故障中恢复,实现集群的高可用性。
环境:
centosa:192.168.40.12
centosb:192.168.40.19
实验的三点基础:主机之间ssh互信;时间同步;域名能互相通信。
两个节点停止要接收管理的服务:
systemctl stop drbd
systemctl stop mariadb
两个节点安装软件:
yum install -y pcs
yum install -y corosync
yum install -y pacemaker
安装crm:
tar -xf crmsh-2.3.2.tar
cd crmsh-2.3.2
python setup.py install
开始定义资源:
[root@centosa ~]# crm
crm(live)# configure
crm(live)configure# primitive mysqldrbd ocf:linbit:drbd params drbd_resource=mysql op start timeout=240 op stop timeout=100 op monitor role=Master interval=20 timeout=30 op monitor role=Slave interval=30 timeout=30 ##添加一个名为mysqldrbd的资源
crm(live)configure# verify ##检查是否有问题
crm(live)configure# ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true ##设置主从
crm(live)configure# verify
crm(live)configure# commit ##检查没问题后保存设置
查看一下状态:
crm(live)configure# cd
crm(live)# status
Stack: corosync
Current DC: centosb (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 20:18:22 2017
Last change: Wed Oct 25 20:18:04 2017 by root via crm_attribute on centosb
2 nodes configured
2 resources configured
Online: [ centosa centosb ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ centosa ]
Slaves: [ centosb ]
添加一个文件挂载资源:
crm(live)configure# primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/data fstype=xfs op start timeout=60 op stop timeout=60 绑定文件资源和drbd主从为亲缘关系(当drbd为主时):
crm(live)configure# colocation ms_mysqldrbd_with_mystore inf: mystore ms_mysqldrbd:Master 设定文件资源和drbd启动的先后顺序(当drbd状态提升时,文件资源系统才挂载):
crm(live)configure# order mystore_after_ms_mysqldrbd Mandatory: ms_mysqldrbd:promote mystore:start 检查并保存:
crm(live)configure# verify
crm(live)configure# commit
添加mysql资源,并与文件资源绑定为亲缘关系然后设置先后顺序:
crm(live)configure# primitive mysqld systemd:mariadb
crm(live)configure# colocation mysqld_with_mystore inf: mysqld mystore
crm(live)configure# order mysqld_after_mystore Mandatory:mystore mysqld
crm(live)configure# verify
crm(live)configure# commit
添加vip资源(并与drbd的主状态绑定):
crm(live)configure# primitive vip ocf:heartbeat:IPaddr params ip=192.168.40.100 op monitor interval=20 timeout=20 on-fail=restart
crm(live)configure# colocation vip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master vip
设置先启动mysqld在启动vip:
crm(live)configure# order vip_after_mysqld Mandatory: mysqld vip 保存并查看状态:
crm(live)configure# verify
crm(live)configure# commit
crm(live)configure# cd
crm(live)# status
Stack: corosync
Current DC: centosb (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 20:41:40 2017
Last change: Wed Oct 25 20:41:34 2017 by root via cibadmin on centosa
2 nodes configured
5 resources configured
Online: [ centosa centosb ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ centosa ]
Slaves: [ centosb ]
mystore(ocf::heartbeat:Filesystem):Started centosa
mysqld(systemd:mariadb):Started centosa
vip(ocf::heartbeat:IPaddr):Started centosa
在本地登录数据库,并创建一个数据库,然后设置给远程登录的权限:
MariaDB [(none)]> create database hatest;
MariaDB [(none)]> grant all on *.* to 'root'@'%' identified by '123456';
然后在远程用vip登录:
[root@centos1 ~]# mysql -uroot -p123456 -h192.168.40.100
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| centos |
| hatest |
| mysql |
| performance_schema |
| test |
+--------------------+
看到有一个添加的数据库。
把主的节点停掉:
crm(live)# node standby 然后查看状态,会发现按先后顺序切换到centosb
crm(live)# status
Stack: corosync
Current DC: centosb (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 21:45:54 2017
Last change: Wed Oct 25 21:21:31 2017 by root via crm_attribute on centosb
2 nodes configured
5 resources configured
Node centosa: standby
Online: [ centosb ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
Masters: [ centosb ]
Stopped: [ centosa ]
mystore(ocf::heartbeat:Filesystem):Started centosb
mysqld(systemd:mariadb):Started centosb
vip(ocf::heartbeat:IPaddr):Started centosb
远程登录,查看数据库:
[root@centos1 ~]# mysql -uroot -p123456 -h192.168.40.100
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 5.5.56-MariaDB MariaDB Server
Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases
-> ;
+--------------------+
| Database |
+--------------------+
| information_schema |
| centos |
| hatest |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
运维网声明
1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网 享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com