10.Mysql-router

MysqL-router是一个轻量级的中间间,可以做MysqL的故障自动转移以及读写分离功能

1.官网下载MysqL-router二进制包

2.主机介绍:

 

3.创建目录

>>mkdir  -p  /var/log/MysqLrouter         :日志目录

>>mkdir -p /etc/MysqLrouter/MysqLrouter.conf  :这个是配置文件

[root@node04 MysqLrouter]# cat MysqLrouter.conf 
[default]
logging_folder=/var/log/MysqLrouter

[logger]
Leverl=info

[routing:failover]
bind_address=0.0.0.0
bind_port=7001
max_connections=1024
mode=read-write
destinations=192.168.11.4:3307,192.168.11.5:3307

[routing:balancing]
bind_address=0.0.0.0
bind_port=7002
max_connections=1024
mode=read-only
destinations=192.168.11.5:3307,192.168.11.6:3307

4.启动

MysqLrouter --config=/xxxx/MysqLrouter.conf

可以用启动脚本进行启动    

说明:7001端口是故障自动切换端口以及可读写

   7002端口是负载均衡端口,可以实现负载均衡效果,但是只能读,不能写

5.效果如下:

[root@node04 bin]# ./MysqL -uMysqLrouter -p123 -h192.168.11.7 -P7002 -e 'select @@server_id'
MysqL: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
|          67 |
+-------------+
[root@node04 bin]# ./MysqL -uMysqLrouter -p123 -h192.168.11.7 -P7002 -e 'select @@server_id'
MysqL: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
|          57 |
+-------------+
[root@node04 bin]# ./MysqL -uMysqLrouter -p123 -h192.168.11.7 -P7002 -e 'select @@server_id'
MysqL: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
|          67 |
+-------------+
[root@node04 bin]# ./MysqL -uMysqLrouter -p123 -h192.168.11.7 -P7002 -e 'select @@server_id'
MysqL: [Warning] Using a password on the command line interface can be insecure.
+-------------+
| @@server_id |
+-------------+
|          57 |
+-------------+

 参考:https://dev.mysql.com/doc/mysql-router/8.0/en/mysql-router-preface.html

相关文章

优化MySQL数据库发布系统存储的方法有:1.mysql库主从读写分...
使用mysql的方法:在“我的电脑”→右键→“管理”→“服务”...
在mysql中查看root用户权限的方法:1.命令行启动mysql服务;...
MySQL主从复制是用来备份一个与主数据库一样环境的从数据库,...
运行mysql的方法1.启动mysql服务,在“我的电脑”→右键→“...
开启mysql的方法1.可以通过快捷键win+r,输入cmd,打开窗口,...