1.安装
rpm -ivh mysql-router-2.0.4-1.el6.x86_64.rpm
2.配置
cat >/etc/mysqlrouter/mysqlrouter.ini <<EOF
[DEFAULT]
logging_folder = /var/log/mysqlrouter/
plugin_folder = /usr/lib64/mysqlrouter
runtime_folder = /var/run/mysqlrouter
config_folder = /etc/mysqlrouter
hostname=192.168.1.201
[logger]
level = info
# 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
[routing:read_write]
#将router绑定到哪个NIC
bind_address = {hostname}:7001
#将路由的后端db列表,rw模式将采用first available模式轮训
#ro模式采用round-robin模式轮训
destinations = {hostname}:3306
mode = read-write
# default 512,like mysql's max_connections
max_connections = 1024
#default 100,like mysql's ax_connect_errors
max_connect_errors = 100
#default 9,like mysql's connect_timeout
client_connect_timeout = 9
[routing:read_only]
bind_address = {hostname}:7002
destinations = {hostname}:3306,{hostname}:3307,{hostname}:3308
mode = read-only
max_connections = 65535
max_connect_errors = 100
client_connect_timeout = 9
EOF
3.启动
service mysqlrouter start
4.测试
[root@localhost ~]# netstat -ntpl|grep mysqlrouter
tcp 0 0 192.168.1.201:7001 0.0.0.0:* LISTEN 20498/mysqlrouter
tcp 0 0 192.168.1.201:7002 0.0.0.0:* LISTEN 20498/mysqlrouter
5.连接
mysql -uroot -p123456 -P7002 -h192.168.1.201