ubuntu下mysql读写分离

安装环境Ubuntu12.04

在设置读写分离前先配置mysql的主从备份

如http://7909846.blog.51cto.com/7899846/1305891所示

master192.168.100.119

slave192.168.100.116

负载调度器192.168.100.115

在负载调度器上安装mysql-proxy

$ sudo apt-get install mysql-proxy
		

将ENABLED改为true

$ sudo vim /etc/default/mysql-proxy
ENABLED="true"
OPTIONS="--defaults-file=/etc/mysql/mysql-proxy.cnf"
		
在etc下新建mysql文件夹

在mysql文件夹中创建mysql-proxy.cnf

$ sudo vi mysql-proxy.cnf

[mysql-proxy]
daemon = true
user = mysql
proxy-skip-profiling = true
keepalive = true
max-open-files = 2048
event-threads = 50
pid-file = /var/run/mysql-proxy.pid
log-file = /var/log/mysql-proxy.log
log-level = debug
admin-address=:4401
admin-username=admin
admin-password=passw0rd
admin-lua-script=/usr/local/lib/mysql-proxy/lua/admin.lua
proxy-address = 0.0.0.0:3307
proxy-backend-addresses = 192.168.100.119:3306
proxy-read-only-backend-addresses=192.168.100.116:3306
proxy-lua-script=/usr/lib/mysql-proxy/lua/proxy/balance.lua
		

修改权限,这个步骤不能省略,否则无法启动。

$ sudo chmod 660 /etc/mysql/mysql-proxy.cnf
		

启动mysql-proxy

$ sudo /etc/init.d/mysql-proxy start
 * Starting MySQL Proxy daemon...                    [ OK ]

你可能感兴趣的:(ubuntu下mysql读写分离)