libevent libevent-devel glib2 glib2-devel lua 5.1.x lua-devel-5.1.x pkg-config mysql-devel openssl openssl-devel gcc* 2安装MySQL-proxy 0.8.5
下载源码包并解压 在源码包路径下安装 1
2
3
| ./configure –prefix=/u01/mysql-proxy
make
make install
|
3.配置mysql-proxy.cnf
内容如下: 1
2
3
4
5
6
7
8
9
10
11
| [mysql-proxy]
admin-username=root
admin-password=oracle
daemon=true
keepalive= true
proxy-backend-addresses= 10.8.13.207:3307
proxy-read-only-backend-addresses= 10.8.13.178:3306
proxy-lua-script= /u01/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
admin-lua-script= /u01/mysql-proxy/share/doc/mysql-proxy/admin.lua
log-file= /var/log/mysql-proxy.log
log-level= debug
|
4.配置rw-splitting.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
| -- *build a connection pool of min_idle_connections for each backend and maintain
-- its size
-- *
--
--
localcommands =require("proxy.commands")
localtokenizer =require("proxy.tokenizer")
locallb =require("proxy.balance")
localauto_config = require("proxy.auto-config")
---config
--
--connection pool
if notproxy.global.config.rwsplit then
proxy.global.config.rwsplit = {
min_idle_connections = 1,
max_idle_connections = 2,
is_debug = false
}
end
---
--read/write splitting sends all non-transactional SELECTs to the slaves
--
--is_in_transaction tracks the state of the transactions
localis_in_transaction = false
-- ifthis was a SELECT SQL_CALC_FOUND_ROWS ... stay on the same connections
localis_in_select_calc_found_rows = false
---
-- get aconnection to a backend
--
-- as long as we don't have enough connections in the pool,create new connections
|
视情况配置 5.启动mysql-proxy 1
| /u01/mysql-proxy/bin/mysql-proxy --defaults-file=/etc/mysql.cnf
|
6.测试 mysql-proxy 服务器ip为10.8.13.251
mysql –utest -p###### -h10.8.13.251 –P4040
在多个mysql客户端连接代理做dml及select操作,可以暂停主从库,看数据查询情况,从而确定mysql-proxy读写分离是否成功。
|