1、Redis版本
[root@wsdhla ~]# redis-server -v
Redis server v=6.2.6 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=bf23dac15dfc00fa
[root@wsdhla ~]# redis-cli -v
redis-cli 6.2.6
2、创建节点目录
创建6个节点目录,分别复制一份redis.conf并编辑:
redis-node1/redis.conf
bind 0.0.0.0 -::1
port 6381
dir /opt/redis-node1
pidfile /var/run/redis_6381.pid
masterauth 密码
cluster-enabled yes
cluster-config-file /opt/redis-node1/nodes-6381.conf
cluster-announce-ip 本机IP
# cluster-announce-tls-port 6379
cluster-announce-port 6381
# cluster-announce-bus-port 6380
# 可选,后台运行
daemonize yes
redis-node2/redis.conf
bind 0.0.0.0 -::1
port 6382
dir /opt/redis-node2
pidfile /var/run/redis_6382.pid
masterauth 密码
cluster-enabled yes
cluster-config-file /opt/redis-node1/nodes-6382.conf
cluster-announce-ip 本机IP
# cluster-announce-tls-port 6379
cluster-announce-port 6382
# cluster-announce-bus-port 6380
# 可选,后台运行
daemonize yes
redis-node3/redis.conf
bind 0.0.0.0 -::1
port 6383
dir /opt/redis-node3
pidfile /var/run/redis_6383.pid
masterauth 密码
cluster-enabled yes
cluster-config-file /opt/redis-node1/nodes-6383.conf
cluster-announce-ip 本机IP
# cluster-announce-tls-port 6379
cluster-announce-port 6383
# cluster-announce-bus-port 6380
# 可选,后台运行
daemonize yes
3、启动节点服务
分别启动6个节点服务脚本
redis-cluster-node1.sh
#!/bin/bash
exec nohup redis-server /opt/redis-node1/redis.conf > ./redis-node1.out 2>&1 &
tail -f ./redis-node1.out
redis-cluster-node2.sh
#!/bin/bash
exec nohup redis-server /opt/redis-node2/redis.conf > ./redis-node2.out 2>&1 &
tail -f ./redis-node2.out
redis-cluster-node3.sh
#!/bin/bash
exec nohup redis-server /opt/redis-node3/redis.conf > ./redis-node3.out 2>&1 &
tail -f ./redis-node3.out
4、创建集群
redis-cli -a 密码 --cluster create 本机IP:6381 本机IP:6382 本机IP:6383 本机IP:6384 本机IP:6385 本机IP:6386 --cluster-replicas 1