twemproxy,又名nutcracker,作为一个小巧的redis和memcache的开源代理工具而存在,当某些主机不能直接通信,或者需要把若干redis服务合成一个ip地址来用的时候,它便有了用武之地。
安装也很简单,详细见:https://github.com/twitter/twemproxy
Twemproxy can be configured through a YAML file specified by the -c or --conf-file command-line argument on process start.
配置文件小例:
alpha:
listen: 127.0.0.1:22121
hash: fnv1a_64
distribution: ketama
auto_eject_hosts: true
redis: true
server_retry_timeout: 2000
server_failure_limit: 1
servers:
- 127.0.0.1:6379:1
其中
listen: 127.0.0.1:22121
Use 0.0.0.0
on the listen
command to tell twemproxy to listen on all available network interfaces on the server. This mean twemproxy will try to listen on:
- the loopback address 127.0.0.1 (localhost),
- on your private IP (i.e. 192.168.0.1) and
- on your public IP (i.e. 134.xxx.50.34)
当使用node_redis连接twemproxy的时候,node_redis默认会向redis服务端发送“info”
信息来确认server状态是否是ready
,而twemproxy是不支持的,所以要在连接redis的时候添加一个参数
no_ready_check: true
。