MYSQL-PROXY(美团)部署实录

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了MYSQL-PROXY(美团)部署实录相关的知识,希望对你有一定的参考价值。

[[email protected] ~]# rpm -ivh epel-release-6-8.noarch.rpm

[[email protected] ~]# rpm -ivh percona-release-0.1-4.noarch.rpm

[[email protected] ~]# rpm -e mysql-devel mysql


[[email protected] ~]# 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


[[email protected] ~]# yum install zlib-devel zlib libffi libffi-devel gettext automake libtool autoconf


[[email protected] ~]# tar xvf glib-2.42.0.tar

[[email protected] ~]# cd glib-2.42.0

[[email protected] glib-2.42.0]# autoreconf -ivf

[[email protected] glib-2.42.0]# ./configure --prefix=/usr --libdir=/usr/lib64

[[email protected] glib-2.42.0]# make

[[email protected] glib-2.42.0]# make install


[[email protected] ~]# vi /etc/ld.so.conf

/usr/lib64

[[email protected] ~]# ldconfig


[[email protected] ~]# 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.


[[email protected] ~]# cd DBProxy

[[email protected] DBProxy]# sh autogen.sh

[[email protected] DBProxy]# sh bootstrap.sh

[[email protected] DBProxy]# make

[[email protected] DBProxy]# make install

[[email protected] DBProxy]# mkdir /usr/local/mysql-proxy/conf

[[email protected] DBProxy]# cp script/source.cnf.samples /usr/local/mysql-proxy/conf/source.cnf 


[[email protected] ~]# cd /usr/local/mysql-proxy/bin

[[email protected] bin]# ./encrypt tpcc

qayIcw==


[[email protected] 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


[[email protected] ~]# cd /usr/local/mysql-proxy/bin


[[email protected] bin]# ./mysql-proxyd source start

OK: MySQL-Proxy of source is started


[[email protected] bin]# ./mysql-proxyd source status

MySQL-Proxy of source is running (2389)

MySQL-Proxy of source is running (2390)


[[email protected] 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(美团)部署实录的主要内容,如果未能解决你的问题,请参考以下文章

MySQL-proxy 读写分离

MYSQL GALERA部署实录

干货Mysql的"事件探查器"-之Mysql-Proxy代理实战一(安装部署与实战sql拦截与性能监控)

MYSQL读写分离解决方案:MYCAT部署实录

MYSQL MMM部署实录

MYSQL MHA部署实录