mysql-router是mysql官方的轻量级的中间件主要有如下工能:
功能 & 特性:
1、流量分发(只向一个实例导入流量、如果当前的实例宕机了、就会向集群的下一个实例导入流量)
2、一定的高可用能力
3、比之前的官方中间件mysql-proxy性能上有好一点
4、可以与mysql-fabric整合
1、下载
https://dev.mysql.com/get/Downloads/MySQL-Router/mysql-router-2.0.4-linux-glibc2.12-x86-64bit.tar.gz
2、安装
tar -xzvf mysql-router-2.0.4-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
ln -s /usr/local/mysql-router-2.0.4-linux-glibc2.12-x86-64bit /usr/local/mysqlrouter
export/usr/local/mysqlrouter/bin/:$PATH
3、测试安装是否成功
mysqlrouter --help
MySQL Router v2.0.4 on Linux (64-bit) (GPL community edition)
Copyright (c)2015, 2016, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Start MySQL Router.
Configuration read from the following filesinthe given order (enclosedin parentheses means not available forreading):
(./mysqlrouter.ini)
(/root/.mysqlrouter.ini)
Usage: mysqlrouter [-v|--version] [-h|--help]
[-c|--config=]
[-a|--extra-config=]
Options:-v, --version
Display version information and exit.-h, --help
Display this help and exit.-c , --config Only read configuration from givenfile.-a , --extra-config Read thisfileafter configuration files are read from either
default locations or from files specified by the--config
option.
4、配置mysql-router
/usr/local/mysqlrouter/etc/mysqlrouter.cnf
[DEFAULT]
logging_folder=/usr/local/mysqlrouter/run/plugin_folder=/usr/local/mysqlrouter/lib/mysqlrouter/runtime_folder=/usr/local/mysqlrouter/run/config_folder=/usr/local/mysqlrouter/etc/[logger]
level=debug
[routing:7001]
bind_address=0.0.0.0:7001connect_timeout=2mode=read-write#[read-write | read-only]
max_connections =256max_connect_errors=1000client_connect_timeout=2destinations=127.0.0.1:3307,127.0.0.1:3308,127.0.0.1:3309
5、为了测试mysql-router的功能(读写分离+高可用)、于是初始化三个实例(3307,3308,3309)各个实例的配置文件如下
3307
[mysql]
auto-rehash
[mysqld]####: for global
user =mysql #mysql
basedir =/usr/local/mysql #/usr/local/mysql/
datadir =/usr/local/datas/3307 #/usr/local/mysql/data
server_id =1 #0
port =3307 #3306
character_set_server =utf8 #latin1
log_timestamps =system #utc
socket =mysql.sock #/tmp/mysql.sock
read_only =0 #off
skip-slave-start =1 #
auto_increment_increment =1 #1
auto_increment_offset =1 #1
lower_case_table_names =1 #0
secure_file_priv = #null
####: for binlog
binlog_format =row #row
log_bin =mysql-bin #off
binlog_rows_query_log_events =on #off
log_slave_updates =on #off
expire_logs_days =4 #0
binlog_cache_size =32768 #32768(32k)
binlog_checksum =none #CRC32
sync_binlog =1 #1
####: for error-log
log_error =error.log #/usr/local/mysql/data/localhost.localdomain.err
####: for slow query log
####: for gtid
gtid_executed_compression_period =1000 #1000
gtid_mode =on #off
enforce_gtid_consistency =on #off
####: for replication
master_info_repository =table #file
relay_log_info_repository =table #file
####: for group replication
transaction_write_set_extraction =XXHASH64 #off
loose-group_replication_group_name ="aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa" #
loose-group_replication_start_on_boot =off #off
loose-group_replication_local