时间:2021-07-01 10:21:17 帮助过:15人阅读
把实现读写分离的 lua 脚本复制到 etc 目录下
[root@SQL-proxy mysql-proxy]# cp share/doc/mysql-proxy/rw-splitting.lua etc/
[root@SQL-proxy mysql-proxy]# cp share/doc/mysql-proxy/admin-sql.lua etc/
创建启动参数文件,启动服务时命令行就不用老长老长的。
[root@SQL-proxy ~]# vim /etc/mysql-proxy.cnf
[mysql-proxy]
user=root
admin-username=root
admin-password=123456
proxy-address=192.168.72.134
proxy-read-only-backend-addresses=192.168.72.128
proxy-backend-addresses=192.168.72.130
proxy-lua-script=/usr/local/src/mysql-proxy/etc/rw-splitting.lua
admin-lua-script=/usr/local/src/mysql-proxy/etc/admin-sql.lua
log-file=/usr/local/src/mysql-proxy/logs/mysql-proxy.log
log-level=info
daemon=true
keepalive=true
启动服务
[root@SQL-proxy ~]# /usr/local/src/mysql-proxy/bin/mysql-proxy --defaults-file=/etc/mysql-proxy.cnf
2017-04-24 16:40:19: (critical) mysql-proxy-cli.c:326: loading config from ‘/etc/mysql-proxy.cnf‘ failed: permissions of /etc/mysql-proxy.cnf aren‘t secure (0660 or stricter required)
2017-04-24 16:40:19: (message) Initiating shutdown, requested from mysql-proxy-cli.c:328
2017-04-24 16:40:19: (message) shutting down normally, exit code is: 1
!!看到无法启动,文件权限要改,因为文件里面有账号密码。
[root@SQL-proxy ~]# chmod 660 /etc/mysql-proxy.cnf # 改权限 [root@SQL-proxy ~]# ll /etc/mysql-proxy.cnf
-rw-rw---- 1 root root 432 Apr 24 16:31 /etc/mysql-proxy.cnf
[root@SQL-proxy ~]# /usr/local/mysql-proxy/bin/mysql-proxy --defaults-file=/etc/mysql-proxy.cnf # 重新启动
[root@SQL-proxy ~]# netstat -lntup # 查看服务
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name
tcp 0 0 192.168.0.86:3306 0.0.0.0:* LISTEN 3086/mysql-proxy
老是命令行敲一长串命令肯定不科学了,直接上服务管理脚本。
[root@SQL-proxy ~]# vim /etc/init.d/mysql-proxy #!/bin/bash # # mysql-proxy This script starts and stops the mysql-proxy daemon # # chkconfig: - 78 30 # processname: mysql-proxy # description: mysql-proxy is a proxy daemon for mysql # Source function library. . /etc/rc.d/init.d/functions prog="/usr/local/mysql-proxy/bin/mysql-proxy" # Source networking configuration. if [ -f /etc/sysconfig/network ]; then . /etc/sysconfig/network fi # Check that networking is up. [ ${NETWORKING} = "no" ] && exit 0 DEFAULT_FILE=/etc/mysql-proxy.cnf PROXY_PID=/var/run/mysql-proxy.pid RETVAL=0 start() { echo -n $"Starting MySQL-proxy... : " daemon $prog --defaults-file=$DEFAULT_FILE RETVAL=$? echo if [ $RETVAL -eq 0 ]; then touch /var/lock/subsys/mysql-proxy.lock fi } stop() { echo -n $"Stopping MySQL-proxy... : " killproc -p $PROXY_PID -d 3 $prog RETVAL=$? echo if [ $RETVAL -eq 0 ]; then rm -f /var/lock/subsys/mysql-proxy.lock rm -f $PROXY_PID fi } # See how we were called. case "$1" in start) start ;; stop) stop ;; restart) stop start ;; condrestart|try-restart) if status -p $PROXY_PIDFILE $prog >&/dev/null; then stop start fi ;; status) status -p $PROXY_PID $prog ;; *) echo "Usage: $0 {start|stop|restart|reload|status|condrestart|try-restart}" RETVAL=1 ;; esac exit $RETVAL
[root@SQL-proxy ~]# chmod +x /etc/init.d/mysql-proxy # 给执行权限
[root@SQL-proxy ~]# chkconfig mysql-proxy on # 可以加入开机启动
测试一下脚本:
[root@SQL-proxy ~]# /etc/init.d/mysql-proxy status mysql-proxy (pid 3086) is running... [root@SQL-proxy ~]# [root@SQL-proxy ~]# /etc/init.d/mysql-proxy stop Stopping MySQL-proxy... : [ OK ] [root@SQL-proxy ~]# [root@SQL-proxy ~]# /etc/init.d/mysql-proxy status mysql-proxy is stopped [root@SQL-proxy ~]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 1079/sshd tcp 0 0 :::22 :::* LISTEN 1079/sshd [root@SQL-proxy ~]# /etc/init.d/mysql-proxy start Starting MySQL-proxy... : [ OK ] [root@SQL-proxy ~]# /etc/init.d/mysql-proxy restart Stopping MySQL-proxy... : [ OK ] Starting MySQL-proxy... : [ OK ] [root@SQL-proxy ~]# [root@SQL-proxy ~]# netstat -lntup Active Internet connections (only servers) Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name tcp 0 0 192.168.0.86:3306 0.0.0.0:* LISTEN 3143/mysql-proxy
以上MySQL-proxy服务器搭建完成,但是用于连接后端数据库的用户:proxy还需要在数据库端创建
LAMP+redis搭建discuz论坛,基于mysql-proxy插件主从同步
标签:toolbar list start prot mkdir 测试环境 mysq ssi mod