环境:
mysql主库 192.168.160.250
mysql从库 192.168.160.233
mysqlproxy 192.168.110.110
[root@ local]# getconf LONG_BIT
64
wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/
网站上下载
wget http://mysql.cdpa.nsysu.edu.tw/Downloads/MySQL-Proxy/mysql-proxy-0.8.4-linux-rhel5-x86-64bit.tar.gz
tar zxvf mysql-proxy-0.8.3-linux-rhel5-x86-64bit.tar.gz -C /usr/local/
cd /usr/local/
mv mysql-proxy-0.8.3-linux-rhel5-x86-64bit/ mysql-proxy
vim /etc/profile
export PATH=/usr/local/share/aclocal:/usr/local/mysql/bin:/usr/local/mysql-proxy/bin:$PATH
source /etc/profile
[root@xnile local]# mysql-proxy --help
Usage:
mysql-proxy [OPTION...] - MySQL Proxy
Help Options:
-?, --help Show help options
--help-all Show all help options
--help-proxy Show options for the proxy-module
Application Options:
-V, --version Show version
--defaults-file=
--verbose-shutdown Always log the exit code when shutting down
--daemon Start in daemon-mode
--user=
--basedir=
--pid-file=
--plugin-dir=
--plugins=
--log-level=(error|warning|info|message|debug) log all messages of level ... or higher
--log-file=
--log-use-syslog log all messages to syslog
--log-backtrace-on-crash try to invoke debugger on crash
--keepalive try to restart the proxy if it crashed
--max-open-files maximum number of open files (ulimit -n)
--event-threads number of event-handling threads (default: 1)
--lua-path=<...> set the LUA_PATH
--lua-cpath=<...> set the LUA_CPATH
[root@xnile local]# mysql-proxy --help-proxy
Usage:
mysql-proxy [OPTION...] - MySQL Proxy
proxy-module
-P, --proxy-address=
-r, --proxy-read-only-backend-addresses=
-b, --proxy-backend-addresses=
--proxy-skip-profiling disables profiling of queries (default: enabled)
--proxy-fix-bug-25371 fix bug #25371 (mysqld > 5.1.12) for older libmysql versions
-s, --proxy-lua-script=
--no-proxy don't start the proxy-module (default: enabled)
--proxy-pool-no-change-user don't use CHANGE_USER to reset the connection coming from the pool (default: enabled)
--proxy-connect-timeout connect timeout in seconds (default: 2.0 seconds)
--proxy-read-timeout read timeout in seconds (default: 8 hours)
--proxy-write-timeout write timeout in seconds (default: 8 hours)
[mysql-proxy]
proxy-address=192.168.110.110:38141 可以修改端口
[root@xnile bin]# vim +40 /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
29
30 local commands = require("proxy.commands")
31 local tokenizer = require("proxy.tokenizer")
32 local lb = require("proxy.balance")
33 local auto_config = require("proxy.auto-config")
34
35 --- config
36 --
37 -- connection pool
38 if not proxy.global.config.rwsplit then
39 proxy.global.config.rwsplit = {
40 min_idle_connections = 1,
41 max_idle_connections = 2,
42
43 is_debug = false
44 }
45 end
46
保证主从同步可以安装SemiSyncReplication插件
测试挺简单,不写了
[root@xnile bin]# more /var/tmp/mysql-proxy.log
2014-05-21 11:16:25: (debug) chassis-unix-daemon.c:121: we are the child: 7306
2014-05-21 11:16:25: (message) chassis-unix-daemon.c:136: [angel] we try to keep PID=7306 alive2014-05-21 11:16:25: (critical) plugin proxy 0.8.3 started
2014-05-21 11:16:25: (debug) max open file-descriptors = 65535
2014-05-21 11:16:25: (debug) chassis-unix-daemon.c:157: waiting for 7306
2014-05-21 11:16:25: (message) proxy listening on port :4040
2014-05-21 11:16:25: (message) added read/write backend: 192.168.160.250:3306
2014-05-21 11:16:25: (message) added read-only backend: 192.168.160.233:3306
2014-05-21 11:17:00: (message) chassis-unix-daemon.c:136: [angel] we try to keep PID=7320 alive
2014-05-21 11:17:00: (debug) chassis-unix-daemon.c:157: waiting for 7320
2014-05-21 11:17:00: (debug) chassis-unix-daemon.c:121: we are the child: 7320
2014-05-21 11:17:00: (critical) plugin proxy 0.8.3 started
2014-05-21 11:17:00: (debug) max open file-descriptors = 65535
2014-05-21 11:17:00: (message) proxy listening on port :4040
2014-05-21 11:17:00: (message) added read/write backend: 192.168.160.250:3306
2014-05-21 11:17:00: (message) added read-only backend: 192.168.160.233:3306
2014-05-21 11:25:34: (message) proxy-plugin.c.1664: connect(192.168.160.250:3306) failed: Connection refused. Retrying with different backend.
2014-05-21 11:25:34: (critical) proxy-plugin.c.1773: Cannot connect, all backends are down.
2014-05-21 11:27:34: (debug) network-backend.c.184: backend 192.168.160.250:3306 was down for more than 4 sec, waking it up
2014-05-21 11:40:21: (message) chassis-unix-daemon.c:136: [angel] we try to keep PID=7476 alive
2014-05-21 11:40:21: (debug) chassis-unix-daemon.c:121: we are the child: 7476
2014-05-21 11:40:21: (debug) chassis-unix-daemon.c:157: waiting for 7476
2014-05-21 11:40:21: (critical) plugin proxy 0.8.3 started
2014-05-21 11:40:21: (debug) max open file-descriptors = 65535
2014-05-21 11:40:21: (critical) network-socket.c:451: bind(0.0.148.253:3306) failed: Address already in use (98)
2014-05-21 11:40:21: (critical) chassis-mainloop.c:267: applying config of plugin proxy failed
2014-05-21 11:40:21: (critical) mysql-proxy-cli.c:597: Failure from chassis_mainloop. Shutting down.
2014-05-21 11:40:21: (message) Initiating shutdown, requested from mysql-proxy-cli.c:598
2014-05-21 11:40:21: (message) shutting down normally, exit code is: 1
2014-05-21 11:40:21: (debug) chassis-unix-daemon.c:167: 7476 returned: 7476
2014-05-21 11:40:21: (message) chassis-unix-daemon.c:176: [angel] PID=7476 exited normally with exit-code = 1 (it used 1 kBytes max)
2014-05-21 11:40:21: (message) Initiating shutdown, requested from mysql-proxy-cli.c:273
2014-05-21 11:40:21: (message) shutting down normally, exit code is: 1
2014-05-21 11:41:18: (critical) mysql-proxy-cli.c:503: Unknown option -p (use --help to show all options)
2014-05-21 11:41:18: (message) Initiating shutdown, requested from mysql-proxy-cli.c:513
2014-05-21 11:41:18: (message) shutting down normally, exit code is: 1
2014-05-21 11:41:22: (critical) mysql-proxy-cli.c:503: Unknown option -p (use --help to show all options)
2014-05-21 11:41:22: (message) Initiating shutdown, requested from mysql-proxy-cli.c:513
2014-05-21 11:41:22: (message) shutting down normally, exit code is: 1
2014-05-21 11:49:32: (message) chassis-unix-daemon.c:136: [angel] we try to keep PID=7524 alive2014-05-21 11:49:32: (debug) chassis-unix-daemon.c:121: we are the child: 7524