博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
1.8. MySQL Proxy
阅读量:5807 次
发布时间:2019-06-18

本文共 6180 字,大约阅读时间需要 20 分钟。

1.8.1. Ubuntu

安装环境 Ubuntu 13.04

$ sudo apt-get install mysql-proxy

ENABLED改为true

$ sudo vim /etc/default/mysql-proxyENABLED="true"OPTIONS="--defaults-file=/etc/mysql/mysql-proxy.cnf"

配置 /etc/mysql/mysql-proxy.cnf

$ sudo vim /etc/mysql/mysql-proxy.cnf[mysql-proxy]daemon = trueuser = mysqlproxy-skip-profiling = truekeepalive = truemax-open-files = 2048event-threads = 50pid-file = /var/run/mysql-proxy.pidlog-file = /var/log/mysql-proxy.loglog-level = debugadmin-address=:4401admin-username=adminadmin-password=passw0rdadmin-lua-script=/usr/local/lib/mysql-proxy/lua/admin.luaproxy-address = 0.0.0.0:3307proxy-backend-addresses = 192.168.2.1:3306proxy-read-only-backend-addresses=192.168.6.2:3306, 192.168.6.1:3306proxy-lua-script=/usr/lib/mysql-proxy/lua/proxy/balance.lua

修改权限,这个步骤不能省略,否则无法启动。

$ sudo chmod 0660 /etc/mysql/mysql-proxy.cnf

启动mysql-proxy

$ sudo /etc/init.d/mysql-proxy start * Starting MySQL Proxy daemon...                    [ OK ]

测试3307端口

$ mysql -hlocalhost -P3307 -uroot -p

mysql-proxy 软件包所含文件如下:

$ dpkg -L  mysql-proxy/./etc/etc/default/etc/default/mysql-proxy/etc/init.d/etc/init.d/mysql-proxy/usr/usr/share/usr/share/mysql-proxy/usr/share/mysql-proxy/active-queries.lua/usr/share/mysql-proxy/active-transactions.lua/usr/share/mysql-proxy/admin-sql.lua/usr/share/mysql-proxy/admin.lua/usr/share/mysql-proxy/analyze-query.lua/usr/share/mysql-proxy/auditing.lua/usr/share/mysql-proxy/commit-obfuscator.lua/usr/share/mysql-proxy/histogram.lua/usr/share/mysql-proxy/load-multi.lua/usr/share/mysql-proxy/ro-balance.lua/usr/share/mysql-proxy/ro-pooling.lua/usr/share/mysql-proxy/rw-splitting.lua/usr/share/mysql-proxy/xtab.lua/usr/share/doc/usr/share/doc/mysql-proxy/usr/share/doc/mysql-proxy/README.TESTS.gz/usr/share/doc/mysql-proxy/README/usr/share/doc/mysql-proxy/copyright/usr/share/doc/mysql-proxy/changelog.Debian.gz/usr/lib/usr/lib/libmysql-chassis-glibext.so.0.0.0/usr/lib/libmysql-chassis-timing.so.0.0.0/usr/lib/libmysql-chassis.so.0.0.0/usr/lib/libmysql-proxy.so.0.0.0/usr/lib/mysql-proxy/usr/lib/mysql-proxy/lua/usr/lib/mysql-proxy/lua/proxy/usr/lib/mysql-proxy/lua/proxy/auto-config.lua/usr/lib/mysql-proxy/lua/proxy/balance.lua/usr/lib/mysql-proxy/lua/proxy/commands.lua/usr/lib/mysql-proxy/lua/proxy/parser.lua/usr/lib/mysql-proxy/lua/proxy/tokenizer.lua/usr/lib/mysql-proxy/lua/proxy/test.lua/usr/lib/mysql-proxy/lua/admin.lua/usr/lib/mysql-proxy/lua/lfs.so/usr/lib/mysql-proxy/lua/glib2.so/usr/lib/mysql-proxy/lua/chassis.so/usr/lib/mysql-proxy/lua/mysql.so/usr/lib/mysql-proxy/lua/lpeg.so/usr/lib/mysql-proxy/lua/posix.so/usr/lib/mysql-proxy/plugins/usr/lib/mysql-proxy/plugins/libadmin.so/usr/lib/mysql-proxy/plugins/libproxy.so/usr/lib/mysql-proxy/plugins/libreplicant.so/usr/lib/mysql-proxy/plugins/libdebug.so/usr/lib/pkgconfig/usr/lib/pkgconfig/mysql-proxy.pc/usr/lib/pkgconfig/mysql-chassis.pc/usr/bin/usr/bin/mysql-binlog-dump/usr/bin/mysql-myisam-dump/usr/bin/mysql-proxy/usr/include/usr/include/network-mysqld.h/usr/include/network-mysqld-lua.h/usr/include/network-mysqld-proto.h/usr/include/network-mysqld-binlog.h/usr/include/network-mysqld-packet.h/usr/include/network-mysqld-masterinfo.h/usr/include/network-conn-pool.h/usr/include/network-conn-pool-lua.h/usr/include/network-queue.h/usr/include/network-socket.h/usr/include/network-socket-lua.h/usr/include/network-address.h/usr/include/network-address-lua.h/usr/include/sys-pedantic.h/usr/include/chassis-plugin.h/usr/include/chassis-log.h/usr/include/chassis-keyfile.h/usr/include/chassis-mainloop.h/usr/include/chassis-path.h/usr/include/chassis-filemode.h/usr/include/chassis-limits.h/usr/include/chassis-event-thread.h/usr/include/chassis-gtimeval.h/usr/include/glib-ext.h/usr/include/glib-ext-ref.h/usr/include/string-len.h/usr/include/lua-load-factory.h/usr/include/lua-scope.h/usr/include/lua-env.h/usr/include/network-injection.h/usr/include/network-injection-lua.h/usr/include/chassis-shutdown-hooks.h/usr/include/chassis-exports.h/usr/include/network-exports.h/usr/include/network-backend.h/usr/include/network-backend-lua.h/usr/include/disable-dtrace.h/usr/include/lua-registry-keys.h/usr/include/chassis-stats.h/usr/include/chassis-timings.h/usr/include/chassis-frontend.h/usr/include/chassis-options.h/usr/include/chassis-win32-service.h/usr/include/chassis-unix-daemon.h/usr/include/my_rdtsc.h/usr/lib/libmysql-chassis-glibext.so.0/usr/lib/libmysql-chassis-glibext.so/usr/lib/libmysql-proxy.so/usr/lib/libmysql-chassis-timing.so.0/usr/lib/libmysql-chassis-timing.so/usr/lib/libmysql-proxy.so.0/usr/lib/libmysql-chassis.so.0/usr/lib/libmysql-chassis.so

