docker镜像创建redis5.0.3容器集群

拉取redis5.0.3镜像

 # docker pull daocloud.io/library/redis:5.0.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost ~]# docker pull daocloud.io/library/redis:5.0.3
5.0.3: Pulling from library/redis
5e6ec7f28fb7: Pull complete
7fdf7fb3ec49: Pull complete
4bd5dbe7bfa7: Pull complete
71f540684935: Pull complete
8c6dbecedd0f: Pull complete
9d190b6684fc: Pull complete
Digest: sha256:e1dc07bf1465661b90b18c1c766c00f733254bf64fcf2ad7a335b2fc1fa31870
Status: Downloaded newer image for daocloud.io/library/redis:5.0.3
[root@localhost ~]#
[root@localhost ~]# docker images
centos                                                 latest              9f38484d220f        2 weeks ago         202MB
daocloud.io/library/redis                              5.0.3               82629e941a38        2 months ago        95MB
ubuntu                                                 16.04               7e87e2b3bf7a        2 months ago        117MB
mysql                                                  latest              102816b1ee7d        3 months ago        486MB

 

 

给redis5.0.3镜像打标签

# docker tag 82629e941a38 redis

删除源镜像标签

# docker rmi daocloud.io/library/redis:5.0.3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
[root@localhost ~]# docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
centos                                                 latest              9f38484d220f        2 weeks ago         202MB
daocloud.io/library/redis                              5.0.3               82629e941a38        2 months ago        95MB
redis                                                  latest              82629e941a38        2 months ago        95MB
ubuntu                                                 16.04               7e87e2b3bf7a        2 months ago        117MB
mysql                                                  latest              102816b1ee7d        3 months ago        486MB
[root@localhost ~]#
[root@localhost ~]# docker rmi daocloud.io/library/redis:5.0.3
Untagged: daocloud.io/library/redis:5.0.3
Untagged: daocloud.io/library/redis@sha256:e1dc07bf1465661b90b18c1c766c00f733254bf64fcf2ad7a335b2fc1fa31870
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY                                             TAG                 IMAGE ID            CREATED             SIZE
centos                                                 latest              9f38484d220f        2 weeks ago         202MB
redis                                                  latest              82629e941a38        2 months ago        95MB
ubuntu                                                 16.04               7e87e2b3bf7a        2 months ago        117MB
mysql                                                  latest              102816b1ee7d        3 months ago        486MB

 

 

创建6个redis容器集群

以redis7000为例:

非集群模式

# docker run --name redis8000 -p 8000:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no 

 

集群模式

# docker run --name redis7000 -p 7000:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes

说明:

redis的密码为123456

Redis持久化功能已启动

保护模式已经关闭

集群模式已开启

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# docker run --name redis7000 -p 7000:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
d8b4eb2b5459b2eaceca1d957b9422123ac906c41a5bf8d23bd65545dda33c77
[root@localhost ~]# docker run --name redis7001 -p 7001:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
163c705af09706b38e2f327febdecbf9c37d3b1528f7d4bfb667eb257d3a0be7
[root@localhost ~]# docker run --name redis7002 -p 7002:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
e4604f44be05811a9dbcf0af9f3f0b6db976dde9c8c2772d8773e6979fbb7284
[root@localhost ~]# docker run --name redis7003 -p 7003:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
a76f43511bb20945695943d009041b2f8398b1e3a5217524edfa34589ad91311
[root@localhost ~]# docker run --name redis7004 -p 7004:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
9eace890c3a44314a01ef58fc0d09086f752be95300165868435b8dfbb1f61b2
[root@localhost ~]# docker run --name redis7005 -p 7005:6379 -d redis redis-server --requirepass "123456" --appendonly yes --protected-mode no --cluster-enabled yes
e91e99f1c31f2deab8f87f0af75625087a2913ff382ef15e62bce2b8d472e60f
[root@localhost ~]#

 

 

查看容器状态

# docker ps

1
2
3
4
5
6
7
8
[root@localhost ~]# docker ps
CONTAINER ID        IMAGE                                                  COMMAND                  CREATED              STATUS              PORTS                    NAMES
e91e99f1c31f        redis                                                  "docker-entrypoint.s…"   6 seconds ago        Up 5 seconds        0.0.0.0:7005->6379/tcp   redis7005
9eace890c3a4        redis                                                  "docker-entrypoint.s…"   16 seconds ago       Up 16 seconds       0.0.0.0:7004->6379/tcp   redis7004
a76f43511bb2        redis                                                  "docker-entrypoint.s…"   32 seconds ago       Up 31 seconds       0.0.0.0:7003->6379/tcp   redis7003
e4604f44be05        redis                                                  "docker-entrypoint.s…"   46 seconds ago       Up 45 seconds       0.0.0.0:7002->6379/tcp   redis7002
163c705af097        redis                                                  "docker-entrypoint.s…"   56 seconds ago       Up 56 seconds       0.0.0.0:7001->6379/tcp   redis7001
d8b4eb2b5459        redis                                                  "docker-entrypoint.s…"   About a minute ago   Up About a minute   0.0.0.0:7000->6379/tcp   redis7000

 

 

