CentOS7.x下安装并配置mysqlrouter

1.下载

[root@centos7 ~]# wget https://downloads.mysql.com/archives/get/file/mysql-router-2.1.6-linux-glibc2.12-x86-64bit.tar.gz

2.安装

[root@centos7 ~]# tar -xzvf mysql-router-2.1.6-linux-glibc2.12-x86-64bit.tar.gz -C /usr/local/
[root@centos7 ~]# ln -s /usr/local/mysql-router-2.1.6-linux-glibc2.12-x86-64bit.tar.gz /usr/local/mysql-router

配置环境变量:
[root@centos7 ~]# vim /etc/profile.d/mysqlrouter.sh

    添加如下内容:
    export MYSQLROUTER_HOME=/usr/local/mysql-router
    export PATH=$MYSQLROUTER_HOME/bin/:$PATH

3、测试安装是否成功

[root@centos7 ~]# mysqlrouter --help

4、配置mysql-router(这里为了搭建方便使用多实例方式)

[root@centos7 ~]# mkdir /usr/local/mysql-router/etc -pv

[root@centos7 ~]# vim /usr/local/mysql-router/etc/mysqlrouter.cnf

添加如下配置内容:
[DEFAULT]
# 定义日志目录
logging_folder = /var/log/mysqlrouter 
[logger]
# 定义日志等级
level = INFO
# 一个高可用的标签
[routing:failover]
bind_address = 0.0.0.0
bind_port = 7001
max_connections = 1024
# 目前就支持两种 : read-write 和 read-only
# read-write:用于高可用,用于可读可写
# read-only:用于负载均衡,只读
mode = read-write
# 实际转发的地址
# 第一个socket如果可用,就一直会使用第一个
# 如果第一个socket无法连接了,才会连接到第二个socket
destinations = 192.168.56.142:3308, 192.168.56.142:3311
# 一个用于复杂均衡的标签
[routing:balancing]
bind_address = 0.0.0.0
bind_port = 7002
max_connections = 1024
# 用于负载均衡的只读模式
mode = read-only
# 这里的两个socket是轮询用的

destinations = 192.168.56.142:3309, 192.168.56.142:3310

5.创建相关目录

[root@centos7 ~]# mkdir -pv /var/log/mysqlrouter

6.启动

[root@centos7 ~]# mysqlrouter --config /usr/local/mysqlrouter/etc/mysqlrouter.cnf &

[root@centos7 mysql-router]# netstat -tnlp | grep 700*
tcp        0      0 0.0.0.0:7001            0.0.0.0:*               LISTEN      18693/mysqlrouter   
tcp        0      0 0.0.0.0:7002            0.0.0.0:*               LISTEN      18693/mysqlrouter   

7.测试

[root@centos7 ~]# mysql -u root -h 192.168.56.142 -p -P 7001
Enter password: 

mysql> select @@port;
+--------+
| @@port |
+--------+
|   3308 |
+--------+
1 row in set (0.00 sec)

##从机有负载均衡的效果
[root@centos7 ~]# mysql -h 192.168.56.142 -u root -pxsy123 -e "select @@port" -P 7002
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|   3309 |
+--------+
[root@centos7 ~]# mysql -h 192.168.56.142 -u root -pxsy123 -e "select @@port" -P 7002
mysql: [Warning] Using a password on the command line interface can be insecure.
+--------+
| @@port |
+--------+
|   3310 |
+--------+

8.备注

按照配置,读写操作在master,读操作轮询到slave1和slave2
如果master宕机,master则不能写入,master服务重启后,需要也重启下MySQLrouter

 

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值