设为首页 收藏本站
查看: 764|回复: 0

[经验分享] 基于corosync和pacemaker实现drbd+mysql高可用

[复制链接]

尚未签到

发表于 2018-10-2 14:51:04 | 显示全部楼层 |阅读模式
  基于corosync和pacemaker实现drbd+mysql高可用
  环境主机-centos7   node1:172.25.0.29    node2:172.25.0.30
  Mysql,drbd已经安装好,我们重新初始化一下资源:搭建参考文档:
  http://xiaozhagn.blog.51cto.com/13264135/1975397
  Corosync和Pacemaker这里搭建不再演示了,详细可以参考文档:
  http://xiaozhagn.blog.51cto.com/13264135/1976185
  一、
  1、初始化了资源
[root@node1 ~]# crm  
crm(live)# status
  
Stack: corosync
  
Current DC: node2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Wed Oct 25 23:16:23 2017
  
Last change: Wed Oct 25 23:02:04 2017 by root via cibadmin on node1
  
2 nodes configured
  
0 resources configured
  
Online: [ node1 node2 ]
  
No resources
  2、在node1和node2启用和禁用资源:
  手动启用资源,之前我关闭过,现在重启,关闭过的需要这样做
[root@node1 ~]#drbdadm up mysql    ####我已经搭建的drbd名字叫mysql  
[root@node2 ~]#drbdadm up mysql
  
[root@node1 ~]# drbd-overview
  
NOTE: drbd-overview will be deprecated soon.
  
Please consider using drbdtop.
  
1:mysql/0  Connected Secondary/Secondary UpToDate/UpToDate
  
[root@node1 ~]# cat /proc/drbd
  
version: 8.4.10-1 (api:1/proto:86-101)
  
GIT-hash: a4d5de01fffd7e4cde48a080e2c686f9e8cebf4c build by mockbuild@, 2017-09-15 14:23:22
  
1: cs:Connected ro:Secondary/Secondary ds:UpToDate/UpToDate C r-----
  
    ns:0 nr:12 dw:12 dr:0 al:0 bm:0 lo:0 pe:0 ua:0 ap:0 ep:1 wo:f oos:0
  
You have new mail in /var/spool/mail/root
  把node1升为主
[root@node1 ~]#  drbdadm primary mysql  
[root@node1 ~]# drbd-overview
  
NOTE: drbd-overview will be deprecated soon.
  
Please consider using drbdtop.
  
1:mysql/0  Connected Primary/Secondary UpToDate/UpToDate
  ###node1已经升为主模式了
  node2上:
[root@node2 ~]# drbd-overview  
NOTE: drbd-overview will be deprecated soon.
  
Please consider using drbdtop.
  
1:mysql/0  Connected Secondary/Secondary UpToDate/UpToDate
  
[root@node2 ~]# drbd-overview
  
NOTE: drbd-overview will be deprecated soon.
  
Please consider using drbdtop.
  
1:mysql/0  Connected Secondary/Primary UpToDate/UpToDate
  
You have new mail in /var/spool/mail/root
  ##也可以看到node1升为主了
  二、高可用实现drbd+mysql
  1、我们在node1上增加drbd资源,以下操作都在node1上:
[root@node1 ~]# crm  
crm(live)# status
  
Stack: corosync
  
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Thu Oct 26 19:47:56 2017
  
Last change: Thu Oct 26 18:16:45 2017 by root via cibadmin on node1
  
2 nodes configured
  
0 resources configured
  
Online: [ node1 node2 ]
  
No resources       ###没有资源
  
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    ###添加drbd资源
  在pacemaker定义克隆资源的专用属性:
  Clone-max:最多克隆出的资源分数
  Clone-node-max:在单个节点上运行积分克隆
  notify:当一份克隆资源启动或者停止是否通知其他副本。
  Globally-unique:每一分副本是否是否是唯一性(false,true)
  Ordered:所有副本是否串行启动。
  interleave:
  Master-max:最多启动积分master资源
  master-node-max:同一个节点最多运行积分master资源类型
  drbd需要定义资源,现在我们来定义一下drbd
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# show  
node 1: node1 \
  
attributes standby=off
  
node 2: node2
  
primitive mysqldrbd ocf:linbit:drbd \
  
params drbd_resource=mysql \
  
op start timeout=240 interval=0 \
  
op stop timeout=100 interval=0 \
  
