master:192.168.1.207
slave:192.168.1.208
msyql-proxy:192.168.1.206
Construction of Master-slave environment: temporary
Mysql-proxy Construction:
First, install Lua
wget http://www.lua.org/ftp/lua-5.1.4.tar.gz
Tar zxvf lua-5.1.4.tar.gz
CD lua-5.1.4
#vim Src/makefile
Will
Cflags=-o2-wall $ (mycflags)
Revision changed to
Cflags=-o2-fpic-wall $ (mycflags)
Make Linux (based on system selection, I am using make generic under CentOS)
Make install
wget http://cdn.mysql.com//Downloads/MySQL-Proxy/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz
wget http://cdn.mysql.com//Downloads/MySQL-Proxy/mysql-proxy-0.8.5.tar.gz
Tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz
MV Mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/opt/mysql-proxy
Mkdir-p/OPT/MYSQL-PROXY/INIT.D
Mkdir-p/opt/mysql-proxy/run
Mkdir-p/opt/mysql-proxy/log
Mkdir-p/opt/mysql-proxy/scripts
Tar zxvf mysql-proxy-0.8.5.tar.gz
CD mysql-proxy-0.8.5
CP lib/rw-splitting.lua/opt/mysql-proxy/scripts/
Vim/opt/mysql-proxy/scripts/rw-splitting.lua
Modify the comments section below
If not Proxy.global.config.rwsplit then
Proxy.global.config.rwsplit = {
Min_idle_connections = 1,//default is 4
Max_idle_connections = 1,//default is 8
Is_debug = False
}
End
Start Mysql-proxy
/opt/mysql-proxy/bin/mysql-proxy--proxy-read-only-backend-addresses=192.168.1.208:3306-- proxy-backend-addresses=192.168.1.207:3306--daemon--pid-file=/opt/mysql-proxy/run/mysql-proxy.pid--user=mysql- -log-level=debug--log-file=/opt/mysql-proxy/log/mysql-proxy.log--plugins=proxy--proxy-lua-script=/opt/ Mysql-proxy/scripts/rw-splitting.lua--plugins=admin--admin-username=admin--admin-password=admin-- Admin-lua-script=/opt/mysql-proxy/lib/mysql-proxy/lua/admin.lua--keepalive
Parameter explanation:
Proxy_path=/opt/mysql-proxy/bin//define MYSQL-PROXY service binary file path
proxy_options= "–admin-username=root \//define internal Management Server account
--admin-password=password \//define internal Management Server password
--proxy-read-only-backend-addresses=192.168.10.131:3306 \//define backend read-only from server address
--proxy-backend-addresses=192.168.10.130:3306 \//define back-end primary server address
--admin-lua-script=/opt/mysql-proxy/lib/mysql-proxy/lua/admin.lua \//define LUA Management script path
--proxy-lua-script=/opt/mysql-proxy/scripts/rw-splitting.lua "\//define LUA read-write detach script path
Proxy_pid=/opt/mysql-proxy/run/mysql-proxy.pid//define Mysql-proxy PID file path
$NICELEVEL $PROXY _path/mysql-proxy $PROXY _options \
--daemon \//definition starts in daemon mode
--keepalive \//causes the process to automatically recover after an abnormal shutdown
--pid-file= $PROXY _pid \//define Mysql-proxy PID file path
--user=mysql \//Start the service as a MySQL user
--log-level=debug \//define log log level, from high to Low (Error|warning|info|message|debug)
--log-file=/opt/mysql-proxy/log/mysql-proxy.log//define log log file path
Test steps:
Authorize Mysql-proxy server Connection account on master
Build test libraries and tables in master and sync to Slave
Close slave (stop slave)
Connection Mysql-proxy
Mysql-uroot-p-p4040-h $mysql-proxy_ip #-p4040 is a listening port for Mysql-proxy
After connecting and then testing the library to insert data, and then exit Reconnect Mysql-proxy query again, compare the data of two queries
The second query does not have the newly inserted data that represents the query to the slave, which realizes the read and write separation
Mysql-proxy read-Write separation test