Redis Cluster 原生安装方式

Cluster原生安装:

  • 1.配置开启节点
  • 2.meet
  • 3.指派槽;
  • 4.主从

配置如下;

vim redis-7000.conf
	port 7000
	daemonize yes
	dir “/opt/redis/redis/data”
	dbfilename “dump-7000.rdb”
	logfile “redis-7000.log”

	cluster-enabled yes
	cluster-config-file nodes-7000.conf
	cluster-requre-full-coverage no 		#是否需要所有节点都可用才正常对外提供服务

sed ’s#7000#7001#g’ redis-7000.conf  > redis-7001.conf
sed ’s#7000#7002#g’ redis-7000.conf  > redis-7002.conf
sed ’s#7000#7003#g’ redis-7000.conf  > redis-7003.conf
sed ’s#7000#7004#g’ redis-7000.conf  > redis-7004.conf
sed ’s#7000#7005#g’ redis-7000.conf  > redis-7005.conf

启动:

	redis-serever redis-7000.conf
	redis-serever redis-7001.conf
	redis-serever redis-7002.conf
	redis-serever redis-7003.conf
	redis-serever redis-7004.conf
	redis-serever redis-7005.conf

meet:

# 查看握手:redis-cli -p 7000 cluster [ nodes | info ]
	reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7001
	reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7002
	reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7003
	reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7004
	reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7005

分配槽位:

		clusterr addslots slot  [slot]
	redis-cli -h 127.0.0.1 -p 7000 cluster addslots {0..5461}
	redis-cli -h 127.0.0.1 -p 7001 cluster addslots {5462..10922}
	redis-cli -h 127.0.0.1 -p 7002 cluster addslots {10923..16383}

# 通过脚本分配槽位;

	start=$1
	end=$2
	port=$3
	for slot  in  `seq ${start}  ${end}`
	do
			echo “slot:${slot}”
			redis-cli -h 127.0.0.1 -p ${port} cluster addslots ${slot}
	done

执行脚本

	sh addslot.sh 0 5461 7000
	sh addslot.sh 5462 10922 7001
	sh addslot.sh 10923 16383 7002

设置主从:

      # 语法
	      cluster replicate node-id
      # node-id查看方法
            redis-clli -p 7000 cluster nodes |  slots查看槽位

# 7003作为7000的slave节点  
redis-cli -h 127.0.0.1 -p 7003 cluster replicate  ${node-id-7000}

# 7004作为7001的slave节点  
redis-cli -h 127.0.0.1 -p 7004 cluster replicate  ${node-id-7001}

# 7005作为7002的slave节点  
redis-cli -h 127.0.0.1 -p 7003 cluster replicate  ${node-id-7002}

重置节点加入集群

  redis-cli -h 127.0.0.0.1  -p 7000 cluster reset
  redis-cli -h 127.0.0.0.1  -p 7001 cluster reset
  redis-cli -h 127.0.0.0.1  -p 7002 cluster reset
  redis-cli -h 127.0.0.0.1  -p 7003 cluster reset
  redis-cli -h 127.0.0.0.1  -p 7004 cluster reset

    # meet
    reedis-cli -h 127.0.0.1 -p 7000 cluster meet 127.0.0.1 7001

  # 分配槽位

Redis Cluster 原生安装方式

上一篇:九个超级实用的 ES6 特性


下一篇:抽象类——抽象方法——接口