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
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
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高可用已经实现了。赞一个。