dfsfd 发表于 2017-10-26 09:07:16

drbd + mysql 高可用集群

在上两篇中,我分别写到了 drbd 和 corosync、pacemaker、crm 的配置和使用,在本节中,我讲这两种东西结合起来,做出 drbd + mysql 高可用集群。
一、实验环境

系统版本:centos7
实验机器:
    node1:192.168.163.172
    node2:192.168.163.173
软件源:阿里云


二、实验过程

drbd 的配置和 corosync 的配置就不再说明,直接开始
首先增加drbd资源


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
crm(live)configure#ms ms_mysqldrbd mysqldrbd meta master-max=1 master-node-max=1 clone-max=2clone-node-max=1 notify=true
crm(live)configure#verify
crm(live)configure#show
crm(live)configure# show
node 1: node1
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





增加文件系统资源

1
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做亲缘性绑定


1
crm(live)configure# colocation mystore_with_ms_mysqldrbd inf: mystore ms_mysqldrbd:Master






做顺序约束,当drbd起来之后才对文件系统进行绑定

1
crm(live)configure# order mystore_after_ms_mysqldrbd mandatory: ms_mysqldrbd:promote mystore:start





接下来增加一下mysql资源,并作亲缘性绑定

1
2
crm(live)configure#primitive mysqld systemd:mariadb
crm(live)configure# colocation mysqld_with_mystoreinf: mysqld mystore








作顺序约束,先挂载文件系统,然后在启动msyqld资源

1
crm(live)configure#order mysqld_after_mystore mandatory: mystore mysqld






增加VIP资源,作虚拟IP调度

1
2
3
crm(live)#configure
crm(live)configure#primitive myvip ocf:heartbeat:IPaddr params ip="192.168.113.120" opmonitor interval=20 timeout=20 on-fail=restart
crm(live)configure#colocation vip_with_ms_mysqldrbd inf:ms_mysqldrbd:Master myvip






检查并提交

1
2
crm(live)configure#verify
crm(live)configure#commit






查看状态


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
crm(live)# status
Stack: corosync
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 08:38:22 2017
Last change: Wed Oct 25 08:38:14 2017 by root via crm_attribute on node2
2 nodes configured
5 resources configured
Online: [ node1 node2 ]
Full list of resources:
Master/Slave Set: ms_mysqldrbd
   Masters: [ node1 ]
   Slaves: [ node2 ]
mystore(ocf::heartbeat:Filesystem):Started node1
mysqld(systemd:mariadb):Started node1
myvip(ocf::heartbeat:IPaddr):Started node1





三、测试

先访问数据库,并新建一个用户,供远程访问使用

1
2
MariaDB[(none)]> GRANT ALL ON *.* TO 'root'@'%' IDENTIFIED BY '123456';            
QueryOK, 0 rows affected (0.00 sec)






使用VIP访问数据库

# mysql -uroot -p123456 -h 192.168.163.100

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
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|
| #mysql50#lost+found |
| mysql               |
| mysqld            |
| performance_schema|
| xhk               |
| xhk777            |
+---------------------+
7 rows in set (0.06 sec)





接下来,将node停掉,服务自行转到node2

1
crm(live)# node standby





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
crm(live)# status
Stack: corosync
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 08:43:46 2017
Last change: Wed Oct 25 08:43:41 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
   Slaves: [ node2 ]
   Stopped: [ node1 ]
mystore   (ocf::heartbeat:Filesystem):    Stopped
mysqld    (systemd:mariadb):Stopped





1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
crm(live)# status
Stack: corosync
Current DC: node1 (version 1.1.16-12.el7_4.4-94ff4df) - partition with quorum
Last updated: Wed Oct 25 08:43:46 2017
Last change: Wed Oct 25 08:43:41 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
   Slaves: [ node2 ]
   Stopped: [ node1 ]
mystore(ocf::heartbeat:Filesystem):Stopped
mysqld(systemd:mariadb):Stopped
myvip(ocf::heartbeat:IPaddr):Started node2





继续使用VIP访问数据库

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# mysql -uroot -p123456 -h 192.168.163.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|
| #mysql50#lost+found |
| mysql               |
| mysqld            |
| performance_schema|
| xhk               |
| xhk777            |
+---------------------+
7 rows in set (0.06 sec)





页: [1]
查看完整版本: drbd + mysql 高可用集群