Simple configuration of Mysql database read/write splitting

Source: Internet
Author: User

Simple configuration environment for Mysql database read/write Splitting:

Master:192.168.71.128      mysql-sql-node1Slave:192.168.71.140       mysql-data-node1Mysql-Proxy:192.168.71.138 mysql-mgm-noderpm -q libevent glib2 pkgconfig libtool mysql-devel
Check whether the above package has been installed. If not, use yum install.
yum install -y libtermcap-devel ncurses-devel libevent-devel readline-devel gcc-c++

 

1. Download the program:
wget http://www.lua.org/ftp/lua-5.1.4.tar.gzwget http://gd.tuwien.ac.at/db/mysql/Downloads/MySQL-Proxy/mysql-proxy-0.6.0.tar.gzwget http://www.monkey.org/~provos/libevent-1.4.13-stable.tar.gz

 

Ii. Install lua:
[Root @ mailtest/software] # tar zxvf lua-5.1.4.tar.gz [root @ mailtest lua-5.1.4] # cd lua-5.1.4 [root @ mailtest lua-5.1.4] # vi Makefile modification: INSTALL_TOP =/usr/local/lua [root @ mailtest lua-5.1.4] # make & make linux & make install set environment variables [root @ mailtest lua-5.1.4] # export LUA_CFLAGS = "-I /usr/local/lua/include "LUA_LIBS ="-L/usr/local/lua/lib-llua-ldl "LDFLAGS ="-L/usr/local/libevent/lib -lm "[root @ mailtest lua-5.1.4] # export CPPFLAGS ="-I/usr/local/libevent/include "[root @ mailtest lua-5.1.4] # export CFLAGS ="-I/usr /local/libevent/include"

 

3. Install libevent:
tar zvxf libevent-1.4.13-stable.tar.gzcd libevent-1.4.13-stable./configure --prefix=/usr/local/libeventmake && make install

 

4. Install mysql-proxy:
. /Configure -- prefix =/usr/local/mysql-proxy -- with-mysql =/usr/local/mysql -- with-luamake & make install start: /usr/local/mysql-proxy/sbin/mysql-proxy -- proxy-read-only-backend-addresses = 192.168.71.140: 3306 -- proxy-backend-addresses = 192.168.71.128: 3306 -- proxy-lua-script =/usr/local/mysql-proxy/share/mysql-proxy/rw-splitting.lua & view process: netstat-ntlp | grep mysql edit STARTUP script: vi/etc/init. d/mysql-proxy #! /Bin/bashPRODIR =/usr/local/mysql-proxyLUA_PATH = $ PRODIR/share/mysql-proxystart () {$ PRODIR/sbin/mysql-proxy -- proxy-read-only-backend-addresses = 192.168.71.140: 3306 -- proxy-backend-addresses = 192.168.71.128: 3306 -- proxy-lua-script =/usr/local/mysql-proxy/share/mysql-proxy/rw-splitting.lua & >$ PRODIR/mysql-proxy.log &} stop () {kill $ (pidof mysql-proxy) if [$? -Ne 0]; thenkill-9 $ (pidof mysql-proxy) fi} case "$1" instart) start; stop) stop; restart) stopstart ;;*) echo $ "Usage: $0 {start | stop | restart}" esac modification permission: chmod + x/etc/init. d/mysql-proxy/etc/init. d/mysql-proxy start test: Create a test database and user on MySQL-Master. Mysql> create database unixhot; mysql> grant all privileges on king. * to proxytest @ '%' identified by 'bo365'; connection test [root @ MySQL-Proxy ~] # Mysql-h 192.168.71.138-P 4040-u proxytest-p enter the password to log on. Mysql> show processlist; + ---- + ----------- + ---------------------- + ------ + --------- + ------ + ------- + ------------------ + | Id | User | Host | db | Command | Time | State | Info | + ---- + ----------- + hour ---------------------- + ------ + --------- + ------ + ------- + ---------------- + | 14 | proxytest | 192.168.71.138: 17350 | NULL | Sleep | 2 | NULL | 15 | proxytest | 192.168.71.138: 17355 | NULL | Query | 0 | NULL | show processlist | 16 | proxytest | 192.168.71.138: 17358 | NULL | Sleep | 2 | NULL | + ---- + ----------- + -------------------- + ------ + --------- + ------ + ------- + -------------------- + 3 rows in set (0.01 sec)

 


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.