码迷,mamicode.com
首页 > 数据库 > 详细

mysql proxy 读写分离 1

时间:2015-11-17 07:03:07      阅读:294      评论:0      收藏:0      [点我收藏+]

标签:mysql proxy 读写分离 1

#查了资料折腾半天,测出来了

#参考http://blog.csdn.net/e421083458/article/details/19697701这个脚本不错。

技术分享

#依赖包

yum -y install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig* libevent* glib* readline-devel

#lua install

cd /home/chentp/tools

curl -R -O http://www.lua.org/ftp/lua-5.3.1.tar.gz

tar zxf lua-5.3.1.tar.gz

cd lua-5.3.1

make linux

make install

#user for daemon

useradd  mysql-proxy -s /sbin/nologin -M

#装mysql-proxy

cd /home/chentp/tools

tar xf mysql-proxy-0.8.5-linux-el6-x86-64bit.tar.gz

cp -rp mysql-proxy-0.8.5-linux-el6-x86-64bit/* /application/mysql-proxy/


echo ‘export PATH=$PATH:/application/mysql-proxy/bin/‘ >>/etc/profile

tail -3 /etc/profile

source /etc/profile


#启动脚本

cat /etc/init.d/mysql-proxy

############################################

#!/bin/sh

export LUA_PATH=/application/mysql-proxy/share/doc/mysql-proxy/?.lua:/applicaton/mysql-proxy/lib/mysql-proxy/lua/?.lua

mode=$1

if [ -z "$mode" ] ; then

  mode="start"

fi


case $mode in

  ‘start‘)

mysql-proxy --daemon \

--log-level=debug \

--user=mysql-proxy \

--keepalive \

--log-file=/var/log/mysql-proxy.log \

--plugins="proxy" \

--proxy-address=:4040 \

--proxy-backend-addresses=192.168.199.21:3306 \

--proxy-read-only-backend-addresses=192.168.199.22:3306 \

--proxy-read-only-backend-addresses=192.168.199.22:3307 \

--proxy-lua-script=/application/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua \

--plugins="admin" \

--admin-address=:4041 \

--admin-username="admin" \

--admin-password="admin" \

--admin-lua-script="/application/mysql-proxy/lib/mysql-proxy/lua/admin.lua"

    ;;


  ‘stop‘)

    killall mysql-proxy

    ;;


  ‘restart‘)

    if $0 stop ; then

      $0 start

    else

      echo  "retart failed!!!"

      exit 1

    fi

    ;;

esac


exit 0

####################################################

#更改为700权限

chmod 700 /etc/init.d/mysql-proxy


#连接代理数据库mysql-proxy,用for循环去压数据库代理

for i in `seq 10000`;do echo "this is quest $i";mysql -uoldboy -p111111 -h 192.168.199.20 -P 4040 -e "select * from oldboy.test" ; done;

#连接代理数据库mysql-proxy的管理界面,查看连接的分配情况

watch ‘mysql -uadmin -padmin -h 192.168.199.20 -P 4041 -e " select * from backends;"‘

+-------------+---------------------+-------+------+------+-------------------+

| backend_ndx | address             | state | type | uuid | connected_clients |

+-------------+---------------------+-------+------+------+-------------------+

|           1 | 192.168.199.21:3306 | up    | rw   | NULL |                 2 |

|           2 | 192.168.199.22:3306 | up    | ro   | NULL |                 1 |

|           3 | 192.168.199.22:3307 | up    | ro   | NULL |                 1 |

+-------------+---------------------+-------+------+------+-------------------+

#有个坑,说明备注

--proxy-backend-addresses=192.168.199.21:3306 \    主库

--proxy-read-only-backend-addresses=192.168.199.22:3306 \    从库

--proxy-read-only-backend-addresses=192.168.199.22:3307 \    从库


mysql proxy 读写分离 1

标签:mysql proxy 读写分离 1

原文地址:http://chentp.blog.51cto.com/10638759/1713228

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!