Redis的代理(Twemproxy)

Twemproxy是Twitter开源的Redis代理,借助其可实现稳定的Redis分布式方案,相对于官方较新的Redis Cluster架构,容量伸缩较麻烦。



安装比较简单,注意可能会遇到autoconf版本低的问题。


安装依赖库

# yum install autoconf libtool -y


下载最新版本

https://github.com/twitter/twemproxy/releases


编译安装twemproxy

# tar zxf twemproxy-0.4.1.tar.gz

# cd twemproxy-0.4.1


遇到autoconf版本低的报错

# autoreconf -fvi

...

configure.ac:8: error: Autoconf version 2.64 or higher is required


下载较高版本的autoconf

http://ftp.gnu.org/gnu/autoconf/autoconf-2.69.tar.gz


编译安装autoconf,并覆盖低版本文件

# ./configure

# make

# make install


# cp /usr/local/bin/autoconf /usr/bin/

# cp /usr/local/bin/autoreconf /usr/bin/


重新安装

# autoreconf -fvi

# ./configure --prefix=/usr/local/twemproxy

# make

# make install



twemproxy的重要特性

1. Maintains persistent server connections.

2. Keeps connection count on the backend caching servers low.

3. Enables pipelining of requests and responses.

4. Supports multiple server pools simultaneously.

5. Observability via stats exposed on the stats monitoring port.

6. Supports multiple hashing modes including consistent hashing and distribution.



配置文件,其中端口6379和6389为2个Redis实例。

$ cat kp.conf 

kp:

  listen: 127.0.0.1:7379

  hash: fnv1a_64

  distribution: ketama

  timeout: 100

  auto_eject_hosts: true

  server_retry_timeout: 2000

  server_failure_limit: 2

  redis: true

  redis_auth: abcdefg

  servers:

   - 127.0.0.1:6379:1

   - 127.0.0.1:6389:1


启动twemproxy

# nutcracker --daemonize --verbose=11 --output=nut.log --conf-file=kp.conf --stats-port=22222 --pid-file=nut.pid


登陆twemproxy

$ redis-cli -p 7379 -a abcdefg

127.0.0.1:7379> get hello

"redis"

127.0.0.1:7379> set twe proxy

OK

127.0.0.1:7379> dbsize

Error: Server closed the connection


获取twemproxy状态

$ curl -GET http://127.0.0.1:22222

{"service":"nutcracker", "source":"51", "version":"0.4.1", "uptime":22766, 

...

}


若感兴趣可关注订阅号”数据库最佳实践”(DBBestPractice).

qrcode_for_gh_54ffa7e55478_258.jpg

猜你喜欢

转载自blog.51cto.com/coveringindex/2152799