Mysql读写分离Mysql-Proxy配置



CentOS
+------------+
| version()  |
内存:512
+------------+
6.0 |   
+------------+




1、配置ip
#Vi/etc/sysconfig/network-scripts/ifcfg-th0
  IPADDR=192.168.1.80
  NETMASK=255.255.255.0
  GATEWAY=192.168.1.1
  TYPE=Ethernet
  ONBOOT=yes


2、配置DNS上网
  #Vi/etc/resolv.conf
   nameserver192.168.1.1


3、下载安装包
  # yum-y install gcc gcc-c++ autoconf mysql-devel libtool pkgconfig ncursesncurses-devel make gettext
  # reboot


MySql Proxy配置脚本
libevent安装: (root)
#tar –libevent-2.0.15-stable.tar.gz–C /usr/local
#cd /usr/local
#mv libevent-2.0.15-stable libevent
#cd /usr/local/ libevent
# ./configure  
# make
# make install


Glib2安装:
glib2安装glib-2.18.4版本,最新版本安装报错,从此处可以下载:
http://ftp.gnome.org/pub/gnome/sources/glib/2.18/glib-2.18.4.tar.gz
运行脚本:
# tar xvf glib-2.18.4.tar.gz
# cd glib-2.18.4
# ./configure
# make
# make install


Readline安装
# tar xvf readline-6.1.tar.gz   
# cd readline-6.1
# ./configure
# make && make install
#应用ldconfig –v
# ldconfig –v


Lua安装: (root)
(安装之前需要先安装readline6.1,不然会报错缺少头文件)
#tar –zxvf lua-5.2.0.tar.gz –C /usr/local
#cd /usr/local
#mv lualua-5.2.0 lua
#cd /usr/local/lua
#vi Makefile,修改INSTALL_TOP= /usr/local/lua
#在CFLAGS里加上-fPIC,因为我在64位机上编译出现了“relocations”错误
#make PLATFORM   
#makegeneric (如果编译不通过有可能是gcc编译器没安装)
#makeinstall
#重要:让pkg-config找到自己编译的库在哪里
#export PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig


Mysql Proxy安装: (root)
#tar –mysql-proxy-0.8.2.tar.gz –C /usr/local
#cd /usr/local
#mv mysql-proxy-0.8.2 mysql-proxy
#cd /usr/local/mysql-proxy
#./autogen.sh
#./configure
# make

make check

# make install


# exportPATH=$PATH:/usr/local/mysql/mysql-proxy/sbin/


# tar –vxzf mysql-proxy-0.8.2-linux-rhel5-x86-64bit.tar.gz–C /usr/local
# cd /usr/local
# mv mysql-proxy-0.8.2-linux-rhel5-x86-64bit mysql-proxy
# cd /usr/local/mysql-proxy


# vim ~/.bash_profile  
PATH=$PATH:$HOME/bin:/usr/local/mysql-proxy/bin  
export PATH
     # wget -c http://customcode.googlecode.com/files/mysql-proxy
      # cp mysql-proxy  /etc/init.d/mysql-proxy


# vim /etc/init.d/mysql-proxy
   PROXY_PATH=/usr/local/mysql-proxy/bin
   :set fileformat=unix


# exportPATH=$PATH:/usr/local/mysql/mysql-proxy/sbin/
# chmod 755 /etc/init.d/mysql-proxy   
# chkconfig mysql-proxy on
# vi /etc/sysconfig/mysql-proxy
     # options to mysql-proxy   
     # do not remove --daemon   
     PROXY_OPTIONS=
     "--proxy-read-only-backend-addresses=192.168.1.103:3306
     --proxy-backend-addresses=192.168.1.60:3306  
     --proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua&"




#cp /usr/local/mysql-proxy/bin/mysql-proxy/usr/local/sbin  
#/etc/init.d/mysql-proxy start
#/etc/init.d/iptables stop    (一定要关闭防火墙)




修改lua配置参数
修改读写分离lua脚本

默认最小4个最大8个以上的客户端连接才会实现读写分离, 现改为最小1个最大2个:

# vi  /usr/local/Mysql Proxy/share/doc/MysqlProxy/rw-splitting.lua  

         connection pool  

        if not proxy.global.config.rwsplit then  

               proxy.global.config.rwsplit = {  

                       min_idle_connections = 1,  

                       max_idle_connections = 2,  

                       is_debug = true   

                }        

        end



标签: linux, mysql

相关文章

评论已关闭