redis代理集群(Twemproxy)(1)
redis主從+哨兵模式只解決了讀的分布式操作,大大提高了性能;但是寫操作,只有主主機器才能進行,從機器無法進行寫操作。此時,Twemproxy也就出現了。
這個模式單純的安裝有些復雜,需要引入很多的輔助工具:
autoconf:下載地址 http://ftp.gnu.org/gnu/autoconf/
Automake :下載地址http://ftp.gnu.org/gnu/automake/
libtool:下載地址 http://ftp.gnu.org/gnu/libtool/
twemproxy下載地址:https://codeload.github.com/twitter/twemproxy/zip/master
記住,都要高版本的,版本太舊,容易出問題》
安裝步驟,我是根據尚學堂視頻進行操作的,大體流程如下:
這裏的安裝目錄都在usr目錄下,這樣可以偷懶不配置環境變量,如果更改安裝目錄,那你自己去配置環境變量,我這裏找到一篇微博,此人是自己配置環境變量的,
可以參考 : http://blog.csdn.net/kk185800961/article/details/53364334
接下來我將逐步分解過程:
1、首先將安裝好的壓縮包全部上傳到linux服務器,我這裏有3臺虛擬機,redis服務分別部署在這3臺不同的虛擬機上面(如果不會,請參考我的《Redis的安裝、服務配置》一文);
而twemproxy代理我僅僅部署在CentOS1(192.168.238.128)上面,文件傳輸路徑為/home/tool/sourceDir目錄下,並解壓
安裝是要有先後順序的,依次安裝autoconf、autoMake、libtool、twemproxy-master;
進入/home/tool/sourceDir目錄下,分別開始安裝:
安裝autoconf:
[[email protected] autoconf-2.69]# cd autoconf-2.69 [[email protected] autoconf-2.69]# ./configure --prefix=/usr [[email protected] autoconf-2.69]# make && make install
安裝automake:
[[email protected] automake-1.15.1]# cd automake-1.15.1 [[email protected] automake-1.15.1]# ./configure --prefix=/usr [root@serverautomake-1.15.1]# make && make install
安裝libtool:
[[email protected] libtool-2.4.5]# cd libtool-2.4.5 [[email protected] libtool-2.4.5]# ./configure --prefix=/usr [[email protected] libtool-2.4.5]# make && make install
安裝twemproxy:
[[email protected] twemproxy-master]# cd twemproxy [[email protected] twemproxy-master]# aclocal [[email protected] twemproxy-master]# autoconf [[email protected] twemproxy-master]# mkdir config [[email protected] twemproxy-master]# autoheader [[email protected] twemproxy-master]# libtoolize [[email protected] twemproxy-master]# automake -a [[email protected] twemproxy-master]# ./configure [[email protected] twemproxy-master]# make [[email protected] twemproxy-master]# make install
# 配置文件 nutcracker.yml(我的都是真實IP)(註意:此文件必須要找到安裝目錄下的nutcracker命令,放在此命令同目錄的conf文件夾下)
具體配置信息:
alpha:
listen: 192.168.238.128:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
redis: true
server_retry_timeout: 2000
server_failure_limit: 1
servers:
- 192.168.238.128:6379:1
- 192.168.238.131:6379:1
- 192.168.238.132:6379:1
測試配置文件:
首先需要將redis的服務全部啟動,然後啟動twemproxy
接下來進入代理模式中:
OK,配置完成,接下來可以進行你需要的操作了。
再來說說問題:
問題實在太多了,舉幾個最容易發現的問題吧。
1、在代理中,keys * 不可執行
2、對字符串操作,當CentOS1、CentOS3、CentOS4之前就有相同的key時候,通過代理拿到的值永遠都是本機的(CentOS1),其余的拿不到
3、對無序集合也是一樣的,CentOS4的值是:
CentOS3的值是:
通過代理拿到的值,不知道怎麽回事,一直都是CentOS4裏面的,CentOS3的值一直拿不到,搞不懂是什麽原理
以上說的情況,都是redis服務之前就有這些鍵值情況下出現的,如果全部通過Twemproxy進行設置,然後在通過Twemproxy進行拿值,是不會出現這樣的問題的。
還是一點也很要命,通過Twemproxy設置的值,各個redis服務是不同步的,只要某一臺redis服務宕機了,裏面的數據也就拿不到了。
當然,以上問題,肯定是有解決辦法的,以後會繼續學習和完善這些問題。
redis代理集群(Twemproxy)(1)