CentOS> Kernel \r on an \m
[root@test ~]# mysql -uroot -p123 -h192.168.31.132
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.46-log MySQL Community Server (GPL) by Remi
[root@mysql ~]# mysql -u root -p123 -h192.168.31.136
Welcome to the MariaDB monitor. Commands end with ; or \g.
mysql> grant all on *.* to root@'192.168.31.%'> Query OK, 0 rows affected (0.05 sec)
mysql> flush privileges
-> ;
Query OK, 0 rows affected (0.00 sec)
授权之后再在192.168.31.132和192。168.31.136上写mysql.sh检测脚本
如下:
#!/bin/sh
pkill keepalived #检测资源放置脑裂
在测试随便一台服务器:
[root@mysql ~]# mysql -uroot -p123 -h 192.168.31.131
MariaDB [(none)]> show databases; +--------------------+
| Database |
+--------------------+
| information_schema |
| han |
| hanye |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
停掉一台服务器在测试:
valid_lft forever preferred_lft forever
[root@mysql ~]# pkill keepalived
[root@mysql ~]# mysql -uroot -p123 -h 192.168.31.131
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.46-log MySQL Community Server (GPL) by Remi
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog_article02 |
| db1 |
| db2 |
| db3 |
| dbtest1 |
| dbtest2 |
| dbtest3 |
| mycat |
| mysql |
| performance_schema |
| syslog |
+--------------------+
12 rows in set (0.07 sec)
注意:我这边两台服务器的数据是不一致的:更容易发现高可用成功与否!!!
[root@test ~]# ifconfig eth0 | awk -F'[: ]+' '/inet addr/{print $4}'
192.168.31.132
[root@test ~]# mysql -u root -p123
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection> Server version: 5.5.46-log MySQL Community Server (GPL) by Remi
Copyright (c) 2000, 2015, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| blog_article02 |
| db1 |
| db2 |
| db3 |
| dbtest1 |
| dbtest2 |
| dbtest3 |
| mycat |
| mysql |
| performance_schema |
| syslog |
+--------------------+
12 rows in set (0.00 sec
[root@mysql ~]# ifconfig eth0 | awk -F'[: ]+' '/inet addr/{print $4}'
192.168.31.136
[root@mysql ~]# mysql -uroot -p123
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection> Server version: 5.5.32-MariaDB-log MariaDB Server
Copyright (c) 2000, 2013, Oracle, Monty Program Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| han |
| hanye |
| mysql |
| performance_schema |
| test |
+--------------------+
6 rows in set (0.00 sec)
ok了配置完成