In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-01 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
This article focuses on "how to build a redis cluster with docker". Interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "docker's method of building redis clusters".
I used to use redis stand-alone to build pseudo-clusters before, but in the real environment, I found that there were holes everywhere.
Set up conditions for 3 hosts to install docker and docker-compose at the same time, you can use vm to virtualize three sets and 6 clusters.
The three servers are 192.168.65.133, 192.168.65.134 and 192.168.65.135 respectively.
The first step is to create a new file on any server (mainly to store redis data and some configuration information). Create a new redis file, and then create a new master and slave in the redis file, because you need to put two redis instances on one machine (the machine is limited, of course, do not put the master of each reids on the same machine as slave) as shown below:
Take master as the column, create docker-compose.yml file and redis.conf file after creation, and create data directory data as shown below:
Docker-compose.yml:
Version: '3.3'services: redis-master: image: redis:latest container_name: redis-master restart: always command: redis-server / usr/local/etc/redis/redis.conf network_mode: host ports:-"6379 volumes:-/ home/docker_container/redis/master/data:/data-/ home/docker_container/redis/master" / conf/redis.conf:/usr/local/etc/redis/redis.conf-/ home/docker_container/redis/master/log/redis.log:/root/redis/redis.log
The above network:host is to solve the problem of Waiting for the cluster to join. Has never been successful.
Redis.conf # bind 192.168.65.133 127.0.0.1 # must comment port 6379 # port protected-mode no # requirepass admin # masterauth admin daemonize no appendonly yes cluster-enabled yes cluster-node-timeout 15000 cluster-config-file nodes.conf
The corresponding 192.168.65.133 slave is also configured with a configuration file docker-compose.yml and redis.conf file docker-compose.yml version: '3.3' services: redis-slave: image: redis:latest container_name: redis-slave restart: always command: redis-server / usr/local/etc/redis/redis.conf network_mode: host ports:-"6380 usr/local/etc/redis/redis.conf network_mode 6380"-"16380 services 16380" volumes:-/ home/docker_ Container/redis/slave/data:/data-/ home/docker_container/redis/slave/conf/redis.conf:/usr/local/etc/redis/redis.conf
Redis.conf # bind 0.0.0.0 port 6380 protected-mode no # requirepass admin # masterauth admin daemonize no appendonly yes cluster-enabled yes cluster-node-timeout 15000 cluster-config-file nodes.conf is mainly to change the port. In the above configuration file docker-compose.yml file-"16380 port 16380" is the trunking communication port. I usually use docker-compose up-d to start the redis of master and slave after + 10000 on the redis port to prepare all the files, and check the startup status. There is no problem with startup, so you can copy the redis file to the other two servers with the scp-r command. Then use docker-compose up-d to start the remaining redis, a total of 6 redis. After the startup is complete, we can use redis-trib cluster redis. You can enter the cluster command on any machine: docker run-- rm-it inem0o/redis-trib create-- replicas 1 192.168.65.133it inem0o/redis-trib create 6379 192.168.65.133it inem0o/redis-trib create 6380 192.168.65.134it inem0o/redis-trib create 6379 192.168.65.134it inem0o/redis-trib create 6380 192.168.65.135Creating cluster will appear: `>
Performing hash slots allocation on 6 nodes... Using 3 masters: 192.168.30.70 Using 7002 192.168.30.70 Adding replica 7003 Adding replica 192.168.30.70 to 192.168.30.70 master 7001 Adding replica 192.168.30.70 master 7005 to 192.168.30.70 master 192.168.30.70 7002 Adding replica 192.168.30.70 70 master 7006 to 192.168.30.70 70 master 7003 M: 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 192.168.30.70 master 7001 slots:0-5460 (5461 slots) master M: .168.30.70: 7002 slots:5461-10922 (5462 slots) master M: d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 192.168.30.70 slots 7003 slots:10923-16383 (5461 slots) master S: 52eee69afa751d71c84d5436d14b0e16a37536fa 192.168.30.70 a3548a9dffa225f05786ea2289db65f5f1c623be 7004 replicates 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 S: 701ed2fbb3df9fc63b083818620f5c020d05e323 192.168.30.70 replicates d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 Can I set the above configuration 7006 replicates d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 Can I set the above configuration? (type 'yes' to accept): `
Enter * * yes** `Waiting for the cluster to join.
Performing Cluster Check (using node 192.168.30.70 master 7001) M: 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 192.168.30.70 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 7001 slots:0-5460 (5461 slots) master 1 additional replica (s) M: d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 192.168.30.70 additional replica 7003 "17003 slots:10923-16383 (5461 slots) master 1 additional replica (s) S: a3548a9dffa225f05786ea2289db65f5f1c623be 192.168.30.70 master 7006" 17006 slots: (0 slots) slave replicates d907530ee9f6356e0e61a6c7f4d0cc1b22da1189 S: 701ed2fbb3df9fc63b083818620f5c020d05e323 192.168.30.7015 7005 "17005 slots: (0 slots) slave Replicates bb8fda08e1dcd39e937443f81b5458e80f52d804 S: 52eee69afa751d71c84d5436d14b0e16a37536fa 192.168.30.70 slots 7004 OK 17004 slots: (0 slots) slave replicates 5a7bd7698b1fe55beb44faac051d66c8a03fd1b1 M: bb8fda08e1dcd39e937443f81b5458e80f52d804 192.168.30.70 slots 7002 slots 17002 slots:5461-10922 (5462 slots) master 1 additional replica (s) [OK] All nodes agree about slots configuration.
Check for open slots... Check slots coverage... [OK] All 16384 slots covered. `
Master and slave should be able to adjust through the cluster order, have not tried, I do not know if this is the case. Docker run-- rm-it inem0o/redis-trib check 192.168.65.133purl 6379 test whether to connect to the cluster
Set up cluster mining pit 1. When creating a cluster, you will encounter Waiting for the cluster to join. It has not been successful to change the way the network mode is changed to host,docker run, add-- net host, and add network_mode: host to the docker-compose mode of each redis. 2. Failure to turn off the firewall may lead to an error when the redis does not start correctly: can't connect to node 192.168.65.134 6379 solution: turn off the firewall
Turn off the firewall
Systemctl stop firewalld.service # stop firewall systemctl disable firewalld.service # disable firewall boot
Open the port
Firewall-cmd-- zone=public-- add-port=80/tcp-- permanent if it still doesn't work, you need to check whether redis is started successfully. You can try to access other ports to see if you can connect. Most of the reasons may be due to redis.conf configuration problems. Configuration file bind parameter configuration or other configuration is not commented out or changed to 0.0.0.0 try to change to ip plus 127.0.0.1 or there is a problem 3. When redis-cli connects to the cluster, add the-c parameter redis-cli-c-h yourhost-p yourpost
Cluster password setting: use the redis-trib.rb tool to build the cluster. Do not configure the password before the cluster construction is completed. After the cluster is built, set the password machine by machine through the config set + config rewrite command. If you set the password for the cluster, then both requirepass and masterauth need to be set, otherwise when master-slave switching occurs, you will encounter authorization problems. The passwords of all nodes must be the same. Otherwise, Redirected will fail. The specific instructions are as follows: the first cluster password, cd / mnt/redis-cluster. Chmod 777 9001According to confuse redis.confession; / / profile authorization. Chmod 777 9003According to confession redis.confession; / both configuration files require authorization
/ / Link redis docker ps-a / / View Container ID
/ 5.0.2 docker run-it-- link redis-9001:redis-- net redis-net-- rm redis redis-cli-h XX.XXX.XX.XX-c-p 9001 / / 5.0 (the password for a single redis is set here, so you need to enter each redis to perform the following operations to set the password) docker exec-it redis container ID redis-cli-h XX.XXX.XX.XX-c-p 9001
The second type / / sets the password config set masterauth 123456 config set requirepass 123456 auth 123456 config rewrite
Set masterauth config set masterauth password
Set requirepass config set requirepass password
Verify the password to continue with auth LinShen
Write back to the file to make it permanent (if Permission denied appears here, Dockerfile is missing RUN chmod 777 / usr/local/etc/redis/redis.conf) config rewrite
At this point, I believe you have a deeper understanding of "docker's method of building redis clusters". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.