MySQL Router is a building block for high availability (HA) solutions. It simplifies application development
by intelligently routing connections to MySQL servers for increased performance and reliability.

MySQL Router 8 fully supports MySQL 5.7 and MySQL 8, and it replaces the MySQL Router 2.x series. If
you currently use Router 2.0 or 2.1 then we recommend upgrading your installation to MySQL Router 8.

1 mysql router 安装

==mysqlroueter 2.1,本测试环境是mysql 5.6.15, Kylin Linux release 3.3.1707 (Core)
[root@mysqlhq soft]# rpm -ivh mysql-router-2.1.6-1.el6.x86_64.rpm
warning: mysql-router-2.1.6-1.el6.x86_64.rpm: Header V3 DSA/SHA1 Signature, key ID 5072e1f5: NOKEY
Preparing... ################################# [100%]
Updating / installing...
1:mysql-router-2.1.6-1.el6 ################################# [100%]
[root@mysqlhq soft]# whereis mysqlrouter
mysqlrouter: /usr/bin/mysqlrouter /usr/lib64/mysqlrouter /etc/mysqlrouter
[root@mysqlhq soft]# ll /usr/bin/mysqlrouter
-rwxr-xr-x 1 root root 23592 Feb 21 2018 /usr/bin/mysqlrouter
[root@mysqlhq soft]# which mysqlrouter
/usr/bin/mysqlrouter
[root@mysqlhq soft]# rpm -qa|grep mysql-router
mysql-router-2.1.6-1.el6.x86_64
[root@mysqlhq soft]# ll /etc/mysqlrouter/
total 4
-rw-r--r-- 1 root root 1231 Feb 21 2018 mysqlrouter.conf
[root@mysqlhq soft]# ll /etc/init.d/mysqlrouter
-rwxr-xr-x 1 root root 2879 Feb 21 2018 /etc/init.d/mysqlrouter
[root@mysqlhq ~]# ll /usr/lib64/mysqlrouter
total 2592
-rwxr-xr-x 1 root root 9424 Feb 21 2018 keepalive.so
-rwxr-xr-x 1 root root 24136 Feb 21 2018 logger.so
-rwxr-xr-x 1 root root 124416 Feb 21 2018 metadata_cache.so
-rwxr-xr-x 1 root root 30096 Feb 21 2018 mysql_protocol.so
-rwxr-xr-x 1 root root 210504 Feb 21 2018 routing.so
-rwxr-xr-x 1 root root 2241288 Feb 21 2018 x_protocol.so #m-s架构
#m 192.168.19.145
#s 192.168.19.227
[root@mysqlhq mysqlrouter]# vim mysqlrouter.conf
[DEFAULT]
logging_folder = /var/log/mysqlrouter/
plugin_folder = /usr/lib64/mysqlrouter
runtime_folder = /var/run/mysqlrouter
config_folder = /etc/mysqlrouter [logger]
level = info [routing:read_write]
bind_address = 192.168.19.145
bind_port = 7001
mode = read-write
destinations = 192.168.19.145:3306,192.168.19.227:3306
max_connections = 1024
max_connect_errors = 100
client_connect_timeout = 6
connect_timeout=3
# 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.
[routing:read_only]
bind_address = 192.168.19.145
bind_port = 7002
mode = read-only
destinations = 192.168.19.145:3306,192.168.19.227:3306
max_connections = 1024
max_connect_errors = 100
client_connect_timeout = 6
connect_timeout=3 [keepalive]
interval = 60
[root@mysqlhq mysqlrouter]# mysqlrouter -v
MySQL Router v2.1.6 on Linux (64-bit) (GPL community edition)
[root@mysqlhq mysqlrouter]# groupadd mysqlrouter
groupadd: group 'mysqlrouter' already exists
[root@mysqlhq mysqlrouter]# useradd -g mysqlrouter mysqlrouter
useradd: user 'mysqlrouter' already exists
[root@mysqlhq mysqlrouter]# id mysqlrouter
uid=989(mysqlrouter) gid=984(mysqlrouter) groups=984(mysqlrouter)
[root@mysqlhq mysqlrouter]# chown -R mysqlrouter:mysqlrouter /etc/mysqlrouter
[root@mysqlhq mysqlrouter]# /usr/bin/mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf &
[1] 3577
[root@mysqlhq mysqlrouter]# ps -ef|grep mysqlrouter
root 3577 831 0 16:57 pts/0 00:00:00 /usr/bin/mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf
root 3588 831 0 16:57 pts/0 00:00:00 grep --color=auto mysqlrouter
[root@mysqlhq mysqlrouter]# netstat -lnt|grep 7001
tcp 0 0 192.168.19.145:7001 0.0.0.0:* LISTEN [root@mysqlhq ~]# cd /var/log/mysqlrouter/
[root@mysqlhq mysqlrouter]# vim mysqlrouter.log
2019-01-14 16:57:10 WARNING [7f266a1d1700] [routing:read_only] setup_tcp_service() error from bind(): Cannot assign requested address
2019-01-14 16:57:10 ERROR [7f266a1d1700] routing:read_only: Setting up TCP service using 192.168.20.118:7002: [routing:read_only] Failed to setup service socket: Cannot assign requested address
2019-01-14 16:57:10 INFO [7f26699d0700] [routing:read_write] started: listening on 192.168.19.145:7001; read-write
2019-01-14 16:57:10 INFO [7f266a9d2700] keepalive started with interval 60
2019-01-14 16:57:10 INFO [7f266a9d2700] keepalive
2019-01-14 16:58:10 INFO [7f266a9d2700] keepalive

