提前准备 redis-6.2.6.tar.gz
3台linux服务器
1.节点1服务器操作
apt update
apt install make
cd /data
tar -xf redis-6.2.6.tar.gz
cd redis-6.2.6
make
make install
mkdir /data/redis-6.2.6-cluster/{bin,conf,data,var,logs} -p
cp /data/redis-6.2.6/src/redis-benchmark /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-check-aof /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-check-rdb /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-cli /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-sentinel /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-server /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/src/redis-trib.rb /data/redis-6.2.6-cluster/bin/
cp /data/redis-6.2.6/redis.conf /data/redis-6.2.6-cluster/conf/
cd /data/redis-6.2.6-cluster/conf/
cp redis.conf redis.conf.defaults
mv redis.conf redis_6701.conf
vim redis_6701.conf
==============================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6701 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6701.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6701.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6701.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6701.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
=============================================================
cp redis_6701.conf redis_6702.conf
vim redis_6702.conf
=============================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6702 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6702.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6702.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6702.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6702.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
=================================================================
spc -r /data/redis-6.2.6-cluster root@节点2IP:/data
spc -r /data/redis-6.2.6-cluster root@节点3IP:/data
2.以下操作节点服务器2操作
cd /data/redis-6.2.6-cluster/conf
mv redis_6701.conf redis_6703.conf
vim redis_6703.conf
=================================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6703 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6703.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6703.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6703.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6703.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
=============================================================
mv redis_6702.conf redis_6704.conf
vim redis_6704.conf
=============================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6704 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6704.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6704.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6704.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6704.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
=================================================================
3.以下操作节点服务器3操作
cd /data/redis-6.2.6-cluster/conf
mv redis_6701.conf redis_6705.conf
vim redis_6705.conf
==================================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6705 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6705.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6705.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6705.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6705.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
====================================================================
mv redis_6702.conf redis_6706.conf
vim redis_6706.conf
====================================================================
bind 0.0.0.0
maxmemory 14848mb
maxmemory-policy allkeys-lru
protected-mode no
port 6706 #注意修改此处
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
pidfile /data/redis-6.2.6-cluster/var/redis_6706.pid #注意修改此处
loglevel notice
logfile /data/redis-6.2.6-cluster/logs/redis_6706.log #注意修改此处
databases 16
always-show-logo yes
set-proc-title yes
proc-title-template "{title} {listen-addr} {server-mode}"
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename redis_6706.rdb #注意修改此处
rdb-del-sync-files no
dir /data/redis-6.2.6-cluster/data
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-diskless-load disabled
repl-disable-tcp-nodelay no
replica-priority 100
acllog-max-len 128
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
lazyfree-lazy-user-del no
lazyfree-lazy-user-flush no
oom-score-adj no
oom-score-adj-values 0 200 800
disable-thp yes
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes_6706.conf #注意修改此处
cluster-node-timeout 15000
slowlog-log-slower-than 10000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
hll-sparse-max-bytes 3000
stream-node-max-bytes 4096
stream-node-max-entries 100
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit replica 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
dynamic-hz yes
aof-rewrite-incremental-fsync yes
rdb-save-incremental-fsync yes
jemalloc-bg-thread yes
masterauth "集群密码"
requirepass "节点密码"
==================================================================
在3台服务器上启动redis服务
节点服务器1:
cd /data/redis-6.2.6-cluster
./bin/redis-server ./conf/redis_6701.conf
./bin/redis-server ./conf/redis_6702.conf
节点服务器2:
cd /data/redis-6.2.6-cluster
./bin/redis-server ./conf/redis_6703.conf
./bin/redis-server ./conf/redis_6704.conf
节点服务器3:
cd /data/redis-6.2.6-cluster
./bin/redis-server ./conf/redis_6705.conf
./bin/redis-server ./conf/redis_6706.conf
启动完成后查看对应端口是否启动
netstat -nutlp | grep 6701 #注意替换端口号
====================================================================
返回节点1服务器创建集群
cd /data/redis-6.2.6-cluster
./bin/redis-cli --cluster create --cluster-replicas 1 节点服务器1IP:6701 节点服务器1IP:6702 节点服务器2IP:6703 节点服务器2IP:6704 节点服务器3IP:6705 节点服务器3IP:6706 -a '集群密码'
./bin/redis-cli -h 节点服务器1IP -p 6701 -a '节点密码' -c
cluster info #可查看集群状态
cluster nodes #查看各节点状态
##################
我这边配置文件目前采用的内存淘汰策略为
allkeys-lru
#从所有键中移除最近最少使用的键(Least Recently Used)。这种策略对所有键都有效,无论是否设置了过期时间。
除了我设置的这个还有其他几种策略 大家可根据自己的实际情况在配置文件中进行更改。
noeviction:当内存超过限制时,不再处理写请求,会返回错误。这种策略会确保数据不会被无意间删除,但可能导致写操作失败。
volatile-lru:仅从设置了过期时间的键中移除最近最少使用的键。
allkeys-random:从所有键中随机移除键。
volatile-random:仅从设置了过期时间的键中随机移除键。
volatile-ttl:从设置了过期时间的键中移除即将要过期的键(剩余时间最短)。
volatile-lfu:仅从设置了过期时间的键中移除最不常使用的键(Least Frequently Used)。
allkeys-lfu:从所有键中移除最不常使用的键。
#####################
另外我的配置文件中内存的最大使用限制为 maxmemory 14848mb 既14.5G,实际需要根据自己服务器内存的大小进行配置。