Mysql router 主要用途是读写分离,主主故障自动切换,负载均衡,连接池等。安装如下
下载地址:https://dev.mysql.com/downloads/router/
tar -zxvf mysql-router-2.1.4-el7-x86-64bit.tar.gz
mv mysql-router-2.1.4-el7-x86-64bit /usr/local/mysql-router
配置文件
mkdir /etc/mysql-route/
mkdir -p /data0/log/mysqlrouter
mkdir -p /usr/local/mysql-router/data/keyring-data
chown mysql:mysql /usr/local/mysql-router
chown mysql:mysql /data0/log/mysqlrouter
cp /usr/local/mysql-router/share/doc/mysqlrouter/sample_mysqlrouter.conf /etc/mysql-route/mysqlrouter.conf
vim /etc/mysql-route/mysqlrouter.conf
[DEFAULT]
logging_folder = /data0/log/mysqlrouter
plugin_folder = /usr/local/mysql-router/lib/mysqlrouter
config_folder = /etc/mysql-route/
runtime_folder = /usr/local/mysql-router/run
data_folder = /usr/local/mysql-router/data
keyring_path = /usr/local/mysql-router/data/keyring-data
master_key_path = /usr/local/mysql-router/data/keyring-key
[logger]
level = INFO
[routing:basic_failover]
bind_address=192.168.56.118
bind_port = 7001
mode = read-write
max_connections =256
max_connect_errors =1000
client_connect_timeout =20
destinations = myma1:3306,myma2:3306
[routing:balancing]
bind_address=192.168.56.118
bind_port = 7002
connect_timeout = 20
max_connections = 1024
destinations = myma1:3306,myma2:3306
mode = read-only
# If no plugin is configured which starts a service, keepalive
# will make sure MySQL Router will not immediately exit. It is
# safe to remove once Router is configured.
[keepalive]
interval = 60
启动配置方式
mysqlrouter --config /etc/mysql-route/mysqlrouter.conf &
vim /etc/profile
PATH=/usr/local/mysql-router/bin:$PATH
mkdir /usr/local/mysql-router/scripts/
vim /usr/local/mysql-router/scripts/start_mysqlrouter.sh
#!/bin/bash
/usr/local/mysql-router/bin/mysqlrouter --config /etc/mysql-route/mysqlrouter.conf &
chmod +x start_mysqlrouter.sh
netstat -tunlp
写节点
mysql -h192.168.56.118 -uroot -P7001 -p
读节点
mysql -h192.168.56.118 -uroot -P7002 -p