2 启动,测试mysql router

[mysql@mysqlhq ~]$ mysql  -h 192.168.19.145  -u system -p*** -P 7001
Warning: Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 312548
Server version: 5.6.15-log MySQL Community Server - (GPL) Copyright (c) 2000, 2013, 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. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. (system@192.168.19.145:7001) [(none)]> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| test |
| zabbix |
+--------------------+
(system@192.168.19.145:7001) [(none)]> show variables like '%read_only%';
+------------------+-------+
| Variable_name | Value |
+------------------+-------+
| innodb_read_only | OFF |
| read_only | OFF |
| tx_read_only | OFF |
+------------------+-------+ [mysql@mysqlhq ~]$ mysql -h 192.168.19.145 -u system -p*** -P 7001 -e "select @@hostname;"
Warning: Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqlhq |
+------------+ [root@mysqlhq mysqlrouter]# netstat -lnt|grep 7002 #7002端口没有启动起来,log中没有报错信息
检查配置文件,发现ip写错了
[routing:read_only]
bind_address = 192.168.20.118 #此处修改为192.168.19.145
重新启动mysqlrouter
[root@mysqlhq mysqlrouter]# /usr/bin/mysqlrouter --help
[root@mysqlhq mysqlrouter]# ps -ef|grep mysqlrouter
root 3577 831 0 16:57 pts/0 00:00:00 /usr/bin/mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf
root 4266 4138 0 17:04 pts/2 00:00:00 tail -f mysqlrouter.log
root 5544 831 0 17:18 pts/0 00:00:00 grep --color=auto mysqlrouter
[root@mysqlhq mysqlrouter]# kill 3577
[root@mysqlhq mysqlrouter]# /usr/bin/mysqlrouter -c /etc/mysqlrouter/mysqlrouter.conf &
[root@mysqlhq mysqlrouter]# netstat -lnt|grep 7001
tcp 0 0 192.168.19.145:7001 0.0.0.0:* LISTEN
[root@mysqlhq mysqlrouter]# netstat -lnt|grep 7002
tcp 0 0 192.168.19.145:7002 0.0.0.0:* LISTEN
日志信息
2019-01-14 17:18:13 INFO [7faef06c7700] keepalive started with interval 60
2019-01-14 17:18:13 INFO [7faef06c7700] keepalive
2019-01-14 17:18:13 INFO [7faeefec6700] [routing:read_only] started: listening on 192.168.19.145:7002; read-only
2019-01-14 17:18:13 INFO [7faeef6c5700] [routing:read_write] started: listening on 192.168.19.145:7001; read-write
在2个port上进行查询
[mysql@mysqlhq scripts]$ mysql -h 192.168.19.145 -u system -p*** -P 7001 -e "select @@hostname;"
Warning: Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqlhq |
+------------+
[mysql@mysqlhq scripts]$ mysql -h 192.168.19.145 -u system -p*** -P 7002 -e "select @@hostname;"
Warning: Using a password on the command line interface can be insecure.
+------------+
| @@hostname |
+------------+
| mysqlhq |
+------------+

(system@192.168.19.145:7001) [(none)]> select @@port;
+--------+
| @@port |
+--------+
| 3306 |
+--------+

 

3 性能--

Deploying MySQL Router
Performance Recommendations
For best performance, MySQL Router is typically installed on the same host as the application that uses it. Possible reasons include:
为了获得更好的性能,建议把mysql router安装在application的主机上
  To allow local UNIX domain socket connections to the application, instead of TCP/IP. 允许本地UNIX域套接字连接到应用程序,替代TCP/IP
  To decrease network latency. 减少网络的潜在因素
  To allow MySQL Router to connect to MySQL without requiring extra accounts for the Router's host, for MySQL accounts that are created specifically
  for application hosts, such as myapp@198.51.100.45 instead of a value like myapp@%. 账号安全
  Typically application servers are easiest to scale. 通常,应用服务器是最容易伸缩的
  You can run several instances of MySQL Router on your network, and do not need to isolate the router to a single machine or even a single
  Router instance. This is because MySQL Router has no affinity for any particular server or host.

https://dev.mysql.com/doc/mysql-router/2.1/en/mysql-router-preface.html

