MySQL proxy read-write separation 1

Source: Internet
Author: User
Tags lua

#查了资料折腾半天, it's coming.

#参考http://blog.csdn.net/e421083458/article/details/19697701 This script is good.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M01/76/15/wKiom1ZJwd3gcw38AAEoaxJt01w372.jpg "title=" Mysql-proxy "alt=" Wkiom1zjwd3gcw38aaeoaxjt01w372.jpg "/>

#依赖包

Yum-y Install gcc* gcc-c++* autoconf* automake* zlib* libxml* ncurses-devel* libmcrypt* libtool* flex* pkgconfig* Libeven t* 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 $ stop; Then

$ start

Else

echo "Retart failed!!!"

Exit 1

Fi

;;

Esac


Exit 0

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

#更改为700权限

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


#连接代理数据库mysql-proxy, use a For loop to press the database proxy

For i in ' seq 10000 ';d o echo "This is Quest $i", Mysql-uoldboy-p111111-h 192.168.199.20-p 4040-e "SELECT * from Oldboy . Test "; Done

#连接代理数据库mysql-proxy Management interface to view the distribution of connections

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 |

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

#有个坑, Description remarks

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

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

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


MySQL proxy read-write separation 1

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.