mysql5.7.13支持读写分离吗

mysql5.7.13支持读写分离吗,第1张

mysql支持读写分离,可以参考如下实例:

1.确认环境

linux centos 7--64bit

2.准备材料

lua

mysql-proxy

3.安装lua

[root@bogon ~]# mkdir /opt/install/

[root@bogon ~]# cd /opt/install/

[root@bogon install]# tar zxvf lua-5.2.3.tar.gz

[root@bogon install]# cd lua-5.3.3

[root@bogon install]# make linux test

<pre name="code" class="plain">若没有错误择执行

[root@bogon install]# make linux

<pre name="code" class="plain">[root@bogon install]# make install

写入环境变量

[root@bogon install]# export LUA_CFLAGS="-I/usr/local/include" LUA_LIBS="-L/usr/local/lib -llua -ldl" LDFLAGS="-lm"

若是显示

readline/readline.h: No such file or directory

择需要安装

yum install readline-devel

4.安装mysql-proxy

[root@bogon install]# cd /opt/install

[root@bogon install]# tar zxvf mysql-proxy-0.8.5-linux-glibc2.3-x86-64bit.tar.gz

[root@bogon install]# mkdir /opt/mysql-proxy/

[root@bogon install]# cp /opt/install/mysql-proxy-0.8.4-linux-rhel5-x86-32bit/* /opt/mysql-proxy/

[root@bogon install]# cd /opt/mysql-proxy/

[root@bogon install]# export PATH=$PATH:/opt/mysql-proxy/bin/ #写入环境变量

5.编辑mysql-proxy配置文件

[root@bogon install]# cp share/doc/mysql-proxy/rw-splitting.lua ./

[root@bogon install]# vi rw-splitting.lua

6修改以下配置文件内容

if not proxy.global.config.rwsplit then

proxy.global.config.rwsplit = {

min_idle_connections = 4, # 4改成1

max_idle_connections = 8, # 8改成1

is_debug = false

}

end

7.执行任务

[root@bogon install]# mysql-proxy --proxy-read-only-backend-addresses=192.168.23.132:3306

<span style="white-space:pre"> </span>--proxy-backend-addresses=192.168.2.131:3306 --proxy-lua-script=/opt/mysql-proxy/share/rw-splitting.lua &

proxy-read-only-backend-addresses:从库的地址

<pre name="code" class="plain">proxy-backend-addresses: 主库的地址

<pre name="code" class="plain">proxy-lua-script=rw-spliting.lua脚本的路径

8.查看监听情况

[root@bogon install]# netstat -tlp | grep mysql-proxy

tcp0 0 *:yo-main *:* LISTEN 13364/mysql-proxy

9.创建用于读写分离的数据库连接用户

CREATE USER 'proxy'@'ip' IDENTIFIED BY '000000'

GRANT ALL ON *.* TO 'proxy1'@'ip' IDENTIFIED BY '000000'

FLUSH PRIVILEGES

10.设置mysql-proxy服务脚本

#!/bin/sh

#

# mysql-proxy This script starts and stops the mysql-proxy daemon

#

# chkconfig: - 78 30

# processname: mysql-proxy

# description: mysql-proxy is a proxy daemon to mysql

# Source function library.

. /etc/rc.d/init.d/functions

#PROXY_PATH=/usr/local/bin

PROXY_PATH=/opt/mysql-proxy/bin

prog="mysql-proxy"

# Source networking configuration.

. /etc/sysconfig/network

# Check that networking is up.

[ ${NETWORKING} = "no" ] &&exit 0

# Set default mysql-proxy configuration.

#PROXY_OPTIONS="--daemon"

PROXY_OPTIONS="--proxy-read-only-backend-addresses=192.168.23.132:3306 --proxy-backend-addresses=192.168.23.131:3306 --proxy-lua-script=/opt/mysql-proxy/share/rw-splitting.lua"

PROXY_PID=/opt/mysql-proxy/run/mysql-proxy.pid

# Source mysql-proxy configuration.

if [ -f /etc/sysconfig/mysql-proxy ]then

. /etc/sysconfig/mysql-proxy

fi

PATH=$PATH:/usr/bin:/usr/local/bin:$PROXY_PATH

