keepalived mysql 主主_keepalived打造mysql主主高可用

注意:要在两个服务器都要给其用户授权:不然报错如下

[root@test ~]# mysql -uroot -p123 -h192.168.31.131

ERROR 1045 (28000): Access denied for user 'root'@'192.168.31.131' (using password: YES)

解决办法:

mysql> grant all on *.* to root@'192.168.31.%' identified by '123';

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 id is 54

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 id is 86

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 id is 734

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了配置完成

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值