docker打包镜像搭建redis集群

从192.168.0.121服务器打包下载镜像

docker save -o redis-cluster-4.0.1.tar ubuntu-redis

镜像下载地址:https://download.csdn.net/download/wxuzero/11038067

在目标服务器载入镜像

docker load --input redis-cluster-4.0.1.tar

查看镜像

docker images

创建启动容器

docker run -it -d --net=host --name=redis-cluster-4.0.1 redis-cluster-4.0.1

进入容器

docker exec -it redis-cluster-4.0.1 /bin/bash

启动各redis节点

/opt/redis-cluster/nodes-7001/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7001/redis-4.0.1/redis.conf

/opt/redis-cluster/nodes-7002/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7002/redis-4.0.1/redis.conf

/opt/redis-cluster/nodes-7003/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7003/redis-4.0.1/redis.conf

/opt/redis-cluster/nodes-7004/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7004/redis-4.0.1/redis.conf

/opt/redis-cluster/nodes-7005/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7005/redis-4.0.1/redis.conf

/opt/redis-cluster/nodes-7006/redis-4.0.1/src/redis-server /opt/redis-cluster/nodes-7006/redis-4.0.1/redis.conf

查看redis启动情况

ps -ef|grep redis

进入到/opt/redis-cluster/nodes-7001/redis-4.0.1/src目录启动集群(注IP192.168.0.121改为对应服务器IP)

redis-trib.rb create --replicas 1 192.168.0.121:7001 192.168.0.121:7002 192.168.0.121:7003 192.168.0.121:7004 192.168.0.121:7005 192.168.0.121:7006

测试集群搭建成功

cd /opt/redis-cluster/nodes-7001/redis-4.0.1/src

./redis-cli -p 7001 -c

127.0.0.1:7001> set key1 1

-> Redirected to slot [9189] located at 192.168.0.121:7002

OK

192.168.0.121:7002> get key1

"1"

192.168.0.121:7002>

# ./redis-cli -p 7002 -c

127.0.0.1:7002> get key1

"1"

# ./redis-cli -p 7003 -c

127.0.0.1:7003> get key1

-> Redirected to slot [9189] located at 192.168.0.121:7002

"1"

192.168.0.121:7002>

退出容器

 

附:

启动各节点脚本

vim start-all.sh

cd /opt/redis-cluster/nodes-7001/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7001/redis-4.0.1/redis.conf

cd /opt/redis-cluster/nodes-7002/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7002/redis-4.0.1/redis.conf

cd /opt/redis-cluster/nodes-7003/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7003/redis-4.0.1/redis.conf

cd /opt/redis-cluster/nodes-7004/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7004/redis-4.0.1/redis.conf

cd /opt/redis-cluster/nodes-7005/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7005/redis-4.0.1/redis.conf

cd /opt/redis-cluster/nodes-7006/redis-4.0.1/src/

./redis-server /opt/redis-cluster/nodes-7006/redis-4.0.1/redis.conf

 

关闭集群脚本

vim shutdown-all.sh

cd /opt/redis-cluster/nodes-7001/redis-4.0.1/src

./redis-cli -p 7001 shutdown

./redis-cli -p 7002 shutdown

./redis-cli -p 7003 shutdown

./redis-cli -p 7004 shutdown

./redis-cli -p 7005 shutdown

./redis-cli -p 7006 shutdown

 

 

你可能感兴趣的:(运维架构)