因爲工做須要想搭建個mysql讀寫分離環境,上網看了不少人寫的博客都說如今讀寫分離還不是很成熟,若是流量太大估計不大好。node
mysql-proxy:10.1.1.6
mysql寫:10.1.1.4
mysql讀:10.1.1.5mysql
mysql-proxy機子上:linux
安裝mysql
tar zxvf mysql-5.1.36.tar.gz
cd mysql-5.1.36
./configure --prefix=/usr/local/mysql
make && make install
安裝readline
產看:$rpm -qa | grep readline
沒有的話yum----
安裝LUA
#tar zxvf lua-5.1.4.tar.gz
#cd lua-5.1.4
#vi Makefile #修改安裝路徑爲: INSTALL_TOP= /usr/local/lua
#make linux installsql
安裝 libevent
tar zxvf libevent-1.4.14b-stable.tar.gz
cd libevent-1.4.14b-stable
./configure --prefix=/usr/local/libevent
make
make installvim
編譯安裝glib-2.24.2.tar.gz
本人原來版本是2.12,過低了,須要升級才能安裝,後來安裝了glib2.8,但編譯時候提示2.12>2.8 ???很奇怪,後來安裝了2.24就能夠了。
#rpm -e --nodeps glib2 強制刪除原來的GLIB2
# cd glib-2.24.2
# ./configure --prefix=/usrapp
在安裝glib新的版本的過程當中,還可能會遇到這樣的問題:
gconvert.c:48:2: error: #error GNU libiconv not in use but included iconv.h is from libiconvide
#./configure --prefix=/usr -enable-iconv=no -with-libiconv=gnu 加入此參數順利編譯
# make&make installoop
安裝mysql-proxy測試
設置環境變量.
vim/etc/profile
export LUA_CFLAGS="-I/usr/local/lua/include" LUA_LIBS="-L/usr/local/lua/lib -llua -ldl" LDFLAGS="-L/usr/local/libevent/lib -lm"
export CPPFLAGS="-I/usr/local/libevent/include"
export CFLAGS="-I/usr/local/libevent/include"
export PKG_CONFIG_PATH=/usr/lib/pkgconfiglua
運行
#source /etc/profile
不然要關閉SHELL才能生效
#tar zxvf mysql-proxy-0.8.1.tar.gz
#cd mysql-proxy-0.8.1
#./configure --prefix=/usr/local/mysql-proxy --with-mysql=/usr/local/mysql --with-lua
# make
# make install
或:(其實和上面同樣)
---------------------------------------------
#tar zxvf mysql-proxy-0.8.1.tar.gz
#cd mysql-proxy-0.8.1
#env LUA_CFLAGS='-I/usr/local/lua/include'
LUA_LIBS='-L/usr/local/lua/lib -llua -ldl' \
CFLAGS='-I/usr/local/include' \
LDFLAGS='-L/usr/local/lib -lm' \
PKG_CONFIG_PATH=/usr/local/lib/pkgconfig \
./configure \
-prefix=/usr/local/mysql-proxy \
-with-mysql=/usr/local/mysql \
-with-lua
----------------------------------------------
#vi /etc/profile
#export PATH=$PATH:/usr/local/mysql-proxy/bin
#source /etc/profile
安裝完畢
啓動mysql-proxy
#/usr/local/mysql-proxy/bin/mysql-proxy --daemon --admin-username=root --admin-password=123456 --proxy-read-only-backend-addresses=10.1.1.5:3306 --proxy-backend-addresses=10.1.1.4:3306 --max-open-files=1024 --proxy-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua --admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
個人默認路徑找不到rw-splitting.lua 因此從其餘地方找了一個,mysql-proxy如今不少人不敢用在生產環境其實就是就個腳本跟不上. 附件是個人腳本,拷到 /usr/local/mysql-proxy/share/doc/mysql-proxy/ 下
–daemon:指定mysql-proxy爲一個daemon
–keepalive:mysql-proxy有時候會自動中止服務的狀況,加上此參數後就解決這個問題
–admin-username:指定MySQL Proxy管理者端(port:4041)的登入賬號
–admin-password:指定MySQL Proxy管理者端(port:4041)的登入密碼
–proxy-backend-addresses:指定寫mysql的位置及端口
–proxy-read-only-backend:指定讀mydql的位置及端口,有多臺讀mysql時,在後面加多一條參數 -proxy–read-only-backend XXXXXX.XXX.xx.xx:3306就能夠了
–log-file:指定儲存MySQL Proxy log的檔案位置
–log-level:指定要記錄log的等級
–max-open-files:指定最大檔案開啓數爲1024,不然爲有【could not raise RLIMIT_NOFILE to 8192, Invalid
argument (22). Current limit still 1024.】的log訊息出現
–proxy-lua-script:指定MySQL Proxy要套用那一個script
官網提供的啓動腳本:http://forge.mysql.com/wiki/MySQL_Proxy_init
啓動遇到的問題:
(critical) admin-plugin.c:579: --admin-lua-script needs to be set, <install-dir>/lib/mysql-
proxy/lua/admin.lua may be a good value
2010-11-30 19:29:12: (critical) mainloop.c:267: applying config of plugin admin failed
2010-11-30 19:29:12: (critical) mysql-proxy-cli.c:596: Failure from chassis_mainloop. Shutting down.
啓動加入:--admin-lua-script=/usr/local/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
could not raise RLIMIT_NOFILE to 8192, Invalid argument (22). Current limit still 1024
啓動加入:--max-open-files=1024
------------------------------------------- - 測 試- -----------------------------
vim /usr/src/mysql-proxy/share/doc/mysql-proxy/rw-splitting.lua
在client端登入 mysql -ualex -p123 -h 10.1.1.6 -P 4040
insert into ....
而後進入:10.1.1.4 看看是否增長了,
select 剛剛增長記錄的表,發現沒有增長記錄,說明查詢只能查到10.1.1.5
好了。最後將寫mysql 和 讀mysql作成A-B 主從複製。。。。。。。。。
----------------------------------------------------------------------------------------------------
完