創(chuàng)新互聯(lián)建站自2013年起,先為繁峙等服務(wù)建站,繁峙等地企業(yè),進(jìn)行企業(yè)商務(wù)咨詢服務(wù)。為繁峙企業(yè)網(wǎng)站制作PC+手機(jī)+微官網(wǎng)三網(wǎng)同步一站式服務(wù)解決您的所有建站問(wèn)題。
本文主要給大家介紹MySQL-proxy代理機(jī)器講析,希望可以給大家補(bǔ)充和更新些知識(shí),如有其它問(wèn)題需要了解的可以持續(xù)在創(chuàng)新互聯(lián)行業(yè)資訊里面關(guān)注我的更新文章的。
一、使用場(chǎng)景介紹
mysql-proxy的機(jī)器屬于代理機(jī)器也就是相當(dāng)于白名單的審核機(jī)器,通過(guò)防火墻規(guī)則,限制允許那些IP訪問(wèn)本機(jī)的代理內(nèi)網(wǎng)數(shù)據(jù)庫(kù)的端口,
有點(diǎn):保證內(nèi)網(wǎng)的數(shù)據(jù)庫(kù)不暴露在公網(wǎng)上,保證了數(shù)據(jù)庫(kù)的安全。
缺點(diǎn):一旦mysql-proxy代理云服務(wù)器掛掉了,就相當(dāng)于應(yīng)用都鏈接不上了數(shù)據(jù)庫(kù)。同時(shí)如果太多的應(yīng)用程序通過(guò)mysql-proxy鏈接內(nèi)網(wǎng)數(shù)據(jù)庫(kù)的話,mysql-proxy代理服務(wù)器必須也得保證足夠的帶寬,負(fù)責(zé)導(dǎo)致鏈接數(shù)據(jù)庫(kù)特別的慢,或者鏈接不上數(shù)據(jù)庫(kù)。
二、演示環(huán)境:
2臺(tái)物理機(jī)器,系統(tǒng)都是CentOS release 6.8 (Final)
一臺(tái)機(jī)器配置內(nèi)外網(wǎng)卡:104.137.27.4 192.168.1.100 部署mysql-proxy 服務(wù)
一臺(tái)機(jī)器配置外網(wǎng)卡:104.137.27.3 部署mysql服務(wù),并登陸此機(jī)器數(shù)據(jù)庫(kù),授權(quán)一個(gè)賬戶允許104.137.27.4機(jī)器來(lái)鏈接此數(shù)據(jù)庫(kù)
grant all on mtoyydb.* to zytestuser01@'104.137.27.4' identified by 'dr3dfKj=DHee';
mysql> flush privileges
三、二進(jìn)制安裝mysql-proxy:
下載安裝包:
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 -C /usr/local/
cd /usr/local/
mv mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit mysql-proxy
mkdir /usr/local/mysql-proxy/{conf,log} -p
定義下環(huán)境變量:
[root@book sysconfig]# tail -3 /etc/profile
LUA_PATH="/usr/local/mysql-proxy/share/doc/mysql-proxy/?.lua"
export LUA_PATH
export PATH=$PATH:/usr/local/mysql-proxy/bin
四、mysql-proxy 參數(shù)介紹:
Application Options:
4.1應(yīng)用參數(shù)介紹:
mysql-proxy --help-all
4.2mysql-proxy代理模塊參數(shù)介紹
4.3線上配置文件介紹:
[root@book mysql-proxy]# cat /usr/local/mysql-proxy/conf/mysql-proxy.conf
[mysql-proxy]
user=www
daemon=true
keepalive=true
plugins=proxy,admin
###日志級(jí)別
log-level=info
log-file=/usr/local/mysql-proxy/log/mysql-proxy.log
###本機(jī)ip地址
proxy-address=104.137.27.4:9196
##backend主 注意addresses
proxy-backend-addresses=104.137.27.3:3306
##proxy的管理用戶admin的IP和端口
admin-address=104.137.27.4:9197
###下面的三個(gè)參數(shù)必須設(shè)定,否則mysql-proxy服務(wù)啟動(dòng)不了的
admin-username=zykjadmin
admin-password=Zyjkwestos
###admin的lua腳本地址;
admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua
五、啟動(dòng)mysql-proxy
/usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf
登陸mysql-proxy管理賬戶,查看反向代理管理列表
[root@book ~]# mysql -uzykjadmin -pZyjkwestos -h204.137.27.4 --port=9197
Warning: 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 1
Server version: 5.0.99-agent-admin
Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MySQL [(none)]> SELECT * FROM backends;
+-------------+------------------+-------+------+------+-------------------+
| backend_ndx | address | state | type | uuid | connected_clients |
+-------------+------------------+-------+------+------+-------------------+
| 1 | 104.137.27.3:3306 | up | rw | NULL | 2 |
+-------------+------------------+-------+------+------+-------------------+
1 row in set (0.00 sec)
MySQL [(none)]> 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 [(none)]>
六、通過(guò)sqlyog來(lái)登陸反向代理數(shù)據(jù)庫(kù)
登陸成功:
七、MySQL-porxy代理服務(wù)器防火墻的配置策略:
[root@book sysconfig]# cat /etc/sysconfig/iptables
#Generated by iptables-save v1.4.7 on Thu Mar 2 14:32:03 2017
*filter
:INPUT ACCEPT [358:20023]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [2491:287941]
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT
-A INPUT -p tcp -m tcp --dport 4567 -j ACCEPT
-A INPUT -p tcp -m multiport --dports 80,81,443 -m state --state NEW -j ACCEPT
-A INPUT -s 104.137.27.6/32 -p tcp -m tcp --dport 873 -m state --state NEW -j ACCEPT
-A INPUT -s 304.37.57.45/32 -p tcp -m multiport --dports 9196 -j ACCEPT
-A INPUT -s 204.17.47.245/32 -p tcp -m multiport --dports 21,10050,3306 -j ACCEPT
#-A INPUT -p tcp -m tcp --dport 9196 -j DROP
##-A INPUT -p icmp -m icmp --icmp-type 8 -j ACCEPT
-A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 5/sec --limit-burst 10 -j ACCEPT
-A INPUT -j DROP
COMMIT
#Completed on Thu Mar 2 14:32:03 2017
7.1配置策略解釋:
-```
A INPUT -p tcp -m tcp --dport 4567 -j ACCEPT
此處6029相當(dāng)于sshd的登陸端口號(hào)
-A INPUT -p tcp -m multiport --dports 80,81,443 -m state --state NEW -j ACCEPT
放行80,81和443業(yè)務(wù)端口
-A INPUT -s 104.137.27.6/32 -p tcp -m tcp --dport 873 -m state --state NEW -j ACCEPT
允許特定的IP104.137.27.6到本地服務(wù)器上通過(guò)rsync拉取數(shù)據(jù)
-A INPUT -s 304.37.57.45/32 -p tcp -m multiport --dports 9196 -j ACCEPT
允許指定的IP304.37.57.45 來(lái)鏈接MySQL-proxy服務(wù)的9196端口,從而鏈接到內(nèi)網(wǎng)的數(shù)據(jù)庫(kù)
-A INPUT -s 204.17.47.245/32 -p tcp -m multiport --dports 21,10050,3306 -j ACCEPT
解釋:204.17.47.245 機(jī)器上部署-server,通過(guò)撥號(hào)登陸-server,然后在可以登陸ftp,登陸3306數(shù)據(jù)庫(kù)服務(wù)
-A INPUT -p icmp -m icmp --icmp-type 8 -m limit --limit 5/sec --limit-burst 10 -j ACCEPT
解釋:對(duì)ping做限制策略
-A INPUT -j DROP
解釋:其他的客戶端IP地址一律禁止訪問(wèn)本服務(wù)器上的服務(wù)的端口
到此處介紹完畢,據(jù)說(shuō)ucloud的Udb就是采用這樣的數(shù)據(jù)庫(kù)的架構(gòu)模式
看了以上關(guān)于mysql-proxy代理機(jī)器講析,希望能給大家在實(shí)際運(yùn)用中帶來(lái)一定的幫助。本文由于篇幅有限,難免會(huì)有不足和需要補(bǔ)充的地方,如有需要更加專業(yè)的解答,可在官網(wǎng)聯(lián)系我們的24小時(shí)售前售后,隨時(shí)幫您解答問(wèn)題的。