Environment: Docker + (Redis:5.0.5 * 3) 1. Pull the imagedocker pull redis:5.0.5 2. Create a Redis containerCreate three redis containers: redis-node1:6379 redis-node2:6380 redis-node3:6381 docker create --name redis-node1 -v /data/redis-data/node1:/data -p 6379:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-1.conf docker create --name redis-node2 -v /data/redis-data/node2:/data -p 6380:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-2.conf docker create --name redis-node3 -v /data/redis-data/node3:/data -p 6381:6379 redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-3.conf 3. Start and build a cluster to start the container First, start three Redis containers using the After executing the run command, check the startup of the container: If the above situation occurs, As shown above, it is a permission problem. Let's try to modify the permissions: chmod -R 777 /data After successful startup, the following figure is shown: Building a cluster View the IP node information assigned by 3 Redis in Docker: Execute "docker inspect redis-node1" to get the redis-node1 ip information: 172.17.0.4 After getting the IP information (each person's IP information may be different), enter a container to build a cluster: # Here we take entering node1 as an example docker exec -it redis-node1 /bin/bash # Then execute the cluster formation command (please splice according to your own IP information) redis-cli --cluster create 172.17.0.2:6379 172.17.0.3:6379 172.17.0.4:6379 --cluster-replicas 0 OK, now the cluster is built. Let's test it. Test cluster Use the 4. Existing problems According to the above steps, although the cluster is built successfully, there are still some problems. Since One solution is to let Docker use the To solve the existing problem, we re-adopt 1. Stop the running container docker stop redis-node1 redis-node2 redis-node3 2. Delete the previously created container docker rm redis-node1 redis-node2 redis-node3 # Clear the configuration file created above rm -rf /data/redis-data/node* 3. Re-create based on host mode docker create --name redis-node1 --net host -v /data/redis-data/node1:/data redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-1.conf --port 6379 docker create --name redis-node2 --net host -v /data/redis-data/node2:/data redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-2.conf --port 6380 docker create --name redis-node3 --net host -v /data/redis-data/node3:/data redis:5.0.5 --cluster-enabled yes --cluster-config-file nodes-node-3.conf --port 6381 Different from the previous creation command, first, the 4. Start the container and form a cluster # Start command docker start redis-node1 redis-node2 redis-node3 # Enter a container docker exec -it redis-node1 /bin/bash # Build a cluster, 10.211.55.4 is the IP address of the current physical machine redis-cli --cluster create 10.211.55.4:6379 10.211.55.4:6380 10.211.55.4:6381 --cluster-replicas 0 5. View cluster information root@CentOS7:/data# redis-cli 127.0.0.1:6379> cluster nodes 72c291c32815194b64d1f6d0fdf771f5cc04e14a 10.211.55.4:6380@16380 master - 0 1590905997358 2 connected 5461-10922 6a595b67bbff15c94e5874c2d2cd556d6a6a6c17 10.211.55.4:6381@16381 master - 0 1590905998362 3 connected 10923-16383 4e3dbdc8f835dcbc38291c88f08165ee51d53d3d 10.211.55.4:6379@16379 myself,master - 0 1590905997000 1 connected 0-5460 127.0.0.1:6379> 6. Test cluster Use root@CentOS7:/data# redis-cli -c 127.0.0.1:6379> set wxiaowei 123 -> Redirected to slot [7515] located at 10.211.55.4:6380 OK 10.211.55.4:6380> get wxiaowei "123" At this point, The master-slave cluster you want: https://www.jb51.net/article/212285.htm This is the end of this article about building a Redis cluster on Docker. For more information about building a Docker Redis cluster, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future! You may also be interested in:
|
<<: CSS3 implements footer fixed at the bottom (always at the bottom no matter how high the page is)
>>: How to display a small icon in front of the browser URL
1. Find the corresponding nodejs package, refer t...
Table of contents Math Objects Common properties ...
I encountered a small problem today and struggled ...
Table of contents Purpose npm init and package.js...
1. There are two ways to modify global variables ...
This article example shares the specific code of ...
This article describes MySQL index coverage with ...
Detailed explanation of mysql count The count fun...
Preface Programming languages usually contain v...
This article shares the download, installation an...
Table of contents text 1. Prepare the machine 2. ...
Copy code The code is as follows: li {width:300px...
Table of contents 1. Reverse proxy preparation 1....
Optimization ideas There are two main optimizatio...
describe: Install VM under Windows 10, run Docker...