Redis-Cluster集群部署

一、环境要求

  • gcc

二、安装

文档参考:https://blog.csdn.net/miss1181248983/article/details/90056960

1、部署规划

c1 port c2 port c3 port
192.168.139.12 6379 192.168.139.15 6379 192.168.139.16 6379
192.168.139.15 6380 192.168.139.16 6380 192.168.139.12 6380

2、redis-5.0.7的安装

2.1、安装
# 安装所需依赖
# yum install gcc-c++ automake autoconf libtool make -y
# yum install -y gcc*

# 下载所需安装包
# wget http://download.redis.io/releases/redis-5.0.7.tar.gz

# 解压编译安装
# tar xzf redis-5.0.7.tar.gz
# cd redis-5.0.7
# make -j 4 && make install PREFIX=/app_server/redis

# 新建相关目录
# cd /app_server/redis
# mkdir {data,conf,logs}
# mkdir data/{redis_6379,redis_6380}
2.2、配置文件
2.2.1、redis_6379
# egrep -v "*#|^$" conf/redis_6379.conf
bind 192.168.139.12
protected-mode yes
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile "/app_server/redis/logs/redis_6379.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/app_server/redis/data/redis_6379"
masterauth gicloud
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass gicloud
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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_6379.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
2.2.2、redis_6380
# egrep -v "*#|^$" conf/redis_6380.conf
bind 192.168.139.12
protected-mode yes
port 6380
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize yes
supervised no
pidfile /var/run/redis_6380.pid
loglevel notice
logfile "/app_server/redis/logs/redis_6380.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/app_server/redis/data/redis_6380"
masterauth gicloud
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
requirepass gicloud
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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_6380.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

其他服务器配置一致。修改对应ip即可。

2.2.3、启动
# redis-server conf/redis_6379.conf
# redis-server conf/redis_6380.conf
2.3、创建集群
# redis-cli -a gicloud --cluster create 192.168.139.12:6379 192.168.139.15:6379 192.168.139.16:6379 192.168.139.15:6380 192.168.139.16:6380 192.168.139.12:6380 --cluster-replicas 1

>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.139.15:6380 to 192.168.139.12:6379
Adding replica 192.168.139.16:6380 to 192.168.139.15:6379
Adding replica 192.168.139.12:6380 to 192.168.139.16:6379
M: 0f9feb435f47296864f4388b7caa971956059259 192.168.139.12:6379
   slots:[0-5460] (5461 slots) master
M: 9a6fb2eab1b7701868d8f71822bed1e7f8ca5669 192.168.139.15:6379
   slots:[5461-10922] (5462 slots) master
M: 45413e9733222b9a3338f9da239c3485c9ac1b5e 192.168.139.16:6379
   slots:[10923-16383] (5461 slots) master
S: 2b7bfbb8777e5eb3b80d6ddc481318034c6c8c47 192.168.139.15:6380
   replicates 0f9feb435f47296864f4388b7caa971956059259
S: 9e146b09716f22b56b89d8286ccd05c565519499 192.168.139.16:6380
   replicates 9a6fb2eab1b7701868d8f71822bed1e7f8ca5669
S: ec22f49945266ced1a497532686121b669a23a01 192.168.139.12:6380
   replicates 45413e9733222b9a3338f9da239c3485c9ac1b5e
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
..
>>> Performing Cluster Check (using node 192.168.139.12:6379)
M: 0f9feb435f47296864f4388b7caa971956059259 192.168.139.12:6379
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 9a6fb2eab1b7701868d8f71822bed1e7f8ca5669 192.168.139.15:6379
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 9e146b09716f22b56b89d8286ccd05c565519499 192.168.139.16:6380
   slots: (0 slots) slave
   replicates 9a6fb2eab1b7701868d8f71822bed1e7f8ca5669
M: 45413e9733222b9a3338f9da239c3485c9ac1b5e 192.168.139.16:6379
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: ec22f49945266ced1a497532686121b669a23a01 192.168.139.12:6380
   slots: (0 slots) slave
   replicates 45413e9733222b9a3338f9da239c3485c9ac1b5e
S: 2b7bfbb8777e5eb3b80d6ddc481318034c6c8c47 192.168.139.15:6380
   slots: (0 slots) slave
   replicates 0f9feb435f47296864f4388b7caa971956059259
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
2.4、基础操作
2.4.1、登录
# redis-cli -c -h 192.168.139.12 -p 6379 -a gicloud
192.168.139.12:6379> CLUSTER INFO                   #集群状态
192.168.139.12:6379> CLUSTER NODES                  #列出节点信息
2.4.2、集群增加节点
# 复制相关配置文件
# 例如192.168.139.12 6381
192.168.139.12:6379> CLUSTER MEET 192.168.139.12 6381
192.168.139.12:6379> CLUSTER NODES
# 可以看到新加的节点以master身份加入
2.4.3、更换节点身份
# 例如上面新加的节点
192.168.139.12:6379> cluster replicate e51ab166bc0f33026887bcf8eba0dff3d5b0bf14
192.168.139.12:6379> CLUSTER NODES
2.4.4、删除节点
192.168.139.12:6379> CLUSTER FORGET 1a1c7f02fce87530bd5abdfc98df1cffce4f1767
2.4.5、保存配置
192.168.139.12:6379> CLUSTER SAVECONFIG

你可能感兴趣的:(Redis-Cluster集群部署)