数据库:10.86.0.110:3306
代理机器:10.86.0.105(有外网IP)
wget https://downloads.mysql.com/archives/get/file/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz
tar zxf mysql-proxy-0.8.5-linux-el6-x86-64bit
mv mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit mysql-proxy
mkdir -p mysql-proxy/{conf,log}
cat conf/mysql-proxy.conf
[mysql-proxy]
user=user_00
daemon=true
keepalive=true
plugins=proxy,admin
log-level=info
log-file=/export/app/test/es/mysql-proxy/log/mysql-proxy.log
# 本机ip地址
proxy-address=10.86.0.105:13306
# backend主 注意addresses
proxy-backend-addresses=10.86.0.110:3306
# proxy的管理用户admin的IP和端口
admin-address=10.86.0.105:13307
# 下面的三个参数必须设定,否则mysql-proxy服务启动不了的
admin-username=admin
admin-password=nimda
# admin的lua脚本地址
admin-lua-script=/export/app/test/es/mysql-proxy/lib/mysql-proxy/lua/admin.lua
# 启动服务
bin/mysql-proxy --defaults-file=conf/mysql-proxy.conf
# 查看进程
ps -ef|grep proxy
root 18499 1 0 17:22 ? 00:00:00 /export/app/test/es/mysql-proxy/libexec/mysql-proxy --defaults-file=conf/mysql-proxy.conf
user_00 18500 18499 0 17:22 ? 00:00:00 /export/app/test/es/mysql-proxy/libexec/mysql-proxy --defaults-file=conf/mysql-proxy.conf
root 18516 14307 0 17:22 pts/0 00:00:00 grep --color=auto proxy
# 查看端口
netstat -ntlp|grep mysql-proxy
tcp 0 0 10.86.0.105:13306 0.0.0.0:* LISTEN 18500/mysql-proxy
tcp 0 0 10.86.0.105:13307 0.0.0.0:* LISTEN 18500/mysql-proxy
# 测试链接
mysql -uadmin -pnimda -h10.86.0.105 --port=13307
mysql> SELECT * FROM backends;
+-------------+------------------+---------+------+------+-------------------+
| backend_ndx | address | state | type | uuid | connected_clients |
+-------------+------------------+---------+------+------+-------------------+
| 1 | 10.86.0.110:3306 | unknown | rw | NULL | 0 |
+-------------+------------------+---------+------+------+-------------------+
1 row in set (0.00 sec)
mysql -uxxxx -pxxxx -h10.86.0.105 --port=13306
mysql> SELECT * FROM backends;
+-------------+------------------+-------+------+------+-------------------+
| backend_ndx | address | state | type | uuid | connected_clients |
+-------------+------------------+-------+------+------+-------------------+
| 1 | 10.86.0.110:3306 | up | rw | NULL | 1 |
+-------------+------------------+-------+------+------+-------------------+
1 row in set (0.00 sec)