Docker implements Redis stand-alone cluster 1master+2slave+3sentinel

1. Basic Concepts

1. Mirror

2, container

3. Warehouse

 

Mirror, which is tiered storage

Containers, the relationship with images, are similar to classes and instances in object-oriented programming

Warehouses are used to manage images. Each warehouse can contain multiple tags, and each tag corresponds to an image.

 

2. Use commit to understand the composition of mirror images

 

 

 

3. Basic commands:

Mirror:

Get the image: docker pull redis:latest

List images: docker image ls

List the included middle-tier images: docker image ls -a

List some images: docker image ls redis:latest

Filter images: docker image ls -f since=redis:latest

Show dangling images: docker image ls -f dangling=true

Remove dangling images: docker image prune

Delete the local image: docker image rm redis

Use ls to delete the image: docker image rm $(docker image ls -q redis)

View the space occupied by images, containers, and data volumes: docker system df

 

container:

List all containers: docker container ls -a

Run the container: docker run redis

Run the container and start a bash terminal: docker run -t -i redis /bin/bash

Run the container in the background: docker run -d redis /bin/sh -c "while true; do echo hello world; sleep 1; done"

Start a stopped container: docker container start [Continer flag]

Terminate the container: docker container stop [Continer flag]

Purge all terminated containers: docker container prune

Remove the container: docker container rm [Continer flag]

Get container output information: docker container logs [Continer flag]

Enter the container: docker attach [Continer flag]

Enter the container (recommended): docker exec -it [Continer flag] bash

(PS: using attach to exit from stdin will cause the container to stop, using exec will not)

Export the container: docker export [Continer flag] redis.tar

Import container snapshot: cat redis.tar | docker import - test/redis:v1.0

 

Check the IP address of the mirror: docker inspect [Continer flag] |grep -i add

 

 

Redis Cluster:

1. Deploy Redis cluster:

redis-master:

docker run -it -p 16379:6379 -v /home/docker/redis/redis-master.conf:/usr/local/etc/redis/redis.conf --name redis-master redis:latest /bin/bash

redis-slave:

docker run -it -p 26371:6379 -v /home/docker/redis/redis-slave1.conf:/usr/local/etc/redis/redis.conf --name redis-slave1 --link redis-master:master redis:latest /bin/bash

docker run -it -p 26372:6379 -v /home/docker/redis/redis-slave2.conf://usr/local/etc/redis/redis.conf --name redis-slave2 --link redis-master:master redis:latest /bin/bash

 

Enter the container and start redis: redis-server /usr/local/etc/redis/redis.conf

 

2. Deploy the Redis sentinel mode and add the following three sentinel containers:

sentinel:

docker run -it -p 36371:36379 -v /home/docker/sentinel/redis-sentinel1.conf:/usr/local/etc/redis/redis.conf --name redis-sentinel1 --link redis-master:master redis:latest /bin/bash

docker run -it -p 36372:36379 -v /home/docker/sentinel/redis-sentinel2.conf:/usr/local/etc/redis/redis.conf --name redis-sentinel2 --link redis-master:master redis:latest /bin/bash

docker run -it -p 36373:36379 -v /home/docker/sentinel/redis-sentinel3.conf:/usr/local/etc/redis/redis.conf --name redis-sentinel3 --link redis-master:master redis:latest /bin/bash

 

Enter the container and start the sentinel: redis-sentinel /usr/local/etc/redis/redis.conf

 

Connect to redis through redis-cli

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325241654&siteId=291194637