Nonsense not to say, directly open dry:
1. Installation Environment:
Yum-y install libevent glib2 lua gcc gcc-c++ autoconf mysql-devel libtool pkgconfig ncurses ncurses-devel libevent-devel
2. Download the file:
wget ftp://mysql.cdpa.nsysu.edu.tw/Unix/Database/MySQL/Downloads/MySQL-Proxy/mysql-proxy-0.8.5.tar.gz
3. Compile and install:
Tar zxvf mysql-proxy-0.8.5.tar.gz
CD mysql-proxy-0.8.5
./configure--prefix=/home/mysql-proxy/
Make
Make install
Mkdir/home/mysql-proxy/logs
Mkdir/home/mysql-proxy/lua
CP Lib/admin-sql.lua/home/mysql-proxy/lua
CP Lib/rw-splitting.lua/home/mysql-proxy/lua
Cp-r lib/proxy/home/mysql-proxy/
4. Edit the configuration file:
VI/ETC/MYSQL-PROXY.CNF #创建配置文件
[Mysql-proxy]
User=root #运行mysql-proxy User
Admin-username=proxy #主从mysql共有的用户
Admin-password=123.com #用户的密码
proxy-address=10.10.10.49:4000 #mysql-proxy Run IP and port, no port, default 4040
proxy-read-only-backend-addresses=10.10.10.50:3306 #指定后端从slave读取数据
proxy-backend-addresses=10.10.10.51:3306 #指定后端主master写入数据
Proxy-lua-script=/usr/local/mysql-proxy/lua/rw-splitting.lua #指定读写分离配置文件位置
Admin-lua-script=/usr/local/mysql-proxy/lua/admin-sql.lua #指定管理脚本
Log-file=/usr/local/mysql-proxy/logs/mysql-proxy.log #日志位置
Log-level=info #定义log日志级别, from high to Low (Error|warning|info|message|debug)
Daemon=true #以守护进程方式运行
Keepalive=true #mysql-proxy crashes, try restarting
Save Exit!
chmod 660/etc/mysql-porxy.cnf
5. Modify the Rw-splitting.lua file
Vi/usr/local/mysql-proxy/lua/rw-splitting.lua
If not Proxy.global.config.rwsplit then
Proxy.global.config.rwsplit = {
Min_idle_connections = 1, #默认超过4个连接数时 before starting read-write separation, changed to 1
Max_idle_connections = 1, #默认8, changed to 1
Is_debug = False
}
End
6. Start:
/home/mysql-proxy/bin/mysql-proxy--defaults-config=/etc/mysql-proxy.cnf
To view a process:
NETSTAT-TUPLN | grep 4000 #已经启动
TCP 0 0 10.10.10.49:4000 0.0.0.0:* LISTEN 1264/mysql-proxy
Off Mysql-proxy used: killall-9 mysql-proxy
7. Assign permissions on the main library:
Grant all on * * to ' proxies ' @ ' 10.10.10.49 ' identified by ' 123456 ';
8, test (please configure Firewall Open 4000 port):
Mysql-u proxy-h 10.10.10.49-p 4000-p123456
Create the database and the table, then the data only write to the master MySQL, and then sync from the slave, you can first turn off the slave, see if you can write
Master-Slave read-write separation----mysql-proxy0.8.5 installation and configuration