配制文件:
/etc/mysqlrouter/mysqlrouter.ini
[DEFAULT]
logging_folder = /var/log/mysql-router
plugin_folder = /usr/local/mysql-router/lib/mysqlrouter
runtime_folder = /usr/local/mysql-router
[logger]
# 定义日志等级
level = INFO
[routing:balancing]
bind_address = 0.0.0.0
bind_port = 7002
max_connections = 1024
mode = read-only
destinations = 10.24.220.70:3306, 10.169.214.33:3306
起动:
./mysqlrouter -c /etc/mysqlrouter/mysqlrouter.ini &
测试:自动均衡负载
mysql router 安装在monitor 上,
10.169.216.172是其中一个网卡
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P 7002 -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 101 |
+---------------+-------+
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P 7002 -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 102 |
+---------------+-------+
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P 7002 -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 101 |
+---------------+-------+
[root@monitor bin]# mysql -u root -p -h 10.169.216.172 -P 7002 -e "show variables like 'server_id'";
Enter password:
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| server_id | 102 |
+---------------+-------+