Redis Cluster 解決了分片與高可用,但獨立的多個 Redis Cluster 之間無法共享資料。業務增長導致建立多個獨立集群時,客戶端需維護多組連線資訊,複雜度大增。Twemproxy (又稱 Nutcracker) 作為輕量級 Redis 代理層,採用一致性哈希分發請求,對客戶端呈現單一入口,完美解決多集群統一接入問題。
OS: RedHat 6.3 | 需自行編譯安裝較新版本的建構工具:
# 1. 移除系統舊版 autoconf
yum remove autoconf
# 2. 依序編譯安裝建構工具
tar -xf autoconf-2.69.tar.gz
cd autoconf-2.69 && ./configure && make && make install
tar -xf automake-1.12.1.tar.gz
cd automake-1.12.1 && ./configure && make && make install
tar -xf libtool-2.2.4.tar.gz
cd libtool-2.2.4 && ./configure && make && make install
# 3. 安裝 Twemproxy
unzip twemproxy-master.zip
cd twemproxy-master
autoreconf -ivf # 關鍵步驟:生成 configure 腳本
./configure
make && make install
| 錯誤訊息 | 原因 | 解決方法 |
|---|---|---|
./configure: command not found | 未執行 autoreconf | 先執行 autoreconf -ivf |
Can't exec "automake": No such file | 缺少 automake | 安裝 automake 後再執行 autoreconf |
undefined macro: AC_PROG_LIBTOOL | 缺少 libtool | 安裝 libtool 後再執行 autoreconf |
alpha:
listen: 0.0.0.0:22121
hash: fnv1a_64
hash_tag: "{}"
distribution: ketama
auto_eject_hosts: true
redis: true
servers:
- 192.168.1.10:6379:1 server1
- 192.168.1.11:6379:1 server2
- 192.168.1.12:6379:1 server3
nutcracker -d -c nutcracker.yml -o nutcracker.log -v 11
# -d: 背景執行, -c: 設定檔, -o: 日誌, -v: 詳細度
# 驗證連線
redis-cli -p 22121 info
:22222) 獲取即時統計client_connections、server_retry_timeout 等參數