# By default it's all good

RETVAL=0

# See how we were called.

case "$1" in

start)

# Start daemon.

echo -n $"Starting $prog: "

$NICELEVEL $PROXY_PATH/mysql-proxy $PROXY_OPTIONS --daemon --pid-file=$PROXY_PID --user=root --log-level=debug --log-file=/opt/mysql-proxy/log/mysql-proxy.log

RETVAL=$?

echo

if [ $RETVAL = 0 ]then

touch /var/lock/subsys/mysql-proxy]

echo "ok"

fi

stop)

# Stop daemons.

echo -n $"Stopping $prog: "

killproc $prog

RETVAL=$?

echo

if [ $RETVAL = 0 ]then

rm -f /var/lock/subsys/mysql-proxy

rm -f $PROXY_PID

fi

restart)

$0 stop

sleep 3

$0 start

condrestart)

[ -e /var/lock/subsys/mysql-proxy ] &&$0 restart

status)

status mysql-proxy

RETVAL=$?

*)

echo "Usage: $0 {start|stop|restart|status|condrestart}"

RETVAL=1

esac

exit $RETVAL

11.启动脚本

[root@bogon init.d]# /opt/mysql-proxy/init.d/mysql-proxy start

你需要重新安装那些被 “dpkg warning” 缺失的软件。

尝试修复:

强制修复

1   sudo apt-get -f install   

2. 如果上一步无效。你需要过滤出被 dpkg warning 的软件,然后执行下面的命令,重新挨个安装

1   sudo apt-get install --reinstall "package name"   

用 warning 中具体的软件名代替上面命令中的 package name

比如:dpkg: warning: files list file for package 'libcap2:amd64' missingassuming package has no files currently installed

重新安装的命令就是:

1   sudo apt-get install --reinstall "libcap2:amd64"   

如果想偷懒,只需执行下面一行命令,原理同上——过滤出被 dpkg warning 的软件,然后安装

1   sudo -i for package in $(apt-get upgrade 2>&1 | grep "warning: files list file for package '" | sed -rn 's/.*package '\''([^'\'']+).*/\1/p') do apt-get install --reinstall "$package" done   

首先要学会搜索。

其次你这个问题可能情况是你安装Mysql时的数据部分指定的路径和My.cnf里的database=/...

不一至造成的。

解决方法是写成一致:

如何判定安装时的参数路径呢,如果是你本人配置通常会记得。但是其他人安装的。也是有办法的:比如下面的:

1、nginx编译参数:

your_nginx_dir/sbin/nginx -v

2、apache编译参数:

cat your_apache_dir/build/config.nice

3、php编译参数:

your_php_dir/bin/php -i |grep configure

4、mysql编译参数:

cat your_mysql_dir/bin/mysqlbug |grep configure

---------------------------------------------------

如果Cmake编译安装的Mysql可以通过。

mysql安装目录,这个可以通过find / -name mysql来确定位置。

然后在其安装目录的bin目录运行mysql_config,如下显示各个参数,将上面显示位置写在配置文件my.cnf中。再启动。

Usage: ./mysql_config [OPTIONS]

Options:

--cflags [-I/usr/local/mysql/include -g]

--include[-I/usr/local/mysql/include]

--libs [-L/usr/local/mysql/lib -lmysqlclient -lpthread -lz -lm -lrt -ldl]

--libs_r [-L/usr/local/mysql/lib -lmysqlclient_r -lpthread -lz -lm -lrt -ldl]

--plugindir [/usr/local/mysql/lib/plugin]

--socket [/var/lib/mysql/data/mysql.sock]

--port [0]

--version[5.5.20]

--libmysqld-libs [-L/usr/local/mysql/lib -lmysqld]

--variable=VAR VAR is one of:

pkgincludedir [/usr/local/mysql/include]

pkglibdir [/usr/local/mysql/lib]

plugindir [/usr/local/mysql/lib/plugin]

++++++++++++++++++++++++++++++++++++++

通常RPM安装都可以正常启动,除非你外更改了配置my.cnf

如果是RPM安装的

可以搜索 rpm -ql mysql


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/8613355.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-18
下一篇 2023-04-18

发表评论

登录后才能评论

评论列表(0条)

保存