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
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 216,324评论 6 498
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 92,356评论 3 392
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 162,328评论 0 353
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 58,147评论 1 292
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 67,160评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 51,115评论 1 296
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,025评论 3 417
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,867评论 0 274
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 45,307评论 1 310
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,528评论 2 332
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,688评论 1 348
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,409评论 5 343
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 41,001评论 3 325
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,657评论 0 22
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,811评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,685评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,573评论 2 353