标签:mamicode 配置 useradd client 复杂度 需求 class tps path
mysql 读写分离读写分离首先不推荐使用,很多业务场景也没有必要,不仅增加技术复杂度,而且可能会导致读到落后的数据,建议优化数据库,推荐使用keepalive+mysql双主复制的方案
然后mysql-proxy是官方推出的中间件,不仅无法高可用,而且这个项目已经夭折了,使用mysql-route了,本次仅记录mysql-proxy的安装过程。
mysql-proxy不再支持mysql5.7以后的client客户端登录
系统版本 centos7.8
mysql-proxy 192.168.197.128
主mysql 192.168.197.129
从mysql 192.168.197.130
yum -y install gcc gcc-c++ ncurses ncurses-devel cmake bison bison-devel
yum -y install mariadb-server mariadb mariadb-libs
具体主从配置mysql5.7主从复制配置
注意:由于mysql-proxy不再支持 mysql5.7以上的访问mysql访问后端server,故只参考里面的配置文件即可,不用安装mysql5.7
创建proxy系统用户
useradd -r mysql-proxy
mkdir -p /usr/local/mysql-proxy
cd /usr/local/mysql-proxy
wget http://ftp.ntu.edu.tw/pub/MySQL/Downloads/MySQL-Proxy/mysql-proxy-0.8.4-linux-el6-x86-64bit.tar.gz
tar -zxvf mysql-proxy-0.8.4-linux-el6-x86-64bit.tar.gz
mv mysql-proxy-0.8.4-linux-el6-x86-64bit/* /usr/local/mysql-proxy/
echo -e ‘\n\nexport PATH=/usr/local/mysql-proxy/bin/:$PATH\n‘ >> /etc/profile && source /etc/profile
方法一:直接命令启动
mysql-proxy --daemon --log-level=debug --user=mysql-proxy --keepalive --log-file=/var/log/mysql-proxy.log --plugins="proxy" --proxy-backend-addresses="192.168.197.129:3306" --proxy-read-only-backend-addresses="192.168.197.130:3306" --proxy-lua-script="/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua" --plugins=admin --admin-username="admin" --admin-password="admin" --admin-lua-script="/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua"
方法二:(推荐)添加配置文件启动
mkdir -p /usr/local/mysql-proxy/conf
mkdir -p /usr/local/mysql-proxy/log
vim /usr/local/mysql-proxy/conf/mysql-proxy.conf
[mysql-proxy]
user=mysql-proxy
admin-username=admin
admin-password=admin
#proxy-address=192.168.197.128:3306
proxy-backend-addresses=192.168.197.129:3306
proxy-read-only-backend-addresses=192.168.197.130:3306
admin-lua-script=/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua
proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
pid-file=/usr/local/mysql-proxy/log/mysql-proxy.pid
log-file=/usr/local/mysql-proxy/log/mysql-proxy.log
plugins=admin,proxy
log-level=debug
keepalive=true
daemon=true
chmod 660 /usr/local/mysql-proxy/conf/mysql-proxy.conf
启动
/usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/usr/local/mysql-proxy/conf/mysql-proxy.conf
netstat -lntp | grep mysql
4040 代理监听,web对外接口
4041 管理模块监听,查询proxy自身的状态
#账号密码由步骤3中的启动代码指定,具体如下
#--plugins=admin --admin-username="admin" --admin-password="admin" --admin-lua-script="/usr/local/mysql-proxy/lib/mysql-proxy/lua/admin.lua"
mysql -h 192.168.197.128 -uadmin -padmin -P4041 -e ‘select * from backends;‘
提示unknown,所以需要在master与slave数据库添加对proxy进行访问授权
grant all on *.* to root@‘%‘ identified by "Huawei12#$";
flush privileges;
mysql -h192.168.197.128 -uroot -pHuawei12#$ -P4040 -e ‘show databases;‘
退出数据库,使用admin登录查看proxy状态
mysql -h 192.168.197.128 -uadmin -padmin -P4041 -e ‘select * from backends;‘
通过授权连接后,proxy显示主从up状态
标签:mamicode 配置 useradd client 复杂度 需求 class tps path
原文地址:https://blog.51cto.com/11442747/2513842