百度360必应搜狗淘宝本站头条
当前位置:网站首页 > 技术教程 > 正文

Redis Cluster6.2.6集群搭建

mhr18 2024-12-05 14:11 22 浏览 0 评论

我们这使用redis版本为6.2.6,下载好后放在某个文件夹然后解压这个步骤。我这是/home/redis,废话不多说我们开干。

一、创建五个文件夹

使用mkdir名称创建7000 7001 7002 7003 7004 7005六?个文件夹

[root@VM-0-5-centos redis]# mkdir 7000 7001 7002 7003 7004 7005
[root@VM-0-5-centos redis]# ll
total 2448
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7000
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7001
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7002
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7003
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7004
drwxr-xr-x 2 root root    4096 Jan  7 09:53 7005
drwxrwxr-x 7 root root    4096 Oct 31 09:35 redis-6.2.6
-rw-r--r-- 1 root root 2476542 Oct  4 19:19 redis-6.2.6.tar.gz

二、将redis.conf配置文件复制6个份,分别放在第一步创建的6个文件夹中

[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7000
[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7001
[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7002
[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7003
[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7004
[root@VM-0-5-centos redis]# cp /home/redis/redis-6.2.6/redis.conf /home/redis/7005

三、修改6个文件夹中的redis.config配置文件

## 如果是在单机模拟集群必须指定bind的IP,如果不修改ip的话使用程序连接集群会报错
bind 0.0.0.0
#关闭保护模式,如果开启需要设置密码
protected-mode no
## 7000-7005端口
port 7000
## 后台启动
daemonize yes

pidfile /var/run/redis_7000.pid

dir /home/redis/7000/
#开启redis-cluster集群
cluster-enabled yes
## 每个实例还包含存储此节点配置的文件的路径,默认情况下为nodes.conf,自动创建
cluster-config-file /home/redis/7000/nodes-7000.conf



四、启动单个节点

此时节点之间还没有联系

[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7000/redis.conf
[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7001/redis.conf
[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7002/redis.conf
[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7003/redis.conf
[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7004/redis.conf
[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-server 7005/redis.conf

五、查看redis进程,确定是否全部正常启动

ps -ef|grep redis

六、创建集群

通过命令redis-cli -h ip -p port进入指定的redis的手脚架,redis-cli -h IP -p 6379,-h后面接redis服务器的IP地址,-p后面接端口, 一般没做过修改redis.conf情况下端口是6379,我这对应的是端口7000

redis-cli -h 192.168.64.1 -p 7000
#不要用内网ip
redis-6.2.6/src/redis-cli --cluster create 192.168.64.1:7000 192.168.64.1:7001 192.168.64.1:7002 192.168.64.1:7003 192.168.64.1:7004 192.168.64.1:7005 --cluster-replicas 1
#用外网ip
redis-6.2.6/src/redis-cli --cluster create ip:7000 ip:7001 ip:7002 ip:7003 ip:7004 ip:7005 --cluster-replicas 1

集群参数说明

cluster-replicas 1:为每个主节点创建从节点的数量,1表示一主一从,2表示一主二从

[root@VM-0-5-centos redis]# redis-6.2.6/src/redis-cli --cluster create ip:7000 ip:7001 ip:7002 ip:7003 ip:7004 ip:7005 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica ip:7004 to ip:7000
Adding replica ip:7005 to ip:7001
Adding replica ip:7003 to ip:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 2629dfd2c10a0bc6a3d83325b94f90076a734c3a ip:7000
   slots:[0-5460] (5461 slots) master
M: a06128cfc6ecc474f4e4b8ea2f28057b65323b5d ip:7001
   slots:[5461-10922] (5462 slots) master
M: 7a857547ac2c30ae32d0143b5e74f117cd733009 ip:7002
   slots:[10923-16383] (5461 slots) master
S: c9377a700a6832d99a9a11dc04aad18abff46cdc ip:7003
   replicates a06128cfc6ecc474f4e4b8ea2f28057b65323b5d
S: c397ccd12f648a6aca8f33cb23ae511113b5b046 ip:7004
   replicates 7a857547ac2c30ae32d0143b5e74f117cd733009
S: 88b190b173c711768039c79c3e0fcc581430b6cf ip:7005
   replicates 2629dfd2c10a0bc6a3d83325b94f90076a734c3a
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
................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................

Can I set the above configuration? (type 'yes' to accept): 询问是否确认节点 slots 分配方案, 我们输入 ‘yes’。

发现一直卡在Waiting for the cluster to join,需要开放云服务器的端口,添加redis集群总线端口和每个redis实例的通信端口即可。

首先需要理清一个概念,就是redis集群总线:

redis集群总线端口为redis客户端端口加上10000,比如说你的redis 6379端口为客户端通讯端口,那么16379端口为集群总线端口

我搭建的redis集群终端口号是从 7001 ~ 7006的,其中 7001、7003、7005 为主节点,7002、7004、7006为从节点;那么redis集群中总线端口为17001、17003、17005


[root@VM-0-5-centos src]# redis-cli --cluster create ip:7000 ip:7001 ip:7002 ip:7003 ip:7004 ip:7005 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica ip:7004 to ip:7000
Adding replica ip:7005 to ip:7001
Adding replica ip:7003 to ip:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: b78ab698b9fe32f161a8af0e78396eb287060538 ip:7000
   slots:[0-5460] (5461 slots) master
M: 5487bd1cd8cbd182caac7e35441892757c8fc466 ip:7001
   slots:[5461-10922] (5462 slots) master
M: 71323348e2ac97dba519ea87d95d5b6765965122 ip:7002
   slots:[10923-16383] (5461 slots) master
S: 448115b6966ca44948f66d262142199b147c70d5 ip:7003
   replicates 71323348e2ac97dba519ea87d95d5b6765965122
S: 0e505c52b1d3be343b986e1e42979ade087c85a7 ip:7004
   replicates b78ab698b9fe32f161a8af0e78396eb287060538
S: a297e581f0f8d3091fb77a3d2e1bfd2213c0becb ip:7005
   replicates 5487bd1cd8cbd182caac7e35441892757c8fc466
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 ip:7000)
M: b78ab698b9fe32f161a8af0e78396eb287060538 ip:7000
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 5487bd1cd8cbd182caac7e35441892757c8fc466 ip:7001
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 0e505c52b1d3be343b986e1e42979ade087c85a7 ip:7004
   slots: (0 slots) slave
   replicates b78ab698b9fe32f161a8af0e78396eb287060538
S: 448115b6966ca44948f66d262142199b147c70d5 ip:7003
   slots: (0 slots) slave
   replicates 71323348e2ac97dba519ea87d95d5b6765965122
M: 71323348e2ac97dba519ea87d95d5b6765965122 ip:7002
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: a297e581f0f8d3091fb77a3d2e1bfd2213c0becb ip:7005
   slots: (0 slots) slave
   replicates 5487bd1cd8cbd182caac7e35441892757c8fc466
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

测试数据插入

[root@VM-0-5-centos src]# redis-cli -c -h 外网ip -p 7000
ip:7000> set firstkey 2022-01-17
OK
ip:7000> set name xiong
-> Redirected to slot [5798] located at 42.194.195.235:7001
OK
ip:7001> set age 28
-> Redirected to slot [741] located at 42.194.195.235:7000
OK
ip:7000> set address jiangxi
OK
ip:7000>

查看对应的从库

[root@VM-0-5-centos src]# ./redis-cli -c -h 42.194.29.** -p 7004
42.194.29:7004> keys *
1) "firstkey"
42.194.29:7004> keys *
1) "firstkey"
42.194.29:7004> keys *
1) "address"
2) "age"
3) "firstkey"

查看集群状态

成功了

相关推荐

AlmaLinux 9.6发布:升级工具、初步支持IBM Power虚拟化技术

IT之家5月21日消息,科技媒体linuxiac昨日(5月20日)发布博文,报道称代号为SageMargay的AlmaLinux9.6发行版已上线,距上一版本9.5发...

Java最新学习路线,系统全面,零基础适用

首先,我个人比较推崇的学习方法是:先学java前段,也就是HTML,css,js,因为学习java以后肯定是往javaee方向发展的,学习完前端,在学习后端很多东西比计较容易理解!其中J2SE是关键...

深入理解数据库事务(数据库事务处理的理解)

Transaction作为关系型数据库的核心组成,在数据安全方面有着非常重要的作用,本文会一步步解析事务的核心特性,以获得对事务更深的理解。什么是事务数据库几乎是所有系统的核心模块,它将数据有条理地保...

IvorySQL 4.4 发布(1044mysql)

IvorySQL4.4已于2025年3月10日正式发布。新版本全面支持PostgreSQL17.4,新增多项新功能,并修复了已知问题。增强功能PostgreSQL17.3增强功...

Oracle 与 Google Cloud 携手大幅扩展多云服务

据DCD4月10日报道,甲骨文(Oracle)与谷歌云(GoogleCloud)深化合作,全力扩展多云产品。双方计划为OracleDatabaseGoogleCloud解决方案新增11...

Izzi 利用 Oracle 云提高计费效率和客户体验

据thefastmode网5月2日报道,墨西哥电信运营商Izzi宣布采用Oracle云基础设施(OCI),对其业务支持系统(BSS)进行现代化改造增强客户体验,已经成功完成。通过在OCI上运行...

好莱坞群星也有明星脸?硅谷科技名人本尊分身比一比

假如有部电影齐聚了众科技名人角色,如同许多好莱坞大牌卡司所共同主演的《瞒天过海》(Ocean’sEleven)那样,演出彼此在商场上竞逐、或共同对抗外来竞争捍卫硅谷的故事,更在剧中有不少对手戏,会不...

澳大利亚Find My iPhone被黑 多人被黑客锁机

FindMyiPhone本来是一个用于协助找回被盗手机的好工具,但是现在,澳洲的苹果用户发现他们的FindMyiPhone变成了黑客的帮凶。昨天,这名自称为OlegPliss的黑客使用Fin...

服务器密码错误被锁定怎么解决(服务器密码失效)

#服务器密码错误被锁定解决方案当服务器因多次密码错误导致账户被锁定时,可以按照以下步骤进行排查和解决:##一、确认锁定状态###1.检查账户锁定状态(Linux)```bash#查看账户锁定...

凌晨突发的数据库重大故障,我排查了一整天……

春节期间过得太热闹了,上班确实没啥状态,这不刚发生的一个重大性能故障,排查了整整一天,后面的领导都站成了一排,本次把故障发生的详细分析过程分享给大家!本次故障发生在凌晨,核心应用卡顿非常严重,Orac...

Oracle锁表紧急处理!3招快速解锁方案

开篇:突发故障现场凌晨1点,某电商系统突然卡顿,数千笔支付订单无法完成——数据库出现死锁,技术团队紧急响应...(遇到类似情况的,欢迎在评论区分享经历)一、问题重现:死锁是如何产生的?典型场景:问题根...

JetBrains DataGrip Mac中文破解版V2025.1下载安装教程

DataGripforMac是由JetBrains开发的数据库集成开发环境(IDE),专为数据库管理员和开发人员设计。它支持多种数据库(如MySQL、PostgreSQL、Oracle、SQ...

电脑装安卓系统,安卓X86版5.1 RC1下载

日前,谷歌放出了Android-x865.1的第一个候选版本Android-x865.1RC1,该版本基于Android5.1.1r24Lollipop开发,更新包括大量x86(32位)代...

来来来!一文告诉你Eclipse的正确安装使用姿势,你都清楚吗?

前言本学习笔记是有关如何设置Eclipse的详细说明。即使你天天在使用它,但是,相信我,或许你并不足够了解它。安装Java运行时环境Eclipse是Java应用程序,因此设置Eclipse的第一步是安...

分享收藏的 oracle 11.2.0.4各平台的下载地址

概述oracle11.2.0.4是目前生产环境用的比较多的版本,同时也是很稳定的一个版本。目前官网上已经找不到下载链接了,有粉丝在头条里要求分享一下下载地址。一、各平台下载地址1.1Linuxx...

取消回复欢迎 发表评论: