> For the complete documentation index, see [llms.txt](https://docker.shujuwajue.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docker.shujuwajue.com/redis-ji-qun/redis-ji-qun-da-jian.md).

# Redis 集群搭建

## 安装Redis镜像

导入本地Redis镜像文件，运行Redis容器

**下载镜像**

```
$ docker pull yyyyttttwwww/redis
```

**宿主机上创建内部网络net2**

```
docker network create –subnet=172.19.0.0/24 net2
```

**运行redis容器**

```
$ docker -it -d --name r1 -p 5001:6379 -net=net2 --ip 172.19.0.2 redis bash
```

**进入容器修改redis配置文件**

```
docker exec -it r1 bash
```

默认是不开启集群模式，配置文件路径`/etc/redis/redis.conf`

![](/files/-LfnTLDRf2biKjIZ7Kaj)

运行redis

```
$ cd /usr/redis/src
$ ./redis-server ../redis.conf
```

相同步骤启动其他5个节点 redis

## 使用redis-trib.rb组件集群

**安装redis-trib.rb**

redis-trib是基于Ruby的Redis集群命令行工具

容器中执行

```
$ cp /usr/redis/src/redis=trib.rb /usr/redis/cluster/
$ cd /usr/redis/cluster
$ apt-get install ruby
$ apt-get intall rubygems
$ gem install redis
```

创建Redis集群

```
#在r1节点上执行下面的指令
$ cd /usr/redis/src
$ mkdir -p ../cluster
$ cp redis-trib.rb ../cluster/
$ cd ../cluster
#创建Cluster集群
$ ./redis-trib.rb create --replicas 1 172.19.0.2:6379 172.19.0.3:6379 172.19.0.4:6379 172.19.0.5:6379 172.19.0.6:6379 172.19.0.7:6379
```

\--replicas 1 参数表示为每个主节点创建一个从节点

> redis 中通过cluster nodes 查看集群状态


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docker.shujuwajue.com/redis-ji-qun/redis-ji-qun-da-jian.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
