Mysql DATA separation (mysql-proxy configuration) 1. Install MySQL2 and install Lua # wget http://www.lua.org/ftp/lua-5.1.4.tar.gz # Tar xzf lua-5.1.4.tar.gz # cd lua-5.1.4 # make linux INSTALL_TOP =/usr/local/lua # make install 3. install glib # wget http://ftp.gnome.org/pub/gnome/sources/glib/2.28/glib-2.28.4.tar.bz2 # Tar jxf glib-2.28.4.tar.bz2 # cd glib-2.28.4 #. /configure -- prefix =/opt/module/glib2 # make & make install # echo "/opt/module/glib2/lib">/etc/ld. so. conf # ldconfig 4. Install pkg-config # wget http://pkg-config.freedesktop.org/releases/pkgconfig-0.18.tar.gz # Tar xzf pkgconfig-0.18.tar.gz # cd pkgconfig-0.18 #./configure & make install 5, install libevent # wget http://monkey.org/%7Eprovos/libevent-2.0.10-stable.tar.gz # Tar zxf libevent-2.0.10-stable.tar.gz # cd libevent-2.0.10-stable #./configure -- prefix =/opt/module/libevent # make; make install 6, install mysql-proxy # wget http://dev.mysql.com/get/Downloads/MySQL-Proxy/mysql-proxy-0.8.1.tar.gz/from/http://mysql.he.net/ # Tar xzf mysql-proxy-0.8.1.tar.gz # cd mysql-proxy-0.8.1 # export LUA_CFLAGS = "-I/usr/local/include" LUA_LIBS = "-L/usr/local/lib-llua-ldl" LDFLAGS =" -lm "export PKG_CONFIG_PATH ="/usr/lib/pkgconfig/"export GLIB_CFLAGS ="-I/opt/module/glib2/include/glib-2.0-I/opt/module/ glib2/lib/glib-2.0/include "GLIB_LIBS ="-L/opt/module/glib2/lib-lglib-2.0 "export GMODULE_CFLAGS ="-I/opt/module/glib2/include "GMOD ULE_LIBS = "-L/opt/module/glib2/lib" export GTHREAD_CFLAGS = "-I/opt/module/glib2/include" export GTHREAD_LIBS = "-L/opt/module/ glib2/lib "export CPPFLAGS =" $ CPPFLAGS-I/opt/module/libevent/include "export CFLAGS =" $ CFLAGS-I/opt/module/libevent/include "export LDFLAGS = "$ LDFLAGS-L/opt/module/libevent/lib-lm" export LIBS = "/opt/module/glib2/lib/libgthread-2.0.so/opt/module/glib2/lib/ libgmodule-2.0.so "#. /Configure -- with-mysql = "/opt/module/mysql" -- prefix = "/opt/module/mysql-proxy" to check whether the installation is successful: #/opt/module/mysql-proxy/bin/mysql-proxy -- help-all | less Configuration: # vi/etc/mysql-proxy.cnf ============================= [mysql-proxy] admin-username = mysqlproxyadm Master/Slave databases are required admin-password = 123456 daemon = true keepalive = true log-file =/opt/module/mysql-proxy/log-level = debug proxy-backend-addresses = 19 Listen 1.223: 3306 master proxy-read-only-backend-address = 192.168.1.222: 3306 from proxy-read-only-backend-address = 192.168.1.20: 3306 from proxy-lua-script =/opt/module/mysql-proxy/rw-splitting.lua admin-lua-script =/opt/module/mysql-proxy/lib/mysql-proxy/lua /admin. lua ============================#chmod 0660/etc/mysql-proxy.cnf make Startup Script: # vi/etc/init. d/mysql-proxy ============================== #! /Bin/sh export LUA_PATH =/opt/module/mysql-proxy /?. Lua mode = $1; if [-z $ mode]; then mode = "start" fi case $ mode in start) /opt/module/mysql-proxy/bin/mysql-proxy -- defaults-file =/etc/mysql-proxy.cnf>/opt/module/mysql-proxy/log &; stop) killall-9 mysql-proxy; *) echo "Usage: $0 (start | stop)" exit 1; esac exit 0; ================================#chmod + x/etc/init. d/mysql-proxy write mysql-proxy to implement read/write separation script # vi/opt/module/mysql-proxy/rw-splitting.lua ============== send all to a slave database if is_in_transaction = 0 and packet: byte () = proxy. COM_QUERY and packet: sub (2, 7) = "SELECT" then local max_conns =-1 local max_conns_ndx = 0 for I = 1, # proxy. servers do local s = proxy. servers [I] needs to select a slave database with idle connection if s. type = proxy. BACKEND_TYPE_RO and s. idling_connections> 0 then if max_conns =-1 or s. connected_clients <MAX_CONNS max_conns_ndx = "I" if so far, an end max_conns = "s. connected_clients "then> 0 then proxy. connection. backend_ndx = max_conns_ndx end else is sent to the master database end return proxy. PROXY_SEND_QUERY ============= start mysql-proxy #/etc/init. d/mysql-proxy start Note: copy the virtual hard disk of the virtual machine, such as 219.vdi, and rename it as 218.vdi. in this case, use virtualbox to create a virtual host and directly connect to the hard disk. A message indicating a duplicate uuid is displayed, this problem can be solved by using the internal commands of virtualbox: C: \ Documents ents and Settings \ Administrator> "c: \ Program Files \ Oracle \ VirtualBox" \ VBoxManage internalcommands setvdiuuid E: \ HardDisks \ 217.vdi