op monitor role=Master interval=20 timeout=30 \
  
op monitor role=Slave interval=30 timeout=30
  
ms ms_mysqldrbd mysqldrbd \
  
meta master-max=1 master-node-max=1 clone-max=2 clone-node-max=1 notify=true
  
property cib-bootstrap-options: \
  
have-watchdog=false \
  
dc-version=1.1.16-12.el7_4.4-94ff4df \
  
cluster-infrastructure=corosync \
  
cluster-name=mycluster \
  
stonith-enabled=false \
  
migration-limit=1
  
crm(live)configure# commit    ##提交
  2、接下来我们要增加文件系统资源
crm(live)configure#  primitive mystore ocf:heartbeat:Filesystem params device=/dev/drbd1 directory=/mnt fstype=xfs op start timeout=60 op stop timeout=60    指定drbd磁盘要挂载的目录  
crm(live)configure#  verify
  3、给文件系统类型和drbd做亲缘性绑定(inf为证书为接近,当位负数时候为分离)。
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master  
crm(live)configure# verify
  4、做顺序约束,当drbd起来之后才对文件系统进行绑定:
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start  
crm(live)configure# verify
  
crm(live)configure# commit
  配完后,我们查看一下当前的资源:
crm(live)# status  
Stack: corosync
  
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Thu Oct 26 20:17:20 2017
  
Last change: Thu Oct 26 20:17:02 2017 by root via cibadmin on node1
  
2 nodes configured
  
3 resources configured
  
Online: [ node1 node2 ]
  
Full list of resources:
  
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
  
     Masters: [ node1 ]
  
     Slaves: [ node2 ]
  
mystore(ocf::heartbeat:Filesystem):Started node1
  ###可以发现drbd已经在node1上起来了
  ##查看下node1我们可以发现已经挂载了/mnt目录:
[root@node1 ~]# df -h  
Filesystem           Size  Used Avail Use% Mounted on
  
/dev/mapper/cl-root   18G  2.5G   16G  14% /
  
devtmpfs             226M     0  226M   0% /dev
  
tmpfs                237M  119M  119M  51% /dev/shm
  
tmpfs                237M   13M  224M   6% /run
  
tmpfs                237M     0  237M   0% /sys/fs/cgroup
  
/dev/sda1           1014M  197M  818M  20% /boot
  
tmpfs                 48M     0   48M   0% /run/user/0
  
/dev/drbd1           2.0G   62M  2.0G   4% /mnt
  5、接下来增加一下mysql资源,并作亲缘性绑定:
crm(live)configure# primitive mysqld systemd:mariadb op start timeout=100 op stop timeout=100  
crm(live)configure# colocation mysqld_with_mystore inf: mysqld mystore
  
crm(live)configure# verify
  
crm(live)configure# commit
  6、作顺序约束,先挂载文件系统,然后在启动msyqld资源
crm(live)configure# order mysqld_after_mystore mandatory: mystore mysqld  
crm(live)configure# verify
  
crm(live)configure# commit
  
crm(live)configure# cd
  
crm(live)# status
  
Stack: corosync
  
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Thu Oct 26 20:26:39 2017
  
Last change: Thu Oct 26 20:26:29 2017 by root via cibadmin on node1
  
2 nodes configured
  
4 resources configured
  
Online: [ node1 node2 ]
  
Full list of resources:
  
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
  
     Masters: [ node1 ]
  
     Slaves: [ node2 ]
  
mystore(ocf::heartbeat:Filesystem):Started node1
  
mysqld(systemd:mariadb):Started node1
  ####到这里我们看到mysql已经启动了
  进入数据库我们也可以,看到我们创建的数据库小张
[root@node1 ~]# mysql -uroot -p  
Enter password:
  
Welcome to the MariaDB monitor.  Commands end with ; or \g.
  
Your MariaDB connection id is 2
  
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 |
  
| mysql              |
  
| performance_schema |
  
| test               |
  
| xiaozhang          |
  
+--------------------+
  
5 rows in set (0.03 sec)
  7、我们要增加VIP资源,让它作为虚拟IP调度
[root@node1 ~]# crm  
crm(live)#  configure
  
crm(live)configure#  primitive myvip ocf:heartbeat:IPaddr params ip="172.25.0.100" op monitor interval=20 timeout=20 on-fail=restart      ###添加172.25.0.100作为调度虚拟ip
  