1.8.2. CentOS

# yum install mysql-proxy
# cat /etc/sysconfig/mysql-proxy# Options for mysql-proxyADMIN_USER="admin"ADMIN_PASSWORD=""ADMIN_LUA_SCRIPT="/usr/lib64/mysql-proxy/lua/admin.lua"PROXY_USER="mysql-proxy"PROXY_OPTIONS="--daemon --log-level=info --log-use-syslog"

修改PROXY_OPTIONS选项

#PROXY_OPTIONS="--daemon --log-level=info --log-use-syslog"PROXY_OPTIONS="--defaults-file=/etc/mysql/mysql-proxy.cnf"

# mkdir /etc/mysql# vim /etc/mysql/mysql-proxy.cnf[mysql-proxy]daemon = trueuser = mysql-proxyproxy-skip-profiling = truekeepalive = true;max-open-files = 2048event-threads = 512pid-file = /var/run/mysql-proxy.pidlog-file = /var/log/mysql-proxy.loglog-level = debugadmin-address=:4401admin-username=adminadmin-password=passw0rdadmin-lua-script=/usr/lib64/mysql-proxy/lua/admin.luaproxy-address = 0.0.0.0:3307proxy-backend-addresses = 192.168.2.1:3306proxy-read-only-backend-addresses=192.168.6.2:3306, 192.168.6.1:3306proxy-lua-script=/usr/lib64/mysql-proxy/lua/proxy/balance.lua

修复启动脚本BUG

# vim /etc/init.d/mysql-proxy#daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID --user=$PROXY_USER --admin-username="$ADMIN_USER" --admin-lua-script="$ADMIN_LUA_SCRIPT" --admin-password="$ADMIN_PASSWORD" 注视这行,改为下面的一行代码daemon $prog $PROXY_OPTIONS --pid-file=$PROXY_PID

启动mysql-proxy

# chkconfig mysql-proxy on# service mysql-proxy startStarting mysql-proxy:                                      [  OK  ]

1.8.2.1. FAQ

(critical) (libevent) evsignal_init: socketpair: Too many open files

;max-open-files = 2048

注释max-open-files = 2048,使用ulimit -SHn 2048设置

原文出处:Netkiller 系列 手札
本文作者:陈景峯
转载请与作者联系,同时请务必标明文章原始出处和作者信息及本声明。

你可能感兴趣的文章
开源 免费 java CMS - FreeCMS1.9 移动APP生成栏目列表数据
查看>>
git reset 三种用法总结
查看>>
hdfs笔记
查看>>
虚拟机新增加硬盘,不用重启读到新加的硬盘
查看>>
Java IO流详尽解析
查看>>
邮件服务系列之四基于虚拟用户的虚拟域的邮件系统(安装courier-authlib以及部分配置方法)...
查看>>
Linux VSFTP服务器
查看>>
DHCP中继数据包互联网周游记
查看>>
Squid 反向代理服务器配置
查看>>
Java I/O操作
查看>>
Tomcat性能调优
查看>>
项目管理心得
查看>>
Android自学--一篇文章基本掌握所有的常用View组件
查看>>
灰度图像和彩色图像
查看>>
通过vb.net 和NPOI实现对excel的读操作
查看>>
TCP segmentation offload
查看>>
java数据类型
查看>>
数据结构——串的朴素模式和KMP匹配算法
查看>>
FreeMarker-Built-ins for strings
查看>>
验证DataGridView控件的数据输入
查看>>