查看6个redis容器的IP

# docker inspect redis7000 | grep IPAddress

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
[root@localhost ~]# docker inspect redis7000 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.6",
                    "IPAddress": "172.17.0.6",
[root@localhost ~]#
[root@localhost ~]# docker inspect redis7001 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.8",
                    "IPAddress": "172.17.0.8",
[root@localhost ~]#
[root@localhost ~]# docker inspect redis7002 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.9",
                    "IPAddress": "172.17.0.9",
[root@localhost ~]#
[root@localhost ~]# docker inspect redis7003 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.10",
                    "IPAddress": "172.17.0.10",
[root@localhost ~]# docker inspect redis7004 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.11",
                    "IPAddress": "172.17.0.11",
[root@localhost ~]#
[root@localhost ~]# docker inspect redis7005 | grep IPAddress
            "SecondaryIPAddresses": null,
            "IPAddress": "172.17.0.12",
                    "IPAddress": "172.17.0.12",
[root@localhost ~]#

 

 

进入redis7000容器

# docker exec -it redis7000 bash

客户端交互

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost ~]# docker exec -it redis7000 bash
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli
127.0.0.1:6379> exit
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -h 172.17.0.6 -p 6379
172.17.0.6:6379>
172.17.0.6:6379> exit
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -h 172.17.0.8 -p 6379
172.17.0.8:6379>
172.17.0.8:6379> exit
root@d8b4eb2b5459:/data#

 

 

集群创建

# redis-cli -a 123456 --cluster create 172.17.0.6:6379 172.17.0.8:6379 172.17.0.9:6379 172.17.0.10:6379 172.17.0.11:6379 172.17.0.12:6379 --cluster-replicas 1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -a 123456 --cluster create 172.17.0.6:6379 172.17.0.8:6379 172.17.0.9:6379 172.17.0.10:6379 172.17.0.11:6379 172.17.0.12:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 172.17.0.10:6379 to 172.17.0.6:6379
Adding replica 172.17.0.11:6379 to 172.17.0.8:6379
Adding replica 172.17.0.12:6379 to 172.17.0.9:6379
M: 19519487a7db6f2fa5fda5f6e1807befe75665e5 172.17.0.6:6379
   slots:[0-5460] (5461 slots) master
M: f6adb618124c791db4e31347982d086cd8b58646 172.17.0.8:6379
   slots:[5461-10922] (5462 slots) master
M: 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf 172.17.0.9:6379
   slots:[10923-16383] (5461 slots) master
S: ca40bc6c36c7c14a7e91b04bec51bc6bb75eebea 172.17.0.10:6379
   replicates 19519487a7db6f2fa5fda5f6e1807befe75665e5
S: b25431b20840b04fc2262d246482981a1a49c1cf 172.17.0.11:6379
   replicates f6adb618124c791db4e31347982d086cd8b58646
S: 53515a889f77bbe553c8fb664983cded5d767826 172.17.0.12:6379
   replicates 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf
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 172.17.0.6:6379)
M: 19519487a7db6f2fa5fda5f6e1807befe75665e5 172.17.0.6:6379
   slots:[0-5460] (5461 slots) master
additional replica(s)
M: 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf 172.17.0.9:6379
   slots:[10923-16383] (5461 slots) master
additional replica(s)
S: b25431b20840b04fc2262d246482981a1a49c1cf 172.17.0.11:6379
   slots: (0 slots) slave
   replicates f6adb618124c791db4e31347982d086cd8b58646
S: 53515a889f77bbe553c8fb664983cded5d767826 172.17.0.12:6379
   slots: (0 slots) slave
   replicates 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf
M: f6adb618124c791db4e31347982d086cd8b58646 172.17.0.8:6379
   slots:[5461-10922] (5462 slots) master
additional replica(s)
S: ca40bc6c36c7c14a7e91b04bec51bc6bb75eebea 172.17.0.10:6379
   slots: (0 slots) slave
   replicates 19519487a7db6f2fa5fda5f6e1807befe75665e5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
root@d8b4eb2b5459:/data#

 

 

1
配置文件启动redis方式<br>docker run -d --name redis_test -p 6379:6379  -v /var/local/conf/redis.conf:/redis.conf redis redis-server /redis.conf

 

posted @   割肉机  阅读(1347)  评论(0编辑  收藏  举报
编辑推荐:
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 震惊!C++程序真的从main开始吗?99%的程序员都答错了
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
历史上的今天:
2018-07-17 Istio官方文档中文版
2018-07-17 Service Mesh服务网格新生代--Istio(转)
2018-07-17 Spring-data-jpa详解,全方位介绍。
点击右上角即可分享
微信分享提示