这篇文章主要介绍“Redis 5.02官方集群的搭建过程”,在日常操作中,相信很多人在Redis 5.02官方集群的搭建过程问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望对大家解答”Redis 5.02官方集群的搭建过程”的疑惑有所帮助!接下来,请跟着小编一起来学习吧!

1、下载安装Redis

#wgethttp://download.redis.io/releases/redis-stable.tar.gz#tarxfzredis-stable.tar.gz#cdredis-stable#make#设置命令执行路径#cat~/.bash_profilePATH=$PATH:$HOME/bin:/data/redis-stable/src

2、创建集群的数据目录和配置文件

在两台服务器上面,要创建6个redis实例(三主三从),每个服务器,分布创建3个数据目录和3个配置文件。

集群主节点

10.152.5.12:7000

10.152.5.12:7001

10.153.115.24:7003

集群从节点

10.152.5.12:7002

10.153.115.24:7004

10.153.115.24:7005

#10.152.5.12#创建数据目录#mkdirredis_cluster#cdredis_cluster#mkdir700070017002#创建配置文件#cd7000#grep-v"^#"redis_7000.confprotected-modenoport7000daemonizeyessupervisednopidfile/var/run/redis_7000.pidloglevelnoticelogfile"/data/redis_cluster/redis_7000.log"dir./appendonlyyescluster-enabledyescluster-config-filenodes_7000.confcluster-node-timeout5000#启动服务redis-server/data/redis_cluster/7000/redis_7000.conf&

#10.152.5.12#mkdirredis_cluster#cdredis_cluster#mkdir700370047005

3、初始化集群

#redis-cli--clustercreate10.152.5.12:700010.152.5.12:700110.153.115.24:700310.152.5.12:700210.153.115.24:700410.153.115.24:7005--cluster-replicas1>>>Performinghashslotsallocationon6nodes...Master[0]->Slots0-5460Master[1]->Slots5461-10922Master[2]->Slots10923-16383Addingreplica10.153.115.24:7004to10.152.5.12:7000Addingreplica10.152.5.12:7002to10.153.115.24:7003Addingreplica10.153.115.24:7005to10.152.5.12:7001M:65dba2ed08ecb139589710f9efdfd7eeacbb377510.152.5.12:7000slots:[0-5460](5461slots)masterM:08e714061bdb817c23c72f1e5c9a72ab878a0c8f10.152.5.12:7001slots:[10923-16383](5461slots)masterM:7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf410.153.115.24:7003slots:[5461-10922](5462slots)masterS:030fc4d0e02bb7f8245b0bbecf428066daf23a7a10.152.5.12:7002replicates7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4S:c33f01a81258077f3d6cd5f97c91a85225279bff10.153.115.24:7004replicates65dba2ed08ecb139589710f9efdfd7eeacbb3775S:18092c18796972c26785a9cfa408cb3a5210781810.153.115.24:7005replicates08e714061bdb817c23c72f1e5c9a72ab878a0c8fCanIsettheaboveconfiguration?(type'yes'toaccept):yes>>>Nodesconfigurationupdated>>>Assignadifferentconfigepochtoeachnode>>>SendingCLUSTERMEETmessagestojointheclusterWaitingfortheclustertojoin..>>>PerformingClusterCheck(usingnode10.152.5.12:7000)M:65dba2ed08ecb139589710f9efdfd7eeacbb377510.152.5.12:7000slots:[0-5460](5461slots)master1additionalreplica(s)S:c33f01a81258077f3d6cd5f97c91a85225279bff10.153.115.24:7004slots:(0slots)slavereplicates65dba2ed08ecb139589710f9efdfd7eeacbb3775S:18092c18796972c26785a9cfa408cb3a5210781810.153.115.24:7005slots:(0slots)slavereplicates08e714061bdb817c23c72f1e5c9a72ab878a0c8fM:08e714061bdb817c23c72f1e5c9a72ab878a0c8f10.152.5.12:7001slots:[10923-16383](5461slots)master1additionalreplica(s)S:030fc4d0e02bb7f8245b0bbecf428066daf23a7a10.152.5.12:7002slots:(0slots)slavereplicates7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4M:7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf410.153.115.24:7003slots:[5461-10922](5462slots)master1additionalreplica(s)[OK]Allnodesagreeaboutslotsconfiguration.>>>Checkforopenslots...>>>Checkslotscoverage...[OK]All16384slotscovered.

查看进程和日志

