準備如下包:
autoconf下載地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
twemproxy下載地址:https://codeload.github.com/twitter/twemproxy/zip/master
twemproxy的安裝要求autoconf的版本在2.64以上,否則提示”error:Autoconf version 2.64 or higher is required“。autoconf直接make和make install即可。
Git下載地址:https://github.com/git/git
1.安裝autoconf
#autoconf下載地址:http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz,上傳包至服務器目錄/home/zhq
cd /home/zhuhaiquan
tar zxvf autoconf-2.69.tar.gz
cd autoconf-2.69
./configure
make
make install
2.安裝git
#首先需要安裝git的依賴包,如果是centos 6以上直接yum install git就ok
yum install curl curl-devel zlib-devel openssl-develperl tcl cpio expat-devel gettext-devel-y
#下載最新的git包
cd /home/zhq
unzip git-master
autoconf
./configure
make && make install
3.安裝automake
#下載最新的automake包,上傳包至服務器目錄
cd /home/zhq
tar automake-1.9.tar.gz
cd automake-1.9
./configure
make && make install
4.安裝libtool
#下載最新的libtool-2.4.6.tar包,上傳包至服務器目錄
cd /home/zhq
tar libtool-2.4.6.tar.gz
cd libtool-2.4.6
./configure
make && make install
5.安裝twemproxy(安裝之前先安裝automake和libtool)
下載最新的twemproxy包,上傳包至服務器目錄
cd /home/zhq
unzip twemproxy-master.zip
cd twemproxy-master
autoreconf -fvi
執行時報錯:
Can't exec "aclocal": No suchfile or directory at /usr/local/share/autoconf/Autom4te/FileUtils.pm line 326.
解決方法:
方法:`aclocal' is part of automake package, tryto install it first.
所以,下載了automake之後,編譯、安裝,在執行就正常了
安裝完automake之後執行 autoreconf -fvi ,報如下錯誤:
解決方法:安裝libtool包即可
./configure
make && make install
輸入src/nutcracker-h 在命令行可以顯示幫助信息,那麼就證明安裝成功
修改配置文件
src/nutcracker -h
mkdir -p /usr/local/nutcracker/bin
mkdir -p /usr/local/nutcracker/conf
cp src/nutcracker /usr/local/nutcracker/bin
cp conf/* /usr/local/nutcracker/conf
vi/usr/local/nutcracker/conf/nutcracker.yml #添加proxy配置文件
redis:
listen: 192.168.189.128:22111
hash: fnv1a_64
distribution: ketama
redis: true
auto_eject_hosts: true
server_retry_timeout: 300000000
server_failure_limit: 0
servers:
-192.168.189.128:6379:1
-192.168.189.129:6379:1
#備註:
hash: crc32a # crc32a表示算法
auto_eject_hosts: true #是否在結點無法響應的時候臨時摘除結點
server_retry_timeout: 300000000 #故障後多久需重連
server_failure_limit: 3 #結點故障多少次就算摘除掉
啓動twemproxy服務:
#測試配置文件 -c
/usr/local/nutcracker/bin/nutcracker -t -c/usr/local/nutcracker/conf/nutcracker.yml
#後臺啓動 -d
/usr/local/nutcracker/bin/nutcracker -d -c/usr/local/nutcracker/conf/nutcracker.yml
測試:
#往代理緩存192.168.1.149的11211端口輸入一個鍵值key1 爲 123
[root@nginxloader nutcracker]# telnet192.168.1.149 11211
Trying 192.168.1.149...
Connected to 192.168.1.149 (192.168.1.149).
Escape character is ‘^]‘.
set key1 0 3600 3
123
STORED