1.vim redis-cluster-6391.conf
bind 0.0.0.0
daemonize yes
protected-mode no
port 6391
logfile "/opt/homebrew/var/db/redis/logs/redis-cluster_6391.log"
pidfile "/var/run/redis-cluster_6391.pid"
dir "/opt/homebrew/var/db/redis"
dbfilename cluster_dump_6391.rdb
appendonly yes
appendfilename "appendonly6391.aof"
requiredpass 111111
masterauth 111111
cluster-enabled yes
cluster-config-file nodes-6391.conf
cluster-node-timeout 5000
wq 保存
2. cp redis-cluster-6391.conf redis-cluster-6392.conf
将6391 改为6392
依此 再
cp redis-cluster-6391.conf redis-cluster-6393.conf
cp redis-cluster-6391.conf redis-cluster-6394.conf
cp redis-cluster-6391.conf redis-cluster-6395.conf
cp redis-cluster-6391.conf redis-cluster-6396.conf
3.启动服务
redis-server redis-cluster-6391
redis-server redis-cluster-6392
redis-server redis-cluster-6393
redis-server redis-cluster-6394
redis-server redis-cluster-6395
redis-server redis-cluster-6395
通过redis-cli为6个实例构建集群关系
- 构建主从
redis-cli -a 111111 --cluster create --cluster-replicas 1 127.0.0.1:6391 127.0.0.1:6392 127.0.0.1:6393 127.0.0.1:6394 127.0.0.1:6395 127.0.0.1:6396
输入yes
同时在我们指定的目录下生成了 nodes-6391conf…nodess-6392.conf文件
到此为止集群成功了
常用命令
- cluster info
- cluster nodes
- info replication