#ps-ef|grepredisroot32071239641811:01pts/000:09:31redis-server*:7003[cluster]root3212023964111:02pts/000:00:42redis-server*:7004[cluster]root3216523964111:03pts/000:00:41redis-server*:7005[cluster]root3455032071011:39pts/000:00:00redis-aof-rewrite*:7003[cluster]#tailredis_7003.log30922:M07Dec201810:41:38.391*Readytoacceptconnections32071:C07Dec201811:01:32.731#oO0OoO0OoO0OoRedisisstartingoO0OoO0OoO0Oo32071:C07Dec201811:01:32.731#Redisversion=5.0.2,bits=64,commit=00000000,modified=0,pid=32071,juststarted32071:C07Dec201811:01:32.731#Configurationloaded32071:M07Dec201811:01:32.733*Nodeconfigurationloaded,I'm7a0a2c7b7778467fa6d5d2d5cab52ad35aa77bf4_.__.-``__''-.__.-```.`_.''-._Redis5.0.2(00000000/0)64bit.-``.-```.```\/_.,_''-._(',.-`|`,)Runninginclustermode|`-._`-...-`__...-.``-._|'`_.-'|Port:7003|`-._`._/_.-'|PID:32071`-._`-._`-./_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|http://redis.io`-._`-._`-.__.-'_.-'_.-'|`-._`-._`-.__.-'_.-'_.-'||`-._`-.__.-'_.-'|`-._`-._`-.__.-'_.-'_.-'`-._`-.__.-'_.-'`-.__.-'`-.__.-'32071:M07Dec201811:01:32.734#WARNING:TheTCPbacklogsettingof511cannotbeenforcedbecause/proc/sys/net/core/somaxconnissettothelowervalueof128.32071:M07Dec201811:01:32.734#Serverinitialized32071:M07Dec201811:01:32.734#WARNINGyouhaveTransparentHugePages(THP)supportenabledinyourkernel.ThiswillcreatelatencyandmemoryusageissueswithRedis.Tofixthisissuerunthecommand'echonever>/sys/kernel/mm/transparent_hugepage/enabled'asroot,andaddittoyour/etc/rc.localinordertoretainthesettingafterareboot.RedismustberestartedafterTHPisdisabled.32071:M07Dec201811:01:32.734*Readytoacceptconnections32071:M07Dec201811:06:15.060#configEpochsetto3viaCLUSTERSET-CONFIG-EPOCH32071:M07Dec201811:06:15.116#IPaddressforthisnodeupdatedto10.153.115.2432071:M07Dec201811:06:18.146*Replica10.152.5.12:7002asksforsynchronization32071:M07Dec201811:06:18.146*Partialresynchronizationnotaccepted:ReplicationIDmismatch(Replicaaskedfor'b8db3eb5c491ab9e2ff92de627925a93105ddd96',myreplicationIDsare'054964ff1a25320ff6d97c24594f2683e30d43c0'and'0000000000000000000000000000000000000000')32071:M07Dec201811:06:18.146*StartingBGSAVEforSYNCwithtarget:disk32071:M07Dec201811:06:18.146*Backgroundsavingstartedbypid3234932349:C07Dec201811:06:18.147*DBsavedondisk32349:C07Dec201811:06:18.148*RDB:0MBofmemoryusedbycopy-on-write32071:M07Dec201811:06:18.196*Backgroundsavingterminatedwithsuccess32071:M07Dec201811:06:18.196*Synchronizationwithreplica10.152.5.12:7002succeeded32071:M07Dec201811:06:20.001#Clusterstatechanged:ok32071:M07Dec201811:31:25.118*1changesin900seconds.Saving...32071:M07Dec201811:31:25.118*Backgroundsavingstartedbypid3374033740:C07Dec201811:31:25.119*DBsavedondisk33740:C07Dec201811:31:25.120*RDB:0MBofmemoryusedbycopy-on-write32071:M07Dec201811:31:25.218*Backgroundsavingterminatedwithsuccess32071:M07Dec201811:31:37.418*StartingautomaticrewritingofAOFon6722641000%growth32071:M07Dec201811:31:37.418*Backgroundappendonlyfilerewritingstartedbypid3375132071:M07Dec201811:31:38.420*AOFrewritechildaskstostopsendingdiffs.33751:C07Dec201811:31:38.420*Parentagreedtostopsendingdiffs.FinalizingAOF...33751:C07Dec201811:31:38.420*Concatenating5.25MBofAOFdiffreceivedfromparent.

到此,关于“Redis 5.02官方集群的搭建过程”的学习就结束了,希望能够解决大家的疑惑。理论与实践的搭配能更好的帮助大家学习,快去试试吧!若想继续学习更多相关知识,请继续关注亿速云网站,小编会继续努力为大家带来更多实用的文章!