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

拉取redis5.0.3镜像

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

[root@localhost ~]# docker pull daocloud.io/library/redis:5.0.
5.0.: 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.
[root@localhost ~]#
[root@localhost ~]# docker images
centos latest 9f38484d220f weeks ago 202MB
daocloud.io/library/redis 5.0. 82629e941a38 months ago 95MB
ubuntu 16.04 7e87e2b3bf7a months ago 117MB
mysql latest 102816b1ee7d months ago 486MB

给redis5.0.3镜像打标签

# docker tag 82629e941a38 redis

删除源镜像标签

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

[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f weeks ago 202MB
daocloud.io/library/redis 5.0. 82629e941a38 months ago 95MB
redis latest 82629e941a38 months ago 95MB
ubuntu 16.04 7e87e2b3bf7a months ago 117MB
mysql latest 102816b1ee7d months ago 486MB
[root@localhost ~]#
[root@localhost ~]# docker rmi daocloud.io/library/redis:5.0.
Untagged: daocloud.io/library/redis:5.0.
Untagged: daocloud.io/library/redis@sha256:e1dc07bf1465661b90b18c1c766c00f733254bf64fcf2ad7a335b2fc1fa31870
[root@localhost ~]#
[root@localhost ~]#
[root@localhost ~]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
centos latest 9f38484d220f weeks ago 202MB
redis latest 82629e941a38 months ago 95MB
ubuntu 16.04 7e87e2b3bf7a months ago 117MB
mysql latest 102816b1ee7d months ago 486MB

创建6个redis容器集群

以redis7000为例:

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

说明:

redis的密码为123456

Redis持久化功能已启动

保护模式已经关闭

集群模式已开启

[root@localhost ~]# docker run --name redis7000 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
d8b4eb2b5459b2eaceca1d957b9422123ac906c41a5bf8d23bd65545dda33c77
[root@localhost ~]# docker run --name redis7001 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
163c705af09706b38e2f327febdecbf9c37d3b1528f7d4bfb667eb257d3a0be7
[root@localhost ~]# docker run --name redis7002 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
e4604f44be05811a9dbcf0af9f3f0b6db976dde9c8c2772d8773e6979fbb7284
[root@localhost ~]# docker run --name redis7003 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
a76f43511bb20945695943d009041b2f8398b1e3a5217524edfa34589ad91311
[root@localhost ~]# docker run --name redis7004 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
9eace890c3a44314a01ef58fc0d09086f752be95300165868435b8dfbb1f61b2
[root@localhost ~]# docker run --name redis7005 -p : -d redis redis-server --requirepass "" --appendonly yes --protected-mode no --cluster-enabled yes
e91e99f1c31f2deab8f87f0af75625087a2913ff382ef15e62bce2b8d472e60f
[root@localhost ~]#

查看容器状态

# docker ps

[root@localhost ~]# docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
e91e99f1c31f redis "docker-entrypoint.s…" seconds ago Up seconds 0.0.0.0:->/tcp redis7005
9eace890c3a4 redis "docker-entrypoint.s…" seconds ago Up seconds 0.0.0.0:->/tcp redis7004
a76f43511bb2 redis "docker-entrypoint.s…" seconds ago Up seconds 0.0.0.0:->/tcp redis7003
e4604f44be05 redis "docker-entrypoint.s…" seconds ago Up seconds 0.0.0.0:->/tcp redis7002
163c705af097 redis "docker-entrypoint.s…" seconds ago Up seconds 0.0.0.0:->/tcp redis7001
d8b4eb2b5459 redis "docker-entrypoint.s…" About a minute ago Up About a minute 0.0.0.0:->/tcp redis7000

查看6个redis容器的IP

# docker inspect redis7000 | grep IPAddress

[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

客户端交互

[root@localhost ~]# docker exec -it redis7000 bash
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli
127.0.0.1:> exit
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -h 172.17.0.6 -p
172.17.0.6:>
172.17.0.6:> exit
root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -h 172.17.0.8 -p
172.17.0.8:>
172.17.0.8:> 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

root@d8b4eb2b5459:/data#
root@d8b4eb2b5459:/data# redis-cli -a --cluster create 172.17.0.6: 172.17.0.8: 172.17.0.9: 172.17.0.10: 172.17.0.11: 172.17.0.12: --cluster-replicas
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on nodes...
Master[] -> Slots -
Master[] -> Slots -
Master[] -> Slots -
Adding replica 172.17.0.10: to 172.17.0.6:
Adding replica 172.17.0.11: to 172.17.0.8:
Adding replica 172.17.0.12: to 172.17.0.9:
M: 19519487a7db6f2fa5fda5f6e1807befe75665e5 172.17.0.6:
slots:[-] ( slots) master
M: f6adb618124c791db4e31347982d086cd8b58646 172.17.0.8:
slots:[-] ( slots) master
M: 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf 172.17.0.9:
slots:[-] ( slots) master
S: ca40bc6c36c7c14a7e91b04bec51bc6bb75eebea 172.17.0.10:
replicates 19519487a7db6f2fa5fda5f6e1807befe75665e5
S: b25431b20840b04fc2262d246482981a1a49c1cf 172.17.0.11:
replicates f6adb618124c791db4e31347982d086cd8b58646
S: 53515a889f77bbe553c8fb664983cded5d767826 172.17.0.12:
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:)
M: 19519487a7db6f2fa5fda5f6e1807befe75665e5 172.17.0.6:
slots:[-] ( slots) master
additional replica(s)
M: 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf 172.17.0.9:
slots:[-] ( slots) master
additional replica(s)
S: b25431b20840b04fc2262d246482981a1a49c1cf 172.17.0.11:
slots: ( slots) slave
replicates f6adb618124c791db4e31347982d086cd8b58646
S: 53515a889f77bbe553c8fb664983cded5d767826 172.17.0.12:
slots: ( slots) slave
replicates 1b5b85bd1f068a656b88e0e396f7da8bc0242ebf
M: f6adb618124c791db4e31347982d086cd8b58646 172.17.0.8:
slots:[-] ( slots) master
additional replica(s)
S: ca40bc6c36c7c14a7e91b04bec51bc6bb75eebea 172.17.0.10:
slots: ( slots) slave
replicates 19519487a7db6f2fa5fda5f6e1807befe75665e5
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
root@d8b4eb2b5459:/data#

end

上一篇:yotaku的开发日志(1)


下一篇:SQL Server 2014 新特性——内存数据库