mysql代理服务器_mysql-proxy代理同一内网的数据库

浅析:

a7566f8dc81528f84181dbd318927815.png

具体部署:mysql服务器:

#授权远程登录账户

[root@localhost ~]# mysql -uroot  -pmysql> GRANT ALL ON *.* to 'test'@'192.168.0.1' IDENTIFIED BY 'lmdb(A7105#B9606@com!';mysql> flush privileges;mysql> select user,host from mysql.user;+---------------+----------------+| user          | host           |+---------------+----------------+| root          | 127.0.0.1      || zabbix        | 127.0.0.1      || test          | 192.168.0.1    || root          | localhost      |+---------------+----------------+11 rows in set (0.00 sec)mysql> quit

#防火墙开放数据库的端口,或者关闭防火墙

a。关闭防火墙

[root@localhost ~]# systemctl status iptables#    systemctl stop iptables● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)Active: inactive (dead) since Tue 2019-08-13 15:43:07 CST; 1 weeks 1 days agoMain PID: 1969 (code=exited, status=0/SUCCESS)

b。防火墙规则

[root@localhost ~]# vim /etc/sysconfig/iptables-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT[root@localhost ~]#  ystemctl restart iptablesmysql-proxy服务器

#下载mysql-proxy包

wget https://downloads.mysql.com/archives/get/file/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz

#安装

[root@e test]# tar zxf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz -C /usr/local/cd /usr/local/[root@e local]# lsmysql-proxy-0.8.5-linux-glibc2.3-x86-64bit[root@e local]# mv mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/   mysql-proxy[root@e local]# lsmysql-proxy[root@e local]# mkdir /usr/local/mysql-proxy/{conf,log} -p[root@e mysql-proxy]# tail -3 /etc/profile#(添加下面三行内容)LUA_PATH="/usr/local/mysql-proxy/share/doc/mysql-proxy/?.lua"export LUA_PATHexport PATH=$PATH:/usr/local/mysql-proxy/bin[root@e mysql-proxy]# source /etc/profile

[root@e conf]# vi mysql-proxy.conf[mysql-proxy]user=wwwdaemon=truekeepalive=trueplugins=proxy,admin###日志级别log-level=infolog-file=/usr/local/mysql-proxy/log/mysql-proxy.log###本机ip地址proxy-address=14.152.90.6:9196         #本地的ip和代理端口,后期navicat连接使用的地址##backend主   注意addressesproxy-backend-addresses=192.168.0.2:3306      #mysql的内网ip地址##proxy的管理用户admin的IP和端口admin-address=192.168.0.1:9197               #mysql-proxy的内网###下面的三个参数必须设定,否则mysql-proxy服务启动不了的admin-username=test1admin-password=test1###admin的lua脚本地址;admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua

#启动

[root@e conf]# chmod 660 mysql-proxy.conf[root@e conf]# /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf[root@e conf]# netstat -luntpActive Internet connections (only servers)Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program nametcp        0      0 14.152.90.6:9196        0.0.0.0:*               LISTEN      11502/mysql-proxytcp        0      0 192.168.0.1:9197        0.0.0.0:*               LISTEN      11502/mysql-proxy

#登陆mysql-proxy管理账户,查看代理管理列表

[root@e bin]# mysql -utest1  -ptest1  -h192.168.0.1  --port=9197Warning: 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 1Server version: 5.0.99-agent-adminCopyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> SELECT * FROM backends;+-------------+------------------+---------+------+------+-------------------+| backend_ndx | address          | state   | type | uuid | connected_clients |+-------------+------------------+---------+------+------+-------------------+|           1 | 192.168.0.2:3306 | unknown | rw   | NULL |                 0 |+-------------+------------------+---------+------+------+-------------------+1 row in set (0.00 sec)mysql> SELECT * FROM help;+------------------------+------------------------------------+| command                | description                        |+------------------------+------------------------------------+| SELECT * FROM help     | shows this help                    || SELECT * FROM backends | lists the backends and their state |+------------------------+------------------------------------+2 rows in set (0.00 sec)mysql> quit

#远程连接mysql

[root@e bin]# mysql -utest -p'lmdb(A7105#B9606@com!'  -h 192.168.0.2Warning: 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 223226Server version: 5.7.27-log MySQL Community Server (GPL)Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.Oracle is a registered trademark of Oracle Corporation and/or itsaffiliates. Other names may be trademarks of their respectiveowners.Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.mysql> show databases;+--------------------+| Database           |+--------------------+| information_schema || CodeDB             || mysql              || mysqldata          || performance_schema || sys                |+--------------------+6 rows in set (0.00 sec)mysql> quit######################成功######################

#防火墙规则(通过navicat,sqlyog等工具连接数据库的时候,当然需要开放本地的代理端口)

a。关闭防火墙

[root@localhost ~]# systemctl status iptables# systemctl stop iptables● iptables.service - IPv4 firewall with iptablesLoaded: loaded (/usr/lib/systemd/system/iptables.service; disabled; vendor preset: disabled)Active: inactive (dead) since Tue 2019-08-13 15:43:07 CST; 1 weeks 1 days agoMain PID: 1969 (code=exited, status=0/SUCCESS)

b。添加防火墙规则

[root@localhost ~]# vim /etc/sysconfig/iptables-A INPUT -p tcp -m tcp --dport 9196 -j ACCEPT[root@localhost ~]#  ystemctl restart iptables

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值