MySQL Proxy安装和使用(一)

按照手册安装MySQL Proxy之前先要安装以下软件

libevent 1.x or higher (1.3b or later is preferred)

lua 5.1.x or higher

glib2 2.6.0 or higher

pkg-config

libtool 1.5 or higher

MySQL 5.0.x or higher developer files

rpm查看libevent

$rpm -q libevent
libevent-1.1a-3.2.1

勉强用吧,家下来安装lua

$tar xvzf lua-5.1.4.tar.gz

$cd lua-5.1.4

$make linux

$make install

$cp etc/lua.pc /usr/local/lib/pkgconfig/

之后安装MySQL Proxy按转世继续报错,呵呵,虽然手册上对于glib2写的版本是2.6.0及以后实际在MySQL Proxy0.7.2上是要求>2.16的,继续升级glib2

$tar xvzf glib-2.23.0.tar.gz

$cd glib-2.23.0

$./configure

$make

$make install

然后提示安装libevent版本过低,晕了

$tar xvzf libevent-1.4.13-stable.tar.gz

$cd libevent-1.4.13-stable

$./configure

$make

$make install

这次再去安装MySQL Proxy

$tar zxf mysql-proxy-0.7.2.tar.gz

$cd mysql-proxy-0.7.2

$./configure --with-mysql=/usr/local/mysql/bin/mysql_config --with-lua

$make

$make install

默认的mysql-proxy 被安装到/usr/local/sbin/mysql-proxy而lua实例脚本则在/usr/local/share/doc下(不过好像需要之前make test才有,不确定).

查看下MySQL Proxy的版本

$mysql-proxy -V
mysql-proxy: error while loading shared libraries: /usr/local/lib/libmysql-chassis.so.0: cannot restore segment prot after reloc: Permission denied

报错,这是SELinux的问题,可如下解决

$chcon -t texrel_shlib_t /usr/local/lib/libmysql-chassis.so.0

$ mysql-proxy -V
mysql-proxy 0.7.2
  glib2: 2.23.0
  libevent: 1.4.13-stable
  lua: Lua 5.1.4
    LUA_PATH: /usr/local/lib/mysql-proxy/lua/?.lua
    LUA_CPATH: /usr/local/lib/mysql-proxy/lua/?.so
2009-12-18 00:05:34: (warning) g_set_prgname() called multiple times
  == plugins ==
  admin: 0.7.0
  proxy: 0.7.0

至此MySQL Proxy安装完成,记住LUA_PATH: /usr/local/lib/mysql-proxy/lua/?.lua下面要用到

启动,编译启动脚本,

$vi /etc/init.d/mysql-proxy

#!/bin/sh
export LUA_PATH=/usr/local/lib/mysql-proxy/lua/?.lua

mode=$1
if [ -z "$mode" ] ; then
  mode="start"
fi

case $mode in
  'start')
    mysql-proxy --daemon /
--admin-address=:4401 /
--proxy-address=:3307 /
--proxy-backend-addresses=:3306 /
--proxy-read-only-backend-addresses=192.168.133.232:3306 /
--proxy-read-only-backend-addresses=10.10.74.61:3306 /
--proxy-lua-script=/usr/local/share/doc/mysql-proxy/rw-splitting.lua
    ;;

  'stop')
    killall mysql-proxy
    ;;

  'restart')
    if $0 stop ; then
      $0 start
    else
      echo  "retart failed!!!"
      exit 1
    fi
    ;;
esac
exit 0

现在解释一下启动脚本:
--daemon 采用daemon方式启动
--admin-address=:4401 指定mysql proxy的管理端口,在这里,表示本机的4401端口
--proxy-address=:3307 指定mysql proxy的监听端口,也可以用 127.0.0.1:3307 表示
--proxy-backend-addresses=:3306 指定mysql主机的端口
--proxy-read-only-backend-addresses=192.168.1.1:3306 指定只读的mysql主机端口
--proxy-read-only-backend-addresses=192.168.1.2:3306 指定另一个只读的mysql主机端口
--proxy-lua-script=/usr/local/share/mysql-proxy/rw-splitting.lua 指定lua脚本,在这里,使用的是rw-splitting脚本,用于读写分离

(以上脚本内容摘自叶金荣blog)

googlecode上也有mysql-proxy脚本也可以下下来修改使用

$wget http://customcode.googlecode.com/files/mysql-proxy

完整的参数可以运行以下命令查看:

$mysql-proxy --help-all

之后可以通过以下命令启动|停止|重启

$ /etc/init.d/mysql-proxy start

$ /etc/init.d/mysql-proxy stop

$ /etc/init.d/mysql-proxy restart

居然提示权限不够,不过简单

$chmod +x /etc/init.d/mysql-proxy

这样该ok了把,可能会报错类似于:

/etc/init.d/mysql-proxy start
2009-12-18 01:59:52: (warning) g_set_prgname() called multiple times
2009-12-18 01:59:52: (critical) chassis.c:981: could not raise RLIMIT_NOFILE to 8192, Invalid argument (22). Current limit still 13815894353589044224.

这个一个警告级别的错误,意思是MySQL Proxy在你的系统上不能把open files limit提升到8192,不过没关系的,MySQL Proxy依然好好的运行在你的电脑上.

$mysql -h127.0.0.1 -uroot -p -P3307
Enter password:
Welcome to the MySQL monitor.  Commands end with ; or /g.
Your MySQL connection id is 6
Server version: 5.1.40-blang-debug-log Source distribution

Type 'help;' or '/h' for help. Type '/c' to clear the current input statement.

mysql> show processlist;
+----+------+----------------+------+---------+------+-------+------------------+
| Id | User | Host           | db   | Command | Time | State | Info             |
+----+------+----------------+------+---------+------+-------+------------------+
|  6 | root | localhost:3688 | NULL | Query   |    0 | NULL  | show processlist |
+----+------+----------------+------+---------+------+-------+------------------+
1 row in set (0.09 sec)

可以看到,产生了一个新连接。

你可能感兴趣的:(mysql)