參考資料:https://redis.io/topics/cluster-tutorial
1. 編譯Redis,配置環境
a. 編譯Redis:
cd src
make install
b. 配置環境
apt-get install ruby
apt-get install rubygems
gem install redis
2. 單機配置集羣(192.168.44.130:8001,192.168.44.130:8001,192.168.44.130:8001)
a. 配置redis.conf
bind 192.168.44.130 ##對外IP地址
port 8001 ##訪問端口
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
b. 創建集羣
I. 啓動各節點
II. 創建集羣:redis-trib.rb create 192.168.44.130:8001 192.168.44.130:8002 192.168.44.130:8003
III. 查看集羣詳情:redis-cli -c -p 8001 -h 192.168.44.130 CLUSTER NODES
3. 多機配置集羣
a. 另一臺機器配置一臺redis服務器(同上)
b. 添加從節點:redis-trib.rb add-node --slave 192.168.44.128:8004 192.168.44.130:8001
c. 其他常用命令:
redis-trib.rb check 192.168.44.130:8001 ##檢查節點
redis-cli -c -h 192.168.44.130 -p 8001 shutdown ##停止節點
redis-trib.rb del-node 192.168.44.130 ID ##刪除集羣節點