条件:3台主机(也可以1台3实例),redis大版本:5(3、4不太一样)
- 下载安装(提前装好gcc)
wget http://download.redis.io/releases/redis-5.0.3.tar.gz
tar redis-5.0.3.tar.gz -C /usr/local/
cd /usr/local/
mv redis-5.0.3/ redis
cd redis/
make
- 配置
vim redis.conf
port 6379(自定义)
bind 10.168.1.166(ip)
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
- 启动3个实例
src/redis-server redis.conf
- 创建集群
再打开一个shell
./redis-cli --cluster create 10.168.1.164:6379 10.168.1.165:6379 10.168.1.166:6379
>>> Performing Cluster Check (using node 10.168.1.164:6379)
M: 4ae32b62955874bbd3df846031155e70b59d6668 10.168.1.164:6379
slots:[0-5460] (5461 slots) master
M: 2adf5ca3cb4d915d1025d61bcb4aa7e1b7c1ede3 10.168.1.166:6379
slots:[10923-16383] (5461 slots) master
M: 5573a15ce40d4a80b304902c902c0b32dbda60f8 10.168.1.165:6379
slots:[5461-10922] (5462 slots) master
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
看到以上基本就成了
5. 测试
登入一个客户端
./redis-cli -h 10.168.1.164 -p 6379 -c
10.168.1.165:6379> set k1 v1
-> Redirected to slot [12706] located at 10.168.1.166:6379
OK
10.168.1.166:6379> set k2 v2
-> Redirected to slot [449] located at 10.168.1.164:6379
OK
10.168.1.164:6379> set k3 v3
OK
10.168.1.164:6379> get k1
-> Redirected to slot [12706] located at 10.168.1.166:6379
"v1"
10.168.1.166:6379> get k2
-> Redirected to slot [449] located at 10.168.1.164:6379
"v2"
更多详情请见