Redis5官方自带集群脚本create-cluster(三主三从)

本文介绍了在CentOS 7环境下,如何利用Redis5官方提供的create-cluster脚本,无需Ruby环境,快速搭建三主三从的Redis集群。详细步骤包括下载安装Redis,了解脚本使用方式,修改start、create和stop部分的脚本,以及启动集群、创建集群和查看集群信息的过程。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.下载并安装redis

环境:centos 7

$ wget http://download.redis.io/releases/redis-5.0.5.tar.gz
$ tar xzf redis-5.0.5.tar.gz
$ cd redis-5.0.5
$ make

2.快速搭建脚本

2.1 官方提供

redis 5.0版本集群搭建不需要我们安装ruby就可以搭建成功,而且redis安装包内utils/create-cluster/ 目录下给我们提供了快速搭建脚本,目录结构如下图:
在这里插入图片描述

2.2 README

使用方式通过阅读README文件内容可以得知,内容如下:
$ cat utils/create-cluster/README

Create-custer is a small script used to easily start a big number of Redis
instances configured to run in cluster mode. Its main goal is to allow manual
testing in a condition which is not easy to replicate with the Redis cluster
unit tests, for example when a lot of instances are needed in order to trigger
a given bug.

The tool can also be used just to easily create a number of instances in a
Redis Cluster in order to experiment a bit with the system.

USAGE
---

To create a cluster, follow these steps:

1. Edit create-cluster and change the start / end port, depending on the
number of instances you want to create.
2. Use "./create-cluster start" in order to run the instances.
3. Use "./create-cluster create" in order to execute redis-cli --cluster create, so that
an actual Redis cluster will be created.
4. Now you are ready to play with the cluster. AOF files and logs for each instances are created in the current directory.

In order to stop a cluster:

1. Use "./create-cluster stop" to stop all the instances. After you stopped the instances you can use "./create-cluster start" to restart them if you change your mind.
2. Use "./create-cluster clean" to remove all the AOF / log files to restart with a clean environment.

Use the command "./create-cluster help" to get the full list of features.

2.3 create-cluster

执行utils/create-cluster/ 目录下的create-cluster脚本,就可以快速搭建,脚本内容如下:
$ cat utils/create-cluster/create-cluster

#!/bin/bash

# Settings
PORT=30000  #起始端口
TIMEOUT=2000  #超时时间
NODES=6  #总节点数
REPLICAS=1  #每个主节点有几个从节点,0为无从节点

# You may want to put the above config parameters into config.sh in order to
# override the defaults without modifying this script.

if [ -a config.sh ]
then
    source "config.sh"
fi

# Computed vars
ENDPORT=$((PORT+NODES))

if [ "$1" == "start" ]
then
    while [ $((PORT < ENDPORT)) != "0" ]; do
        PORT=$((PORT+1))
        echo "Starting $PORT"
        ../../src/redis-server --port $PORT --cluster-enabled yes --cluster-config-file nodes-${
   PORT}.conf --cluster-node-timeout $TIMEOUT --appendonly yes --appendfilename appendonly-${
   PORT}.aof --dbfilename dump-${
   PORT}.rdb --logfile ${
   PORT}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值