时间:2021-07-01 10:21:17 帮助过:23人阅读
创建mysql用户:
mysql主从都需要创建相同的用户与密码:
grant all on *.* to ‘test‘@‘%‘ identified by ‘123456‘;
新建mysql-proxy配置文件:
vim /etc/mysql-proxy.cnf
添加:
[mysql-proxy]
admin-username = test
admin-password = 123456
daemon = true
keepalive = true
proxy-backend-addresses = 192.168.1.2:3306
proxy-read-only-backend-addresses = 192.168.1.2:3307
proxy-lua-script = /usr/local/proxy-mysql/share/doc/mysql-proxy/rw-splitting.lua
admin-lua-script = /usr/local/proxy-mysql/share/doc/mysql-proxy/admin-sql.lua
log-file = /usr/local/proxy-mysql/cn.log
log-level = debug
主要参数:
proxy-backend-addresses mysql主库(写)地址
proxy-read-only-backend-addresses mysql从库(读)地址
proxy-lua-script 读写分离脚本
admin-lua-script admin脚本
admin-username 数据库用户名(主从上都需建立相同用户)
admin-password 数据库密码
daemon daemon进程运行
keepalive 保持连接(启动进程会有2个,一号进程用来监>视二号进行,如果二号进程死掉自动重建,此参数在旧版本中无法使用)
创建mysql-proxy启动脚本:
vim /etc/init.d/mysql-proxy
#!/bin/bash
mode=$1
if [ -z "$mode" ] ; then
mode="start"
fi
case $mode in
start)
mysql-proxy --defaults-file=/etc/mysql-proxy.cnf>/usr/local/proxy-mysql/cn.log &
;;
stop)
killall -9 mysql-proxy
;;
restart)
if $0 stop ; then
$0 start
else
echo "Restart failed!"
exit 1
fi
;;
esac
exit 0
授权:
chmod 755 /etc/init.d/mysql-proxy
chkconfig --add mysql-proxy
启动mysql-proxy:
service mysql-proxy start
本文出自 “Linux” 博客,请务必保留此出处http://syklinux.blog.51cto.com/9631548/1743794
mysql 读写分离
标签:profile mysql local