MySQL Proxy LUA安装和使用教程是本文要介绍的内容,主要是来了解MySQL Proxy LUA的学习技巧,具体内容来看本文详解。
按照手册安装MySQL Proxy之前先要安装以下软件
- libevent1.xorhigher(1.3borlaterispreferred)
- lua5.1.xorhigher
- glib22.6.0orhigher
- pkg-config
- libtool1.5orhigher
- MySQL5.0.xorhigherdeveloperfiles
- rpm查看libevent
- rpm-qlibevent
- libevent-1.1a-3.2.1
勉强用吧,家下来安装lua
- tarxvzflua-5.1.4.tar.gz
- cdlua-5.1.4
- makelinux
- makeinstall
- cpetc/lua.pc/usr/local/lib/pkgconfig/
之后安装MySQLProxy按转世继续报错,呵呵,虽然手册上对于glib2写的版本是2.6.0及以后实际在MySQLProxy0.7.2上是要求>2.16的,继续升级glib2
- tarxvzfglib-2.23.0.tar.gz
- cdglib-2.23.0
- ./configure
- make
- makeinstall
然后提示安装libevent版本过低,晕了
- tarxvzflibevent-1.4.13-stable.tar.gz
- cdlibevent-1.4.13-stable
- ./configure
- make
- makeinstall
这次再去安装MySQLProxy
- tarzxfmysql-proxy-0.7.2.tar.gz
- cdmysql-proxy-0.7.2
- ./configurewith-mysql=/usr/local/mysql/bin/mysql_configwith-lua
- make
- makeinstall
默认的mysql-proxy被安装到/usr/local/sbin/mysql-proxy而lua实例脚本则在/usr/local/share/doc下(不过好像需要之前maketest才有,不确定).
查看下MySQLProxy的版本
mysql-proxy-V
mysql-proxy:errorwhileloadingsharedlibraries:/usr/local/lib/libmysql-chassis.so.0:cannotrestoresegmentprotafterreloc:Permissiondenied
报错,这是SELinux的问题,可如下解决
- chcon-ttexrel_shlib_t/usr/local/lib/libmysql-chassis.so.0
- mysql-proxy-V
- mysql-proxy0.7.2
- glib2:2.23.0
- libevent:1.4.13-stable
- lua:Lua5.1.4
- LUA_PATH:/usr/local/lib/mysql-proxy/lua/?.lua
- LUA_CPATH:/usr/local/lib/mysql-proxy/lua/?.so
- 2009-12-1800:05:34:(warning)g_set_prgname()calledmultipletimes
- ==plugins==
- admin:0.7.0
- proxy:0.7.0
至此MySQLProxy安装完成,记住LUA_PATH:/usr/local/lib/mysql-proxy/lua/?.lua下面要用到
启动,编译启动脚本,
- vi/etc/init.d/mysql-proxy
- #!/bin/sh
- exportLUA_PATH=/usr/local/lib/mysql-proxy/lua/?.lua
- mode=1
- if[-z"mode"];then
- mode="start"
- fi
- casemodein
- 'start')
- mysql-proxydaemon/
- 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')
- killallmysql-proxy
- ;;
- 'restart')
- if0stop;then
- 0start
- else
- echo"retartfailed!!!"
- exit1
- fi
- ;;
- esac
- exit0
现在解释一下启动脚本:
- daemon采用daemon方式启动
- admin-address=:4401指定mysqlproxy的管理端口,在这里,表示本机的4401端口
- proxy-address=:3307指定mysqlproxy的监听端口,也可以用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脚本也可以下下来修改使用
- wgethttp://customcode.googlecode.com/files/mysql-proxy
完整的参数可以运行以下命令查看:
- mysql-proxyhelp-all
之后可以通过以下命令启动|停止|重启
- /etc/init.d/mysql-proxystart
- /etc/init.d/mysql-proxystop
- /etc/init.d/mysql-proxyrestart
居然提示权限不够,不过简单
- chmod+x/etc/init.d/mysql-proxy
这样该ok了把,可能会报错类似于:
- /etc/init.d/mysql-proxystart
- 2009-12-1801:59:52:(warning)g_set_prgname()calledmultipletimes
- 2009-12-1801:59:52:(critical)chassis.c:981:couldnotraiseRLIMIT_NOFILEto8192,Invalidargument(22).Currentlimitstill13815894353589044224.
这个一个警告级别的错误,意思是MySQLProxy在你的系统上不能把openfileslimit提升到8192,不过没关系的,MySQLProxy依然好好的运行在你的电脑上.
- mysql-h127.0.0.1-uroot-p-P3307
- Enterpassword:
- WelcometotheMySQLmonitor.Commandsendwith;or/g.
- YourMySQLconnectionidis6
- Serverversion:5.1.40-blang-debug-logSourcedistribution
- Type'help;'or'/h'forhelp.Type'/c'toclearthecurrentinputstatement.
可以看到,产生了一个新连接。
小结:MySQL Proxy LUA安装和使用教程的内容介绍完了,希望通过本文的学习能对你有所帮助!