部署MySQL-proxy
- 先安装lua
yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig* libevent* glib* readline-devel
mkdir -p /opt/lua && cd /opt/lua
wget http://www.lua.org/ftp/lua-5.4.3.tar.gz
tar -zxvf lua-5.4.3.tar.gz -C /usr/local/ && cd /usr/local
mv lua-5.4.3/ lua && cd lua && make linux && make install
export LUA_CFLAGS="-I/usr/local/include" LUA_LIBS="-L/usr/local/lib -llua -ldl" LDFLAGS="-lm"
- 下载mysql-proxy的安装包
tar -zxvf mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz -C /usr/local && mv /usr/local/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/ /usr/local/mysql-proxy && cd /usr/local/mysql-proxy && mkdir ./conf ./log
export PATH=$PATH:/usr/local/mysql-proxy/bin/
cp /usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua /usr/local/mysql-proxy/ && vi /usr/local/mysql-proxy/rw-splitting.lua
vi /usr/local/mysql-proxy/conf/mysql-proxy.conf
chmod 660 /usr/local/mysql-proxy/conf/mysql-proxy.conf
[mysql-proxy]
proxy-address=0.0.0.0:3306
proxy-backend-addresses=10.1.1.101:3306
proxy-read-only-backend-addresses=10.1.1.102:3306
proxy-lua-script=/usr/local/mysql-proxy/rw-splitting.lua
pid-file=/usr/local/mysql-proxy/log/mysql-proxy.pid
log-file=/usr/local/mysql-proxy/log/mysql-proxy.log
plugins=proxy
log-level=debug
keepalive=true
daemon=true
- 启动代理
mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf
- 查看日志
tailf /usr/local/mysql-proxy/log/mysql-proxy.log
--输出
2021-11-24 09:44:52: (message) chassis-unix-daemon.c:136: [angel] we try to keep PID=4998 alive
2021-11-24 09:44:52: (debug) chassis-unix-daemon.c:157: waiting for 4998
2021-11-24 09:44:52: (debug) chassis-unix-daemon.c:121: we are the child: 4998
2021-11-24 09:44:52: (critical) plugin proxy 0.8.5 started
2021-11-24 09:44:52: (debug) max open file-descriptors = 1024
2021-11-24 09:44:52: (message) proxy listening on port 0.0.0.0:3306
2021-11-24 09:44:52: (message) added read/write backend: 10.1.1.101:3306
2021-11-24 09:44:52: (message) added read-only backend: 10.1.1.102:3306