使用mysql-proxy代理mysql集群

本文系统环境为:CentOS Linux release 7.9.2009 (Core)

安装

mysql-proxy下载地址:dev.mysql.com/downloads/m…

 

服务信息

 
markdown
复制代码
mysql-proxy:
    192.168.1.113:4040  //目标配置信息

已搭建mysql数据库(双主):
    192.168.1.113:3306
    192.168.1.113:3307

步骤如下:

1、下载

 
bash
复制代码
wget https://cdn.mysql.com/archives/mysql-proxy/mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz

2、解压下载好的mysql-proxy的包

 
bash
复制代码
tar -xzvf mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz

3、复制已经解压好的mysql-proxy的文件夹到/usr/loca/文件夹下

 
bash
复制代码
cp -p mysql-proxy-0.8.5-linux-el6-x86-64bit mysql-proxy

4、在/etc文件夹下创建msql-proxy的配置文件:mysql-proxy.cnf

 
bash
复制代码
cd /etc/
vi mysql-proxy.cnf

配置文件

mysql-proxy.cnf

 
conf
复制代码
[mysql-proxy]
user=mysql-proxy
daemon=true
keepalive=true
plugins=proxy,admin
log-level=debug
pid-file=/var/run/mysql-proxy.pid
log-file=/usr/local/mysql-proxy/logs/mysql-proxy.log
proxy-address=0.0.0.0:4040
proxy-backend-addresses=192.168.1.113:3306
# proxy-backend-addresses=192.168.1.113:3307  # 测试暂时屏蔽
admin-address=192.168.1.113:4041
admin-username=cx
admin-password=cx123456
admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua

启动

 
bash
复制代码
 mysql-proxy --defaults-file=/etc/mysql-proxy.cnf

测试

连接mysql-proxy

 
bash
复制代码
mysql -ucx -pcx123456 -h192.168.1.113 -P4041
SELECT * FROM backends;

 

实例配置:

 

[root@test-master03 ~]# cat /etc/mysql-proxy.cnf 
[mysql-proxy]
user=root
daemon=true
keepalive=true
plugins=proxy,admin
log-level=debug
pid-file=/var/run/mysql-proxy.pid
log-file=/usr/local/mysql-proxy/logs/mysql-proxy.log
proxy-address=172.20.10.10:4040
proxy-backend-addresses=172.20.10.8:3306
admin-address=172.20.10.10:4041
admin-username=root
admin-password=Password123%
admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua

  

[root@test-master03 bin]# ./mysql-proxy --defaults-file=/etc/mysql-proxy.cnf
[root@test-master03 bin]# 
[root@test-master03 bin]# ps aux|grep mysql
root       5624  0.0  0.0  39976   712 ?        S    02:54   0:00 /usr/local/mysql-proxy/libexec/mysql-proxy --defaults-file=/etc/mysql-proxy.cnf
root       5625  0.0  0.0  42100  1488 ?        S    02:54   0:00 /usr/local/mysql-proxy/libexec/mysql-proxy --defaults-file=/etc/mysql-proxy.cnf
root       5658  0.0  0.0 112808   968 pts/1    R+   02:54   0:00 grep --color=auto mysql
[root@test-master03 bin]# 
[root@test-master03 bin]# mysql -uroot -pPassword123% -h172.20.10.10  -P4040
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 5.6.51 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MySQL [(none)]> show databases;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
3 rows in set (0.01 sec)

MySQL [(none)]> Bye

  

posted @ 2023-09-12 10:27  Oops!#  阅读(115)  评论(0编辑  收藏  举报