1、redis.7003.conf内容port 7003appendonly.7003.aofcluster-config-file nodes-7003.confredis.7004.conf内容port 7004appendonly.7004.aofcluster-config-file nodes-7004.confredis.7005.conf内容port 7005appendonly.7005.aofcluster-config-file nodes-7005.confredis.7006.conf内容port 7006appendonly.7006.aofcluster-config-
2、file nodes-7006.conf启动服务打开6个CMD命令行工具,切换到C:redis-64.3.0.503目录下,分别输入Redis-server.exe redis.7001.confRedis-server.exe redis.7002.confRedis-server.exe redis.7003.confRedis-server.exe redis.7004.confRedis-server.exe redis.7005.confRedis-server.exe redis.7006.conf启动成功后界面如下3. Ruby安装下载地址:安装界面如下所示安装完成后,打开命令输
3、入ruby v命令检查是否安装成功4. 安装redis的ruby运行库打开命令行输入gem install redis命令5. 下载redis-trib.rb脚本文件redis-trib.rb文件是运行redis集群的脚本库,文件内容如下,可将下面的文件内容拷贝到记事本中另存为redis-trib.rb文件然后将redis-trib.rb拷贝到C:redis-64.3.0.503目录下#!/usr/bin/env ruby# TODO (temporary here, well move this into the Github issues once# redis-trib initial
4、implementation is completed).# - Make sure that if the rehashing fails in the middle redis-trib will try# to recover.# - When redis-trib performs a cluster check, if it detects a slot move in# progress it should prompt the user to continue the move from where it# stopped.# - Gracefully handle Ctrl+C
5、 in move_slot to prompt the user if really stop# while rehashing, and performing the best cleanup possible if the user# forces the quit.# - When doing fix set a global Fix to true, and prompt the user to# fix the problem if automatically fixable every time there is something# to fix. For instance:#
6、1) If there is a node that pretend to receive a slot, or to migrate a# slot, but has no entries in that slot, fix it.# 2) If there is a node having keys in slots that are not owned by it# fix this condition moving the entries in the same node.# 3) Perform more possibly slow tests about the state of
7、the cluster.# 4) When aborted slot migration is detected, fix it.require rubygemsredisClusterHashSlots = 16384defxputs(s) case s0.2 when color=29;1ER31;OK32FA,*33 else color=nil end color = nil if ENVTERM != xterm print 033#colorm if color print s0330mnendclass ClusterNodedef initialize(addr) s = ad
8、dr.split(:) if s.length 1 here, its IPv6, so restore address r = nil info = info:host = ipport = portslots = migrating = importing = replicate = false dirty = false # True if we need to flush slots info into node. friends = def friends friendsdef slotsslotsdefhas_flag?(flag)flags.index(flag)defto_s
9、#info:host:portdef connect(o=) return if rConnecting to node #self:STDOUT.flush begin r = Redis.new(:host =host, :port =port, :timeout = 60) r.ping rescuexputs ERR Sorry, cant connect to node #self exit 1 if o:abortOKdefassert_cluster info = r.infoif !infocluster_enabled | info.to_i = 0ERR Node #sel
10、f is not configured as a cluster node.defassert_empty(r.cluster(info).split(rn).index(cluster_known_nodes:) | (r.infodb0)ERR Node #self is not empty. Either the node already knows other nodes (check with CLUSTER NODES) or contains some key in database 0.defload_info(o=)self.connect nodes = r.cluster
11、(nodesnodes.each|n| # name addr flags role ping_sentping_recvlink_status slots split = n.splitname,addr,flags,master_id,ping_sent,ping_recv,config_epoch,link_status = split0.6 slots = split8.-1 info = :name = name,addr =addr,flags =flags.split(),replicate =master_id,ping_sent =ping_sent.to_i,ping_re
12、cv =ping_recv.to_i,link_status =link_status info:replicate = false if master_id = - if info:flags.index(myself info = info.merge(info)slots.each|s| if s0.0 = if s.index(-) # Migratingslot,dst = s1.-1.split(migratingslot.to_i = dstelsifs.index(-) # Importingslot,src = s1.-1.split(importingslot.to_i =
13、 srcstart,stop = s.split(self.add_slots(start.to_i).(stop.to_i)self.add_slots(s.to_i).(s.to_i) if slots dirty = false r.cluster().each|e|k,v=e.split( k = k.to_symv.chop! if k != :cluster_state infok = v.to_i infok = velsif o:getfriends friends infodefadd_slots(slots)slotss = :new dirty = truedefset_
14、as_replica(node_id)replicate = node_iddefflush_node_config return if !dirty if info:replicatereplicate,info:replicate) # If the cluster did not already joined it is possible that # the slave does not know the master node yet. So on errors # we return ASAP leaving the dirty flag set, to flush the # c
15、onfig later. return new = slots.each|s,val| if val = : new sslotss = trueaddslots,*new)definfo_string # We want to display the hash slots assigned to this node # as ranges, like in:1-5,8-9,20-25,30 # # Note: this could be easily written without side effects, # we use slots just to split the computat
16、ion into steps. # First step: we want an increasing array of integers # for instance: 1,2,3,4,5,8,9,20,21,22,23,24,25,30 slots = info:slots.keys.sort # As we want to aggregate adjacent slots we convert all the # slot integers into ranges (with just one element) # So we have something like 1.1,2.2, .
17、 and so forth.slots.map!|x| x.x # Finally we group ranges with adjacent elements. slots = slots.reduce() |a,b|a.empty? &b.first = (a-1.last)+1a0.-2 + (a-1.first).(b.last) a + b # Now our task is easy, we just convert ranges with just one # element into a number, and a real range into a start-end for
18、mat. # Finally we join the array using the comma as separator. slots = slots.map|x|x.count = 1 ?x.first.to_s :#x.first-#x.last.join( role = self.has_flag?(master) ?MS if self.info:replicate and dirty is = S: #self.info:name #self.to_s#role:name #self.to_sn+ slots:#slots (#self.slots.length slots) #(
19、self.info:flags-).join() is += n replicates #info:replicateelsifself.has_flag?) & self.info:replicasn #info:replicas.length additional replica(s) is # Return a single string representing nodes and associated slots. # TODO: remove slaves from config when slaves will be handled # by Redis Cluster.defget_config_signatureconfig = ).each_line|l| s = l.split slots = s8.-1.select |x| x0.0 ! next if slots.length = 0config 0 and num_args != req_args) | (req_args 0 and num_argsreq_args.abs)ERR Wrong number of arguments for specified sub commanddefadd_node(node) nodes nodedefcluste
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1