MySQL router的更多相关文章

  1. MYSQL router 自动均衡负载

    配制文件: /etc/mysqlrouter/mysqlrouter.ini [DEFAULT] logging_folder = /var/log/mysql-router plugin_folde ...

  2. mysql router 自动failover测试

    mysql router 启动服务文件内容: [root@monitor mysqlrouter]# cat /etc/init.d/mysqlrouter#! /bin/bash## mysqlro ...

  3. MySQL Router 测试使用 转

    MySQL Router 测试使用 . 特性 MySQL Router 并没有包括一些特别新的特性, 总体上看中规中矩, 不过 first-available 和插件两个特性挺有意思, 后续会进行讲解 ...

  4. MySQL Router实现MySQL的读写分离

    1.简介 MySQL Router是MySQL官方提供的一个轻量级MySQL中间件,用于取代以前老版本的SQL proxy. 既然MySQL Router是一个数据库的中间件,那么MySQL Rout ...

  5. mysql router使用配置

    mysql router使用配置 参考资料: https://www.jianshu.com/p/7fc8d77bea59 一.架构图 介绍: MySQL Router是处于应用client和dbse ...

  6. MySQL Router单点隐患通过Keepalived实现

    目录 一.介绍 二.环境准备 三.安装步骤 3.1下载软件包,解压 3.2源码安装 3.3配置keepalived 3.4修改keepalived配置文件 3.5启动keepalived 3.6查看V ...

  7. MySQL Router重装后重新连接集群进行引导出现的——此主机中之前已配置过的问题

    问题出现的前因: 因为重新安装了MySQL Router,然后打算重新连接上目标集群进行MySQL Router的初始化引导,结果报错了! [root@linux666 system]# mysqlr ...

  8. 利用MySQL Router构建读写分离MGR集群

    GreatSQL社区原创内容未经授权不得随意使用,转载请联系小编并注明来源. 目录 1. 部署MySQL Router 2. 启动mysqlrouter服务 3. 确认读写分离效果 4. 确认只读负载 ...

  9. Mysql Router 的集群

    1. c:\mysql-router, c:\mysql-5.7.23, 这两个目录的bin都要加入path 2. c:\mysql-shell,在bin下,有一个 mysqlsh.exe, 双击,打 ...

随机推荐

  1. django Models 常用的字段和参数

    1.字段 CharField IntegerField floatField DateTimeField DateField DecimalField 2.参数 null default choice ...

  2. GO学习笔记:struct类型

    Go语言中,也和C或者其他语言一样,我们可以声明新的类型,作为其它类型的属性或字段的容器.例如,我们可以创建一个自定义类型person代表一个人的实体.这个实体拥有属性:姓名和年龄.这样的类型我们称之 ...

  3. web项目在iis配置好后不能正确访问问题集锦,以及IIS常规设置

    6.IIS配置好,项目无法访问,注意项目对应的应用程序池的net版本是否正确,是否集成(一般都是集成,很少是经典) 本项目用的4.0,可IIS默认程序池为2.0,将2.0改为4.0就行.   7.HT ...

  4. 下载并安装Prism5.0库(纯汉语版)

    Prism5.0中包含了文档,WPF代码示例,程序集.本篇告诉你从哪里获取程序集和代码示例,还有NuGet包的内容. 对于新功能,资产,和API的更改信息,请看Prism5.0新内容. 文档 Pris ...

  5. Spring 自动装配;方法注入

    通过配置defalut—autowire属性,Spring IOC容器可以自动为程序注入Bean:默认是no(不启用自动装配). default—autowire的类型有: byName:通过名称自动 ...

  6. Android性能优化系列总篇

    目前性能优化专题已完成以下部分: 性能优化总纲——性能问题及性能调优方式 性能优化第四篇——移动网络优化 性能优化第三篇——Java(Android)代码优化 性能优化第二篇——布局优化 性能优化第一 ...

  7. [JS学习笔记]浅谈Javascript事件模型

    DOM0级事件模型 element.on[type] = function(){} 兼容性:全部支持   lay1 lay2 lay3 e.target:直接触发事件的元素[IE8及以下不支持tage ...

  8. Centos6.4_X64编译安装php-5.4.17、nginx-1.4.2、mysql-5.6.13

    安装参考: CentOS 6.3编译安装Nginx1.2.2+MySQL5.5.25a+PHP5.4.5 http://www.dedecms.com/knowledge/servers/linux- ...

  9. Python之namedtuple源码分析

    namedtuple()函数根据提供的参数创建一个新类,这个类会有一个类名,一些字段名和一个可选的用于定义类行为的关键字,具体实现如下 namedtuple函数源码 from keyword impo ...

  10. initWithImage和imageWithContentsOfFile的区别

    UIImageView *imageView = [[UIImageView alloc] initWithImage:         [UIImage imageNamed:@"icon ...