当前位置:网站首页>Redis replication cluster setup
Redis replication cluster setup
2022-07-23 10:28:00 【Uncle flying against the wind】
Preface
redis Replication cluster is a common cluster mode in development , This article demonstrates how to centos7 Build a quick redis Replication cluster ;
Environmental preparation
1、 be based on centos7 Server of the system ( Or cloud servers );
2、redis Installation package ;
![]()
Set up process
Due to resource constraints , This article will build on a server , Distinguish by different port numbers ;
1、 Upload redis Install the package to the specified directory ( And extract the )

2、 In the current directory , Create three directories
In the current directory , Create separate 7001,7002,7003 Three file directories

3、 take redis Unzip the package redis.conf The configuration files are copied to three directories

4、 Modify the default port number of each configuration file , Data storage directory
have access to sed Command to perform batch replacement modification
sed -i -e 's/6379/7001/g' -e 's/dir .\//dir \/tmp\/7001\//g' 7001/redis.conf
sed -i -e 's/6379/7002/g' -e 's/dir .\//dir \/tmp\/7002\//g' 7002/redis.conf
sed -i -e 's/6379/7003/g' -e 's/dir .\//dir \/tmp\/7003\//g' 7003/redis.conf
After modification , We might as well check any configuration file ,

5、 Modify the declaration of each instance IP
There are multiple virtual machines IP, To avoid future chaos , Need to be in redis.conf Specify the binding of each instance in the file ip Information , The format is as follows :
replica-announce-ip At present IP
You can still edit in batch
sed -i '1a replica-announce-ip At present IP' 7001/redis.conf
sed -i '1a replica-announce-ip At present IP' 7002/redis.conf
sed -i '1a replica-announce-ip At present IP' 7003/redis.conf
The modification is complete , You can confirm with the following command

The modification of the above configuration file is basically completed
6、 Cluster start
To start, respectively, 3 An example , The starting process is as follows :
7001 example :

7002 example :

7003 example :

If you want to stop with one key , You can run the following command :
printf '%s\n' 7001 7002 7003 | xargs -I{} -t redis-cli -p {} shutdown
7、 To configure 3 The master-slave relationship between instances
It's activated 3 An example , But there is no master-slave relationship between them , To configure master-slave, you can use replicaof perhaps slaveof(5.0 before ) command .
There are temporary and permanent modes :
- Modify the configuration file ( permanent ), stay redis.conf Add a line of configuration : slaveof <masterip> <masterport>;
- Use redis-cli The client connects to redis service , perform slaveof command ( Failure after restart ): slaveof <masterip> <masterport>;
Here is to show the effect , We use the second way to explain , adopt redis-cli Command connection 7002, Execute the following command :
redis-cli -p 7002

Then execute the following command
SLAVEOF 127.0.0.1 7001
The moment you execute the above command, you can see 7001 and 7002 Output information of two instance consoles , I see 7002 Completed the 7001 Connection and data synchronization

Connect in the same way 7003 client , And perform the above operations

Connect 7001 client , perform info Command to view the cluster information , See the following message , It indicates that the cluster is successfully built

8、 Cluster testing
stay 7001 Connect the client and set a key, And then in 7002 Check above

But if 7002 or 7003 above set One key It's a mistake , That is, the slave node does not have write permission ;

The problem summary
Many students upload and unzip the installation package in the first step , It is also configured correctly according to the configuration file , But the startup error , This makes a common sense mistake , Because at this time redis Compilation and installation have not been completed , Therefore, it is necessary to enter redis Unzip the package src, Under the table of contents , perform : make install command ;
边栏推荐
- [c #] IEnumerable enumerable type interface analysis yield
- C语言文件操作
- Kingbasees SQL language reference manual of Jincang database (8. Function (7))
- How to build and use redis fragment cluster
- Redis token record user login design solution?
- Android development learning diary - content provider (cross application database modification)
- [300 + selected interview questions from big companies continued to share] big data operation and maintenance sharp knife interview question column (VII)
- 大专码农和 985 程序员有什么区别?
- mysql三表查询问题
- 金仓数据库 KingbaseES SQL 语言参考手册 (8. 函数(四))
猜你喜欢

Kingbasees SQL language reference manual of Jincang database (8. Function (9))

C language file operation

EasyCVR平台升级到最新版本v2.5.0,如何同步mysql数据库?

【代码案例】网页版表白墙 & 待办事项 (包含完整源码)

数据中台、BI业务访谈(三):如何选择合适的访谈对象

缓存穿透、缓存击穿、缓存雪崩

【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(七)

仅用5000行代码,在V853上AI渲染出一亿幅山水画

S2SH+mysql的在线英语学习系统

大专码农和 985 程序员有什么区别?
随机推荐
EasyCVR平台CGO回放回调参数缺失导致设备录像无法播放,该如何解决?
C language -- several classic exercises of C language
MySQL主从复制
redis的事务、锁机制、秒杀
Nine charts overview the cycle law of encryption Market
32-spark的分区算子介绍、广播变量和累加器
Self organization is the two-way rush of managers and members
浏览安全怎么提升?教你设置安全浏览器信任站点
C language file operation
2022/7/21
SSM framework takeout ordering system
Redis安装
[vscode] the current working directory is not the current folder /pathlib print CWD path error
How does the browser import and export | delete bookmarks? Here are the steps
Rapid SQL All-Platforms高性能 SQL 代码
Redis token record user login design solution?
redis伪集群一键部署脚本---亲测可用
Sum of three numbers: (sort + double pointer + pruning)
mysql三表查询问题
【300+精选大厂面试题持续分享】大数据运维尖刀面试题专栏(七)