crm(live)configure#  colocation vip_with_ms_mysqldrbd inf: ms_mysqldrbd:Master myvip   ##虚拟ip命名为myip
  
crm(live)configure#  verify
  
crm(live)configure#  commit
  查看一下资源
crm(live)configure# cd  
crm(live)# status
  
Stack: corosync
  
Current DC: node2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Thu Oct 26 21:09:18 2017
  
Last change: Thu Oct 26 21:07:38 2017 by root via cibadmin on node1
  
2 nodes configured
  
5 resources configured
  
Online: [ node1 node2 ]
  
Full list of resources:
  
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
  
     Masters: [ node1 ]
  
     Slaves: [ node2 ]
  
mystore(ocf::heartbeat:Filesystem):Started node1
  
mysqld(systemd:mariadb):Started node1
  
myvip(ocf::heartbeat:IPaddr):Started node1
  ###可以发现三个服务都已经在node1上起来了
  8、最后所有的工作都完成之后,我们测试一下vip:
  先进入数据库我们要给maridb授权
  ####现在我们授权:
[root@node1 ~]# mysql -uroot -p  
Enter password:
  
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)]> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';
  
Query OK, 0 rows affected (0.00 sec)
  
MariaDB [(none)]> FLUSH PRIVILEGES;
  
Query OK, 0 rows affected (0.00 sec)
  现在我们用vip来访问以下
[root@node2 ~]#  mysql -uroot -p123456 -h 172.25.0.100  
Welcome to the MariaDB monitor.  Commands end with ; or \g.
  
Your MariaDB connection id is 4
  
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 |
  
| mysql              |
  
| performance_schema |
  
| test               |
  
| xiaozhang          |
  
+--------------------+
  
5 rows in set (0.00 sec)
  ##可以发现通过vip访问看到我们的数据库
  9、接下来我们要测试drbd+mariadb的高可用,下面我们把node1设置为standby,然后在node2访问:
crm(live)# node standby  
crm(live)# status
  
Stack: corosync
  
Current DC: node2 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
  
Last updated: Thu Oct 26 21:22:38 2017
  
Last change: Thu Oct 26 21:22:15 2017 by root via crm_attribute on node1
  
2 nodes configured
  
5 resources configured
  
Node node1: standby
  
Online: [ node2 ]
  
Full list of resources:
  
Master/Slave Set: ms_mysqldrbd [mysqldrbd]
  
     Masters: [ node2 ]
  
     Stopped: [ node1 ]
  
mystore(ocf::heartbeat:Filesystem):Started node2
  
mysqld(systemd:mariadb):Started node2
  
myvip(ocf::heartbeat:IPaddr):Started node2
  ###查看一下状态,我们可以发现,所以服务已经切换到node2上面去了
[root@node2 ~]# ip addr  
1: lo:  mtu 65536 qdisc noqueue state UNKNOWN qlen 1
  
    link/loopback 00:00:00:00:00:00 brd 00:00:00:00:00:00
  
    inet 127.0.0.1/8 scope host lo
  
       valid_lft forever preferred_lft forever
  
    inet6 ::1/128 scope host
  
       valid_lft forever preferred_lft forever
  
2: ens33:  mtu 1500 qdisc pfifo_fast state UP qlen 1000
  
    link/ether 00:0c:29:64:00:b1 brd ff:ff:ff:ff:ff:ff
  
    inet 172.25.0.30/24 brd 172.25.0.255 scope global ens33
  
       valid_lft forever preferred_lft forever
  
    inet 172.25.0.100/24 brd 172.25.0.255 scope global secondary ens33
  node2上也可以看到虚拟ip了
  接下来我们要访问以下虚拟ip,看看是否可以访问到数据库
[root@node2 ~]#  mysql -uroot -p123456 -h 172.25.0.100  
Welcome to the MariaDB monitor.  Commands end with ; or \g.
  
Your MariaDB connection id is 2
  
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 |
  
| mysql              |
  
| performance_schema |
  
| test               |
  
| xiaozhang          |
  
+--------------------+
  
5 rows in set (0.08 sec)
  ###我们发现vipy已经漂移过来,数据也漂移了过来,证明我们的drbd+mariadb高可用已经实现了。赞一个。



运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-607672-1-1.html 上篇帖子: Centos7环境MySQL安装简易方法 下篇帖子: mysql5.5数据库权限知识补充
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表