创建 6 个节点的配置文件
[root@redis3_0_7 config]# cd /opt/soft/redis/config
[root@redis3_0_7 config]# vi redis-7000.conf
port 7000
daemonize yes
dir "/opt/soft/redis/data"
logfile "7000.log"
dbfilename "dump-7000.rdb"
cluster-enabled yes
cluster-config-file nodes-7000.conf
cluster-require-full-coverage no
[root@redis3_0_7 config]# sed "s/7000/7001/g" redis-7000.conf > redis-7001.conf
[root@redis3_0_7 config]# sed "s/7000/7002/g" redis-7000.conf > redis-7002.conf
[root@redis3_0_7 config]# sed "s/7000/7003/g" redis-7000.conf > redis-7003.conf
[root@redis3_0_7 config]# sed "s/7000/7004/g" redis-7000.conf > redis-7004.conf
[root@redis3_0_7 config]# sed "s/7000/7005/g" redis-7000.conf > redis-7005.conf
启动 6 个节点
[root@redis3_0_7 config]# redis-server redis-7000.conf
[root@redis3_0_7 config]# redis-server redis-7001.conf
[root@redis3_0_7 config]# redis-server redis-7002.conf
[root@redis3_0_7 config]# redis-server redis-7003.conf
[root@redis3_0_7 config]# redis-server redis-7004.conf
[root@redis3_0_7 config]# redis-server redis-7005.conf
[root@redis3_0_7 config]# ps -ef|grep redis
root 71 1 0 11:09 ? 00:00:00 redis-server *:7000 [cluster]
root 75 1 0 11:09 ? 00:00:00 redis-server *:7001 [cluster]
root 79 1 0 11:09 ? 00:00:00 redis-server *:7002 [cluster]
root 83 1 0 11:09 ? 00:00:00 redis-server *:7003 [cluster]
root 87 1 0 11:09 ? 00:00:00 redis-server *:7004 [cluster]
root 91 1 0 11:09 ? 00:00:00 redis-server *:7005 [cluster]
root 95 8 0 11:09 pts/1 00:00:00 grep --color=auto redis
尝试向一个节点写数据
- 失败,在集群模式下,16384 个槽都进行了分配,集群才是可用的;
[root@redis3_0_7 config]# redis-cli -p 7000
127.0.0.1:7000> set hello world
(error) CLUSTERDOWN The cluster is down
查看 data 目录下生成的文件
[root@redis3_0_7 data]# ll /opt/soft/redis/data/
total 52
-rw-r--r-- 1 root root 2036 May 14 17:00 6382.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7000.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7001.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7002.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7003.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7004.log
-rw-r--r-- 1 root root 1951 May 18 11:09 7005.log
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7000.conf
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7001.conf
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7002.conf
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7003.conf
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7004.conf
-rw-r--r-- 1 root root 112 May 18 11:09 nodes-7005.conf
查看一个节点的配置文件
[root@redis3_0_7 data]# cat nodes-7000.conf
53be0c4f0ec1275a7fad49ca74c85623c70201da :0 myself,master - 0 0 0 connected
vars currentEpoch 0 lastVoteEpoch 0
连接上 7000 节点查看集群的节点
[root@redis3_0_7 data]# redis-cli -p 7000 cluster nodes
53be0c4f0ec1275a7fad49ca74c85623c70201da :7000 myself,master - 0 0 0 connected
连接上 7000 节点查看集群的信息
[root@redis3_0_7 data]# redis-cli -p 7000 cluster info
cluster_state:fail
cluster_slots_assigned:0
cluster_slots_ok:0
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:1
cluster_size:0
cluster_current_epoch:0
cluster_my_epoch:0
cluster_stats_messages_sent:0
cluster_stats_messages_received:0