本文共 3464 字,大约阅读时间需要 11 分钟。
wget
tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz echo "export MYSQL_PROXY=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit">>/etc/profile echo "export PATH=$MYSQL_PROXY/bin:$PATH">>/etc/profile source /etc/profilemkdir -p /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/logs/
firewall-cmd --add-port=4040/tcp --permanent firewall-cmd --reloadvi /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.cnf
[mysql-proxy] user=root admin-username=root admin-password=xmrbi3967968@ proxy-address=10.0.39.90:4040 proxy-read-only-backend-addresses=realmysqlip proxy-backend-addresses=realmysqlip proxy-lua-script=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/share/doc/mysql-proxy/rw-splitting.lua admin-lua-script=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/share/doc/mysql-proxy/admin-sql.lua log-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/logs/mysql-proxy.log log-level=info daemon=true keepalive=truechmod 600 /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.cnf
if not proxy.global.config.rwsplit then
proxy.global.config.rwsplit = { min_idle_connections = 1, #默认超过4个连接数时,才开始读写分离,改为1 max_idle_connections = 1, #默认8,改为1 is_debug = false } endmysql-proxy --defaults-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.cnf
vi /usr/lib/systemd/system/mysql-proxy-readwrite.service
[Unit] Description=Mysql Proxy read write After=rc-local.service[Service]
Type=forking ExecStart=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/bin/mysql-proxy --defaults-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.cnf ExecReload=/usr/bin/pkill mysql-proxy && /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/bin/mysql-proxy --defaults-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.cnf ExecStop=/usr/bin/pkill mysql-proxy Restart=on-failure RestartSec=42s PrivateTmp=true[Install]
WantedBy=multi-user.targetps -ef|grep mysql-proxy|grep -v 'grep'|awk '{print $2}'
/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/bin/mysql-proxy
--proxy-address=ipaddress:4040 \ #这个是安装mysql-proxy的主机上的ip,这个4040端口是mysql-proxy的默认端口 --proxy-backend-addresses=192.168.2.45:3125 \ #这个是mysql服务器安装主机的ip和mysql的端口 --proxy-backend-addresses=192.168.2.45:3126 --log-level=info --log-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/logs/mysql-proxy.log \ #存放日志文件的位置 --daemonmysql -uroot -p123456 -h1.0.0.3 -P4040
xargs -L 1 kill -HUP
vi /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.sh
/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/bin/mysql-proxy
--proxy-address=10.0.39.90:4040 --proxy-backend-addresses=realmysqlip:3306 --proxy-read-only-backend-addresses=realmysqlip:3306 --proxy-lua-script=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/share/doc/mysql-proxy/rw-splitting.lua --log-level=info --log-file=/data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/logs/mysql-proxy-readwrite.log --daemonchmod +x /data/mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit/mysql-proxy-readwrite.sh
转载地址:http://lkmix.baihongyu.com/