Redis-3.2.4 build based on the Redis-Cluster Cluster
principle
Redis cluster using the P2P model, completely decentralized. Key to all Redis divided into 16384 slot, wherein each instance is responsible for a portion of Redis slot. All information (node, port, slot, etc.) in the cluster are updated by the periodic exchange of data between nodes.
Examples Redis Redis client can issue a request for any, if the required data is not in this example, the access command to the desired instance by redirecting guide client.
Between any two nodes are interconnected. The client can be connected to any node, and then you can access any node in the cluster. Their access and other operations.
Redis on each node, there are two such things, is a slot (slot) can be understood as a range of a variable can store two values of this variable is: 0-16383. There is a cluster I personally put this cluster is understood as a cluster management plug-ins. When we reach the access key, will come Redis crc16 algorithm according to a result, and the results of the remainder number of 16384, such that each number corresponds to a hash key groove are between 0-16383 by this value, corresponding to the node to find the corresponding slot, and then automatically jump directly to the corresponding node access operation.
Set up
3 3 recommended master node 6 from Scheme
#创建文件夹
mkdir /usr/local/redis-cluster
mkdir /usr/local/redis-cluster/bin
cd /usr/local/redis-cluster
mkdir -p 6380/data 6381/data 6382/data 6383/data 6384/data 6385/data
#进入编译好的redis下的src目录,拷贝文件到redis-cluster/bin中
cd redis-3.2.4/src
cp mkreleasehdr.sh redis-benchmark redis-check-aof redis-cli redis-server redis-trib.rb /usr/local/redis-cluster/bin
#复制一个新的redis实例到6380文件夹中
cp -r /usr/local/redis /usr/local/redis-cluster/6380
#修改redis.conf
port 6380 #端口号
daemonize yes
requirepass redispwd #设置密码
masterauth redispwd #设置验证密码
bind 192.168.204.128 #本机ip
dir /usr/local/redis-cluster/6380/data/ #数据文件存放位置
pidfile /var/run/redis_6380.pid #6380跟port一致
cluster-enabled yes #启动集群模式
cluster-config-file nodes6380.conf #6380跟port一致
cluster-node-timeout 15000
appendonly yes
#另外复制上一个配置好的实例5个
\cp -rf /usr/local/redis-cluster/6380/* /usr/local/redis-cluster/6381
\cp -rf /usr/local/redis-cluster/6380/* /usr/local/redis-cluster/6382
\cp -rf /usr/local/redis-cluster/6380/* /usr/local/redis-cluster/6383
\cp -rf /usr/local/redis-cluster/6380/* /usr/local/redis-cluster/6384
\cp -rf /usr/local/redis-cluster/6380/* /usr/local/redis-cluster/6385
#分别修改这5个配置文件,采用字符串替换
vi /usr/local/redis-cluster/6381/redis/etc/redis.conf
:%s/6380/6381
vi /usr/local/redis-cluster/6382/redis/etc/redis.conf
:%s/6380/6382
vi /usr/local/redis-cluster/6383/redis/etc/redis.conf
:%s/6380/6383
vi /usr/local/redis-cluster/6384/redis/etc/redis.conf
:%s/6380/6384
vi /usr/local/redis-cluster/6385/redis/etc/redis.conf
:%s/6380/6385
#分别启动redis实例
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6380/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6381/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6382/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6383/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6384/redis/etc/redis.conf
/usr/local/redis/bin/redis-server /usr/local/redis-cluster/6385/redis/etc/redis.conf
#查看进程信息
ps aux|grep 'redis'
#安装ruby,rubygems
yum install ruby
yum install rubygems
#上传redis-3.2.1.gem文件到某个目录下并cd到该目录进行安装
gem install -l redis-3.2.1.gem
#设置集群密码
find / -name 'client.rb'
#添加密码(我的在以下目录)
vi /usr/local/share/gems/gems/redis-3.2.1/lib/redis/client.rb
password redispwd
# 创建集群
/usr/local/redis-cluster/bin/redis-trib.rb create --replicas 1 192.168.204.128:6380 192.168.204.128:6381 192.168.204.128:6382 192.168.204.128:6383 192.168.204.128:6384 192.168.204.128:6385
#命令行访问任一节点,进行测试
/usr/local/redis-cluster/6380/redis/bin/redis-cli -c -h 192.168.204.128 -p 6380 -a "redispwd"
Problems
springboot integration redis clusters need to turn off the firewall available, only open port numbers for all nodes can not establish a connection, inquired about the official website said node port number +10000 port number is also required before they can open, such as 6380 nodes need to be opened outside the port 6380,16380 network access, other nodes in the same way, but I tried it or not, the specific reasons unknown, also please guide.