twemproxy
安装
1. 获取安装包
shell> wget http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz
shell> wget https://codeload.github.com/twitter/twemproxy/zip/master
#twemproxy要求autoconf的版本在2.64以上
2. 编译安装
shell> unzip ./twemproxy-master.zip shell> tar -zxvf ./autoconf-2.69.tar.gz shell> cd ./autoconf-2.69 shell> ./configure --prefix=/usr/ shell> make && make install
shell> /usr/bin/autoconf -V
autoconf (GNU Autoconf) 2.69
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+/Autoconf: GNU GPL version 3 or later
<http://gnu.org/licenses/gpl.html>, <http://gnu.org/licenses/exceptions.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Written by David J. MacKenzie and Akim Demaille.
shell> cd twemproxy-master shell> autoreconf -fvi
shell> configure.ac:36: error: possibly undefined macro: AC_PROG_LIBTOOL
If this token and others are legitimate, please use m4_pattern_allow.
See the Autoconf documentation. shell> yum -y install libtool
shell> autoreconf -fvi
shell> ./configure --prefix=/usr/local/twemproxy shell> make -j `grep processor /proc/cpuinfo | wc -l` shell> make install
3.增加配置文件
shell> cd /usr/local/twemproxy shell> cat > /usr/local/twemproxy/nutcracker.yml << EOF memcache: listen: 0.0.0.0: hash: fnv1a_64 distribution: ketama auto_eject_hosts: true redis: false timeout: server_retry_timeout: server_failure_limit: servers: - 172.18.18.52:: - 172.18.18.53:: - 127.18.3.11:: - 172.18.3.12:: #- 172.18.3.4:: #- 172.18.3.7:: EOF
4. 启动服务
shell> vi /etc/sysconfig/iptables shell> -A INPUT -m state --state NEW -m tcp -p tcp --dport -j ACCEPT #开放防火墙端口11210 shell> /etc/init.d/iptables restart shell> nutcracker -t #测试配置文件 shell> /usr/local/twemproxy/sbin/nutcracker -d -c /usr/local/twemproxy/nutcracker.yml #指定配置文件启动
5.启动命令详解
Usage: nutcracker [-?hVdDt] [-v verbosity level] [-o output file]
[-c conf file] [-s stats port] [-a stats addr]
[-i stats interval] [-p pid file] [-m mbuf size]
参数 | 释义 |
---|---|
-h, –help | 查看帮助文档,显示命令选项 |
-V, –version | 查看nutcracker版本 |
-t, –test-conf | 测试配置脚本的正确性 |
-d, –daemonize | 以守护进程运行 |
-D, –describe-stats | 打印状态描述 |
-v, –verbosity=N | 设置日志级别 (default: 5, min: 0, max: 11) |
-o, –output=S | 设置日志输出路径,默认为标准错误输出 (default: stderr) |
-c, –conf-file=S | 指定配置文件路径 (default: conf/nutcracker.yml) |
-s, –stats-port=N | 设置状态监控端口,默认22222 (default: 22222) |
-a, –stats-addr=S | 设置状态监控IP,默认0.0.0.0 (default: 0.0.0.0) |
-i, –stats-interval=N | 设置状态聚合间隔 (default: 30000 msec) |
-p, –pid-file=S | 指定进程pid文件路径,默认关闭 (default: off) |
-m, –mbuf-size=N | 设置mbuf块大小,以bytes单位 (default: 16384 bytes) |
Twemproxy是一种代理分片机制,由Twitter开源。Twemproxy作为代理,可接受来自多个程序的访问,按照路由规则,转发给后台的各个Redis服务器,再原路返回。