当前位置: 首页 > 工具软件 > MySQL Router > 使用案例 >

MySQL Router安装与配置

关冠宇
2023-12-01

1. MySQL Router的安装

root@Ubuntu# wget https://downloads.mysql.com/archives/get/p/41/file/mysql-router-8.0.11.tar.gz
root@ubuntu# tar zxvf mysql-router-8.0.11.tar.gz
root@ubuntu# cd mysql-router-8.0.11
root@ubuntu:/mysql-router-8.0.11# cmake ./
root@ubuntu:/mysql-router-8.0.11# make
root@ubuntu:/mysql-router-8.0.11# make install

2. 创建配置文件

# 创建日志目录
root@ubuntu:/mysql-router-8.0.11#mkdir -p /var/log/mysqlrouter/
# 创建配置文件目录
root@ubuntu:/mysql-router-8.0.11#mkdir -p /etc/mysqlrouter
root@ubuntu:/mysql-router-8.0.11#touch /etc/mysqlrouter/mysqlrouter.ini
root@ubuntu:/mysql-router-8.0.11#vim /etc/mysqlrouter/mysqlrouter.ini

3. 编辑配置文件

[DEFAULT]
# 定义日志目录
logging_folder = /var/log/mysqlrouter
[logger]
# 定义日志等级
level = INFO
# 一个高可用的标签
[routing:failover]
bind_address = 0.0.0.0
bind_port = 7001
max_connections = 1024
# 目前就支持两种 : read-write 和 read-only
# read-write:用于高可用,用于可读可写
# read-only:用于负载均衡,只读
mode = read-write
# 实际转发的地址
# 第一个socket如果可用,就一直会使用第一个
# 如果第一个socket无法连接了,才会连接到第二个socket
destinations = 主库ip:3306

#从库
# 一个用于复杂均衡的标签
[routing:balancing]
bind_address = 0.0.0.0
bind_port = 7002
max_connections = 1024
# 用于负载均衡的只读模式
mode = read-only
# 这里的两个socket是轮询用的
destinations = 从库ip:3306

4. 启动

root@ubuntu#mysqlrouter -c /etc/mysqlrouter/mysqlrouter.ini

5.测试

root@VM-4-5-ubuntu:/# mysql -u[用户名] -p[密码] -h [mysqlrouter主机IP] -P 7001 -e "show variables like 'server_id'";
mysql: [Warning] Using a password on the command line interface can be insecure.
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id     | 1     |
+---------------+-------+

 类似资料: