当前位置:网站首页>Redis cluster setup
Redis cluster setup
2022-07-24 11:03:00 【AscendKing】
The article comes from the blog Garden , Add a little , Such as infringement , Please contact to delete
Beginners redis, To study the redis Common data structure of , Then it's time to learn redis It's time to cluster
that , Before learning, we should build up redis colony
The following steps are set up by looking for various data , You can use
First installation redis
What's installed here is redis Source package , So we need to gcc Environmental support
yum install gcc-c++
Will be taken from redis Downloaded from the official website redis Upload the installation package to /usr/local
Then decompress
tar -zxvf redis-3.2.5.tar.gz
Enter the decompressed directory to compile
cd /usr/local/redis-3.2.5
make
In this step of compiling, you can specify the directory , That is, the specified directory of the installation
Put the previous step make It's written in make PREFIX=/usr/local/redis install ( The directory I specify here is /usr/local/redis)
After installation redis A... Will be generated under the folder bin Catalog
redis start-up
Direct operation bin/redis-server Will start in front mode , The disadvantage of front-end mode startup is ssh When the command window is closed redis-server Program end , This method is not recommended . Here's the picture :
modify redis.conf The configuration file , daemonize yes Later mode starts .
Execute the following command to start redis:
cd /usr/local/redis
./bin/redis-server ./redis.conf
thus redis Your installation is complete
Let's start building clusters
ruby Environmental Science
redis Cluster management tool redis-trib.rb rely on ruby Environmental Science , Installation is required first ruby Environmental Science :
install ruby
yum install ruby
yum install rubygems
install ruby and redis The interface program of
gem install redis
Cluster node planning
Here, different ports are used to represent different ports on the same server redis The server , as follows :
Master node :192.168.106.132:7001 192.168.106.132:7002 192.168.106.132:7003
From the node :192.168.106.132:7004 192.168.106.132:7005 192.168.106.132:7006
stay /usr/local Create redis-cluster Catalog , It creates 7001、7002..7006 Catalog , as follows :
take redis The installation directory bin Copy the files under to each 700X In the table of contents , At the same time redis Source directory src Under the redis-trib.rb copy to redis-cluster Under the table of contents .
Modify each 700X In the catalog redis.conf The configuration file :
port XXXX
cluster-enabled yes
Start each node redis service
Respectively into the 7001、7002、...7006 Catalog , perform :
./redis-server ./redis.conf
Check the process
Execute the create cluster command
stay /usr/local/redis-cluster/
perform redis-trib.rb, This script is ruby Script , It relies on ruby Environmental Science .
./redis-trib.rb create --replicas 1 192.168.106.132:7001 192.168.106.132:7002 192.168.106.132:7003 192.168.106.132:7004 192.168.106.132:7005 192.168.106.132:7006
explain :
redis Clustering requires at least 3 Main node , Each master node has one slave node 6 Nodes
replicas Designated as 1 Indicates that each master node has a slave node
Be careful :
In case of execution, the following error is reported :
[ERR] Node XXXXXX is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0
The solution is to delete the generated configuration file nodes.conf, If not, the node created now includes the node information of the old cluster , You need to remove redis And then restart redis, such as :appendonly.aof、dump.rdb
Be careful :
In case of execution, the following error is reported :
>>> Creating cluster
[ERR] Sorry, can't connect to node 192.168.168.151:7001
This is because redis.conf It is equipped with a password , Need to comment out the password Or the cluster mode is not turned on Or is it protected-mode yes
Comment out the password :#requirepass ******
Open cluster mode : Let go of comments
take
# cluster-enabled yes
It is amended as follows
cluster-enabled yes
take
protected-mode yes
It is amended as follows
protected-mode no
take
daemonize no
It is amended as follows
daemonize yes
The output of creating a cluster is as follows
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.106.132:7001
192.168.106.132:7002
192.168.106.132:7003
Adding replica 192.168.106.132:7004 to 192.168.106.132:7001
Adding replica 192.168.106.132:7005 to 192.168.106.132:7002
Adding replica 192.168.106.132:7006 to 192.168.106.132:7003
M: 6c388e0cd04990b23e2e65b285b5f9c1bc996538 192.168.106.132:7001
slots:0-5460 (5461 slots) master
M: 01e9cd67978b1cad73a40e9a70000a236744cb17 192.168.106.132:7002
slots:5461-10922 (5462 slots) master
M: 72a649017fdd5d4045f9d58df8b231c2d69e6c32 192.168.106.132:7003
slots:10923-16383 (5461 slots) master
S: b90aa487cf48270df43e79af98807bb5ffabbe34 192.168.106.132:7004
replicates 6c388e0cd04990b23e2e65b285b5f9c1bc996538
S: f873f54c61dbb613df58fa4b9ff8bc3dd48e2388 192.168.106.132:7005
replicates 01e9cd67978b1cad73a40e9a70000a236744cb17
S: daa813e169580417f4410fac86a3d4ab9abda804 192.168.106.132:7006
replicates 72a649017fdd5d4045f9d58df8b231c2d69e6c32
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 192.168.106.132:7001)
M: 6c388e0cd04990b23e2e65b285b5f9c1bc996538 192.168.106.132:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
S: b90aa487cf48270df43e79af98807bb5ffabbe34 192.168.106.132:7004
slots: (0 slots) slave
replicates 6c388e0cd04990b23e2e65b285b5f9c1bc996538
M: 72a649017fdd5d4045f9d58df8b231c2d69e6c32 192.168.106.132:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 01e9cd67978b1cad73a40e9a70000a236744cb17 192.168.106.132:7002
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: daa813e169580417f4410fac86a3d4ab9abda804 192.168.106.132:7006
slots: (0 slots) slave
replicates 72a649017fdd5d4045f9d58df8b231c2d69e6c32
S: f873f54c61dbb613df58fa4b9ff8bc3dd48e2388 192.168.106.132:7005
slots: (0 slots) slave
replicates 01e9cd67978b1cad73a40e9a70000a236744cb17
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
Query cluster information
The cluster is successfully created and logged in redis Node queries the nodes in the cluster
Be careful ! Be careful ! Be careful ! After installing the cluster, you must use Only the lowest command can connect
./redis-cli -h 192.168.168.102 -p 7006( If the password is configured You need to add parameters -a password )
Use ./redis-cli -c 192.168.168.102 -p 7006 perhaps ./redis-cli -c -p 7006 Can't connect
Cluster created
redis To restart the cluster, you need to delete the files under each node , The delete command is as follows :
I only have two files
rm -rf appendonly.aof | rm -rf dump.rdb | rm -rf nodes.conf | rm -rf redis.log
边栏推荐
- Publish local image to private library
- [FPGA]: IP core - multiplier
- BBR 与 queuing
- openresty lua-resty-logger-socket日志传输
- web咸鱼自救攻略--typescript的类没有你想象中的那么难
- 蓝牙技术的发展与历程
- Zero basic learning canoe panel (7) -- input/output box
- [FPGA]: IP core -- rapid IO
- [micro service] eureka+ribbon realizes registration center and load balancing
- [AHK] AutoHotKey tutorial ①
猜你喜欢

Working principle and function application of frequency converter

【直播报名】Location Cache 模块浅析及 OCP 监控、报警详解

「低功耗蓝牙模块」主从一体 蓝牙嗅探-助力智能门锁

Cookie sessionstorage localstorage differences

RS485 communication OSI model network layer

Idea background image set

Docker installs 3 master and 3 slave redis clusters

CSDN blog removes the uploaded image watermark

rs485通信OSI模型网络层

cookie sessionStorage localStorage 区别
随机推荐
The bean injected through @autowired can still be injected even if the class is not annotated with annotations such as @comment
零基础学习CANoe Panel(3)—— 静态控件(Static Text , Group Box ,Picture Box)
[interview: Basics 04: insert order]
Simply understand MODBUS function code and partition
BBR and queuing
西门子200smart自创库与说明
Simply use MySQL index
QT create application tray and related functions
UVM——双向通信
redis 缓存设置,实现类似putIfAbsent功能
自学软件测试天赋异禀——不是盖的
Siemens 200smart self created library and description
UNIX C language POSIX thread creation, obtaining thread ID, merging thread, separating thread, terminating thread, thread comparison
变频器的四大组成部分和工作原理
【白帽子讲Web安全】第一章 我的安全世界观
Tidb query SQL report runtime error: index out of range [-1] error
web咸鱼自救攻略--typescript的类没有你想象中的那么难
SQL optimization skills and precautions
Distributed lock implementation scheme (glory collection version)
Publish local image to private library