千家信息网

MySQL Router介绍

发表于:2025-02-01 作者:千家信息网编辑
千家信息网最后更新 2025年02月01日,MySQL Router介绍MySQL Router是一个轻量级的中间件,提供了应用程序与后端数据库的透明路由,是mysql用来实现负载均衡和高可用功能。同时router也提供了使用fabric 高可
千家信息网最后更新 2025年02月01日MySQL Router介绍

MySQL Router介绍

MySQL Router是一个轻量级的中间件,提供了应用程序与后端数据库的透明路由,是mysql用来实现负载均衡和高可用功能。同时router也提供了使用fabric 高可用的方式。

安装配置 MySQL Router

shell> tar zxvf mysql-router-2.0.2-linux-glibc2.17-x86-64bit.tar.gzshell> mv mysql-router-2.0.2-linux-glibc2.17-x86-64bit /opt/mysqlroutershell> cd /opt/mysqlroutershell> mkdir config log创建Router配置文件shell> more conf/router.cnf[DEFAULT]logging_folder = /opt/mysqlrouter/log/[logger]level = INFO[routing:read_only]bind_address = 10.106.58.174bind_port = 7001connect_timeout = 3max_connections = 1024destinations = 10.106.58.176:3307,10.106.58.177:3307mode = read-only[routing:read_write]bind_address = 10.106.58.174bind_port = 7002connect_timeout = 3max_connections = 1024destinations = 10.106.58.175:3307,10.106.58.176:3307mode = read-write

升级gcc、glibc

升级gcc为4.8版本,升级glibc为2.14以上版本

查看系统GLIBCXX版本shell> strings /usr/lib64/libstdc++.so.6 | grep GLIBCXX升级gcc,查看gcc4.8.5中GLIBCXX版本shell> strings /usr/local/lib64/libstdc++.so.6.0.19 | grep GLIBCXX升级支持GLIBCXX_3.4.15shell> cp /usr/local/lib64/libstdc++.so.6.0.19 /usr/lib64/shell> cd /usr/lib64/shell> rm -f libstdc++.so.6shell> ln -s libstdc++.so.6.0.19 libstdc++.so.6查看系统glibc支持的版本:shell> strings /lib64/libc.so.6  |grep GLIBC_升级glibc支持2.14以上版本

运行mode介绍

mode = read-only时,客户端请求将被循环分发给配置列表,当配置列表中服务器不可用,将会跳过该服务器,列表中下一个可用机器将处理请求,如列表没有可用服务器,路由将失败。

mode = read-write时,所有客户端请求都会被列表中第一个可用服务器处理,当此服务器宕机时,列表中下一个可用机器才会处理客户端请求,如列表没有可用服务器,路由将失败。第一个被成功连接的服务器信息将被保存在内存中,重启router后失效。

启动router

1、启动router前,需要确保配置文件中转发的server可用。
2、运行router

shell> /opt/mysqlrouter/bin/mysqlrouter --config=/opt/mysqlrouter/config/router.cnf &2016-02-24 06:10:35 INFO    [7f898af9e700] routing:read_write started: listening on 10.106.58.174:7002; read-write2016-02-24 06:10:35 INFO    [7f898b99f700] routing:read_only started: listening on 10.106.58.174:7001; read-onlyshell> netstat -an | grep 700tcp        0      0 10.106.58.174:7001          0.0.0.0:*                   LISTENtcp        0      0 10.106.58.174:7002          0.0.0.0:*                   LISTEN

3、测试连接

shell> mysql -h 10.106.58.174 -P 7001 -u test -p -e "select @@hostname;"shell> mysql -h 10.106.58.174 -P 7002 -u test -p -e "select @@hostname;"
参考:
http://mysqlhighavailability.com/setting-up-mysql-router/
0