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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章