Preface, there are already a lot of MySQL middle layer, Baidu's Dbproxy,taobao Tddl, 126, Alibaba corba,360 Altas, Mysql-proxy, Lou Fangxin Oneproxy,sohu dbproxy , fabric, and so on. Some support the sub-database sub-table, some do not support. Just choose the right one. However, if you do technology selection, still have to be careful. Choose self-development or use existing third-party products to be cautious. (see Libevent Understand, can do independent research and development, but to develop a stable version, need a period of time, developed and put on the line, will tread a lot of pits, personal experience, no online running 2 years of time products, do not use. We developed this, ran for almost 3 years, until 12, only to stabilize, before the bug constantly
#安装dbproxy Altas Basically according to Zhu Su wrote this, you can install the installation of Http://github.com/Qihoo360/Atlas/wiki/Atlas
A. Download
Mkdir-p/data/software && Cd/data/software
wget https://github.com/Qihoo360/Atlas/archive/2.2.1.tar.gz
MV 2.2.1.tar.gz atlas.2.2.1.tar.gz
Tar zxvf atlas.2.2.1.tar.gz
two. Install the library file
#安装库文件, GCC and other compilation environments, need to be well-prepared, this is over.
Yum install-y libevent-devel lua-devel openssl-devel Flex Mysql-devel
Yum install-y XZ Gettext-devel
# Libffi,glib (>2.32)
Yum-y Install libffi*
Cd/data/software
wget HTTP://FTP.ACC.UMU.SE/PUB/GNOME/SOURCES/GLIB/2.33/GLIB-2.33.6.TAR.XZ
Xz-d GLIB-2.33.6.TAR.XZ
CD glib-2.33.6
./configure
Make
Make install
Ldconfig
# Jemalloc
Cd/data/software
wget http://www.canonware.com/download/jemalloc/jemalloc-3.1.0.tar.bz2
Tar xvf jemalloc-3.1.0.tar.bz2
Make
Make install
cp/data/software/jemalloc-3.1.0/lib/libjemalloc.so.1/usr/local/lib/
Ldconfig
three. Compiling and installing Atlas
cd/data/software/atlas-2.2.1
#修改安装目录--prefix=/home/mysql/dbproxy
Vim bootstrap.sh
#!/bin/sh
base=$ (CD "$ (dirname") "; pwd)
CD $base
Pkg_config_path=/usr/local/lib/pkgconfig./configure--with-mysql=/usr--prefix=/home/mysql/dbproxy CFLAGS= "-DHAVE _lua_h-o2 "ldflags="-lm-ldl-lcrypto-ljemalloc "lua_cflags="-i/usr/local/include/"lua_libs="-l/usr/local/lib-llua "
#用惯了, before we installed Dbproxy in/home/mysql/dbproxy, accustomed to
./bootstrap.sh
Make && make install
#编译过程中, if there is a problem, see Config.log recorded information, generally jemalloc not installed, low version, libffi*,glib-2.32, and other library version is low or not installed problems.
Four. Configuration
1. Configure the Stop script Mysql-proxyd
Vim/home/mysql/dbproxy/bin/mysql-proxyd
Modify Proxydir=/usr/local/mysql-proxy to Proxydir=/home/mysql/dbproxy
#或者 sed-i ' s%proxydir=/usr/local/mysql-proxy%proxydir=/home/mysql/dbproxy%g '/home/mysql/dbproxy/bin/mysql-proxyd
2. Modify the configuration file, the suffix name must be. CNF, if you do not want to use. CNF, you can also change mysql-proxyd this script
Vim/home/mysql/dbproxy/conf/dbproxy.cnf
[Mysql-proxy]
Admin-username = user
Admin-password = pwd
Admin-address = 0.0.0.0:2345
Proxy-backend-addresses = 192.168.0.220:9858
Proxy-read-only-backend-addresses = 192.168.1.221:9858,192.168.0.14:9858
PWDs = Dbproxy_longxibendi_w:/izxz+0groa=,dbproxy_longxibendi_r:/izxz+0groa=
Daemon = True
KeepAlive = True
Event-threads = 4
Log-level = Message
Log-path =/home/mysql/dbproxy/log
Sql-log = On
Sql-log-slow = 10
Wait-timeout = 10
Proxy-address = 0.0.0.0:12340
charset = UTF8
Client-ips = 127.0.0.1, 192.168.1,192.168.0.220,192.168.1.221
Add an account on 3.mysql,slave
master:192.168.0.220
slave:192,168.1.221,192.168.0.14
Master on: Mysql-uroot-p-h127.0.0.1-p5858
Mysql-> Grant Select,update,delete,insert on longxibendi.* to [e-mail protected] identified by ' 123456 ';
Slave, same authorization, note IP address is dbproxy address
Five. Start
1. Start Dbproxy
Cd/home/mysql/dbproxy/bin
./mysql-proxyd Dbproxy Start
2. Access Testing
mysql-udbproxy_longxibendi_w-h192.168.0.220-p123456-p10240
mysql-> show databases;
#可以测试下事务, read/write separation, main library downtime, failover from library downtime, and more.
#最后感谢 Web platform Related team
Compile and install Dbproxy Altas