MYSQL-PROXY(美團)部署實錄
[root@king04 ~]# rpm -ivh percona-release-0.1-4.noarch.rpm
[root@king04 ~]# rpm -e mysql-devel mysql
[root@king04 ~]# yum install -y Percona-Server-devel-55.x86_64 Percona-Server-client-55.x86_64 Percona-Server-shared-55 jemalloc jemalloc-devel libevent \
libevent-devel openssl openssl-devel lua lua-devel bison flex libtool.x86_64
[root@king04 ~]# yum install zlib-devel zlib libffi libffi-devel gettext automake libtool autoconf
[root@king04 ~]# tar xvf glib-2.42.0.tar
[root@king04 ~]# cd glib-2.42.0
[root@king04 glib-2.42.0]# autoreconf -ivf
[root@king04 glib-2.42.0]# ./configure --prefix=/usr --libdir=/usr/lib64
[root@king04 glib-2.42.0]# make
[root@king04 glib-2.42.0]# make install
[root@king04 ~]# vi /etc/ld.so.conf
/usr/lib64
[root@king04 ~]# ldconfig
[root@king04 ~]# git clone https://github.com/Meituan-Dianping/DBProxy.git
Initialized empty Git repository in /root/DBProxy/.git/
remote: Counting objects: 2204, done.
remote: Total 2204 (delta 0), reused 0 (delta 0), pack-reused 2204
Receiving objects: 100% (2204/2204), 15.71 MiB | 349 KiB/s, done.
Resolving deltas: 100% (742/742), done.
[root@king04 ~]# cd DBProxy
[root@king04 DBProxy]# sh autogen.sh
[root@king04 DBProxy]# sh bootstrap.sh
[root@king04 DBProxy]# make
[root@king04 DBProxy]# make install
[root@king04 DBProxy]# mkdir /usr/local/mysql-proxy/conf
[root@king04 DBProxy]# cp script/source.cnf.samples /usr/local/mysql-proxy/conf/source.cnf
[root@king04 ~]# cd /usr/local/mysql-proxy/bin
[root@king04 bin]# ./encrypt tpcc
qayIcw==
[root@test04 bin]# cat /usr/local/mysql-proxy/conf/source.cnf
[mysql-proxy]
#帶#號的為非必需的配置項目
#管理接口的用戶名
admin-username=guest
#管理接口的密碼
admin-password=guest
#dbproxy後端連接的MySQL主庫的IP和端口,可設置多項,用逗號分隔
proxy-backend-addresses=192.168.1.201:3306
#dbproxy後端連接的MySQL從庫的IP和端口,@後面的數字代表權重,用來作負載均衡,若省略則默認為1,可設置多項,用逗號分隔
proxy-read-only-backend-addresses=190.168.1.202:3306
#用戶名與其對應的加密過的MySQL密碼,密碼使用PREFIX/bin目錄下的加密程序encrypt加密,下行的user1和user2為示例,將其替換為你的MySQL的用戶名和加密密碼!
pwds=tpcc:qayIcw==
#設置dbproxy的運行方式,設為true時為守護進程方式,設為false時為前臺方式,一般開發調試時設為false,線上運行時設為true
daemon=true
#設置dbproxy的運行方式,設為true時dbproxy會啟動兩個進程,一個為monitor,一個為worker,monitor在worker意外退出後會自動將其重啟,設為false時只有worker,沒有monitor,一般開發調試時設為false,線上運行時設為true
keepalive=true
#工作線程數,對dbproxy的性能有很大影響,可根據情況適當設置
event-threads=8
#日誌級別,分為message、warning、critical、error、debug五個級別
log-level=debug
#日誌存放的路徑
log-path=/var/log/dbproxy_log/
#SQL日誌的開關,可設置為OFF、ON、REALTIME,OFF代表不記錄SQL日誌,ON代表記錄SQL日誌,REALTIME代表記錄SQL日誌且實時寫入磁盤,默認為OFF
sql-log=ON
#SELECT無where條件的限制,分為ON,OFF
select-where-limit = OFF
#實例名稱,用於同一臺機器上多個dbproxy實例間的區分
instance=source
#dbproxy監聽的工作接口IP和端口
proxy-address=0.0.0.0:3308
#dbproxy監聽的管理接口IP和端口
admin-address=0.0.0.0:3309
#分表設置,此例中person為庫名,mt為表名,id為分表字段,3為子表數量,可設置多項,以逗號分隔,若不分表則不需要設置該項
#tables = person.mt.id.3
#默認字符集,設置該項後客戶端不再需要執行SET NAMES語句
#charset=utf8
#dbproxy前面掛接的LVS的物理網卡的IP(註意不是虛IP),若有LVS且設置了client-ips則此項必須設置,否則可以不設置
#lvs-ips = 192.168.1.1
max-connections=1000
#長時等待閾值,同步等待時間超過該閾值則認為是長時等待
long-wait-time=500
#慢查詢閾值,查詢執行時間超過該閾值則認為是慢查詢
long-query-time=500
#0:不統計,1:僅統計總體的響應時間,其中包括慢查詢,2:進行直方圖統計;默認為1。
query-response-time-stats=2
#SQL日誌文件最大大小,單位為字節,默認為1G
sql-log-file-size=1073741824
#保留的最大SQL日誌文件個數,默認為0,不保留歷史文件,僅保留當前文件
sql-log-file-num=500
#後臺MySQL版本號,默認為5.5
mysql-version=5.6
#後臺MySQL最大連接數,默認為0,表示不限制
backend-max-thread-running=64
#後臺MySQL連接超過backend-max-thread-running後,每次sleep的時間,單位為ms
thread-running-sleep-delay=10
#SQL過濾統計緩存的SQL模板數,默認為0
lastest-query-num=100000
#SQL過濾的時間閾值
query-filter-time-threshold=500
#SQL過濾的頻率閾值
query-filter-frequent-threshold=10
#SQL過濾頻率統計時間窗口內的最小執行次數,根據頻率和該參數計算時間窗口
access-num-per-time-window = 5
#手動過濾SQL是否生效,默認為OFF
manual-filter-flag=OFF
#自動過濾SQL是否生效,默認為OFF
auto-filter-flag=OFF
[root@king04 ~]# cd /usr/local/mysql-proxy/bin
[root@king04 bin]# ./mysql-proxyd source start
OK: MySQL-Proxy of source is started
[root@king04 bin]# ./mysql-proxyd source status
MySQL-Proxy of source is running (2389)
MySQL-Proxy of source is running (2390)
[root@test04 bin]# mysql -utpcc -ptpcc -P3308 -h127.0.0.1
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.6.22-71.0-log Source distribution
Copyright (c) 2009-2018 Percona LLC and/or its affiliates
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> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| tpcc1000 |
+--------------------+
2 rows in set (0.08 sec)
MYSQL-PROXY(美團)部署實錄