Redis5.0集群搭建

Redis集群教程

此文重在介绍 Redis5.0 三主三从集群安装,无复杂难懂的概念,若想深入了解集群原理请参考Redis集群规范

Redis集群介绍

Redis Cluster 提供一种 Redis 安装方式:数据自动在多个 Redis 节点间分片。

Redis Cluster 提供一定程度的高可用,在实际的环境中当某些节点失败或者不能通讯的情况下能够继续提供服务。大量节点失败的情况下集群也会停止服务(例如大多数主节点不可用)。

Redis集群提供的能力:

  • 自动切分数据集到多个节点上;
  • 当部分节点故障或不可达的情况下继续提供服务;

Redis集群目录创建编译及端口分配

# 创建 redis 集群安装目录
$ mkdir redis5.0.14-cluster
$ cd redis5.0.14-cluster
# 下载 redis5.0.14 源码
$ wget --no-check-certificate  https://download.redis.io/releases/redis-5.0.14.tar.gz
# 解压 redis5.0.14 源码包
$ tar -xvf redis-5.0.14.tar.gz
# 进入 redis5.0.14 目录
$ cd redis-5.0.14
# 编译并安装
$ make && make install
# 集群根目录下创建集群节点目录
$ cd .. && mkdir 7000 7001 7002 7003 7004 7005

分别在 7000 … 7005 目录下创建 redis.conf 文件,修改对应的 port、pidfile、dir 并拷贝到对应的目录下

################################## NETWORK #####################################
bind 0.0.0.0
protected-mode no
# 修改
port 7005
tcp-backlog 511
timeout 6000
tcp-keepalive 300

################################# GENERAL #####################################
daemonize yes
supervised no
# 修改
pidfile /root/redis5.0.14-cluster/7005/redis_7005.pid
loglevel notice
logfile ""
databases 16
always-show-logo yes

################################ SNAPSHOTTING  ################################
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
# 修改 - 工作目录
dir /root/redis5.0.14-cluster/7005/

################################# REPLICATION #################################
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

############################# LAZY FREEING ####################################
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

############################## APPEND ONLY MODE ###############################
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 SCRIPTING  ###############################
lua-time-limit 5000

########################## CLUSTER DOCKER/NAT support  ########################
slowlog-log-slower-than 10000
slowlog-max-len 128

################################ LATENCY MONITOR ##############################
latency-monitor-threshold 0

############################# EVENT NOTIFICATION ##############################
notify-keyspace-events ""

############################### ADVANCED CONFIG ###############################
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

分别启动Redis节点

$ cd redis-5.0.14/src
$ ./redis-server ../../7000/redis.conf
$ ./redis-server ../../7001/redis.conf
$ ./redis-server ../../7002/redis.conf
$ ./redis-server ../../7003/redis.conf
$ ./redis-server ../../7004/redis.conf
$ ./redis-server ../../7005/redis.conf

在这里插入图片描述

构建集群

$ redis-cli --cluster create  192.168.19.128:7000 192.168.19.128:7001 192.168.19.128:7002 192.168.19.128:7003 192.168.19.128:7004 192.168.19.128:7005 --cluster-replicas 1 -a 123456


  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值