redis-集群安装(1)

Redis 3.0概述
Redis 是一个高性能的key-value数据库。 redis的出现,很大程度补偿了memcached这类keyvalue存储的不足,在部分场合可以对关系数据库起到很好的补充作用。它提供了Python,Ruby,Erlang,PHP客户端,使用很方便。3.0版本加入cluster功能,解决了redis单点无法横向扩展问题。
此时我们安装的是3.2版本

M1,M2,M3为redis三个主节点,S1,S2,S3为redis三个从节点,分别为M1,M2,M3备份数据以及故障切换使用。APP访问数据库可以通过连接任意一个Master节点实现。在三个Master节点的redis集群中,只容许有一个Master出故障,当多于一个Master宕机时,redis即不可用。当其中一个Master出现故障,其对应的Slave会接管故障Master的服务,保证redis 数据库的正常使用。
安装。在此安装4节点集群
1,
安装系统包
[ root@T1 ~]# yum install gcc
[ root@T1 ~]#  yum install zlib
发现没有zib的yum源
查看系统版本
[ root@T1 yum.repos.d]# cat /etc/issue
CentOS release 6.7 (Final)
Kernel \r on an \m
自己配置yum源
[root@T1 ~]# yum install ruby
[root@T1 yum.repos.d]# yum install rubygems
红色解释
Redis作者应该是个Ruby爱好者,Ruby客户端就是他开发的。这次集群的管理功能没有嵌入到Redis代码中,于是作者又顺手写了个叫做redis-trib的管理脚本。redis-trib依赖Ruby和RubyGems,以及redis扩展。可以先用which命令查看是否已安装ruby和rubygems
[ root@T1 tmp]# gem install -l /tmp/redis-3.2.1.gem
Successfully installed redis-3.2.1
1 gem installed
Installing ri documentation for redis-3.2.1...
Installing RDoc documentation for redis-3.2.1...
redis软件
[ root@T1 tmp]# yum install lszrz
[ root@T1 tmp]# rz
z waiting to receive.**B0100000023be50
[ root@T1 tmp]# tar -zxvf redis-3.2.0.tar.gz 
[ root@T1 tmp]# cd redis-3.2.0
[ root@T1 redis-3.2.0]# ls
00-RELEASENOTES  CONTRIBUTING  deps     Makefile   README.md   runtest          runtest-sentinel  src    utils
BUGS             COPYING       INSTALL  MANIFESTO  redis.conf  runtest-cluster  sentinel.conf     tests
[ root@T1 redis-3.2.0]# make
[ root@T1 redis-3.2.0]# make test
cd src && make test
make[1]: Entering directory `/tmp/redis-3.2.0/src'
You need tcl 8.5 or newer in order to run the Redis test
make[1]: *** [test] 错误 1
make[1]: Leaving directory `/tmp/redis-3.2.0/src'
make: *** [test] 错误 2
若出现测试地址被占用
[ root@T1 redis-3.2.0]# pwd
/tmp/redis-3.2.0
[ root@T1 redis-3.2.0]# vi redis.conf 
改变
bind 172.16.57.54

[ root@T1 redis-3.2.0]# yum install -y tcl
再次运行 make test
在make成功以后,会在src目录下多出一些可执行文件:redis-server,redis-cli等等。  方便期间用cp命令复制到usr目录下运行(直接使用make install 应该也可以)。
[ root@T1 redis-3.2.0]# make install 
cd src && make install
make[1]: Entering directory `/tmp/redis-3.2.0/src'

Hint: It's a good idea to run 'make test' ;)

    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
    INSTALL install
make[1]: Leaving directory `/tmp/redis-3.2.0/src'
2,
修改系统参数
[ root@T1 redis-3.2.0]# vi /etc/sysctl.conf
添加vm.overcommit_memory=1
[ root@T1 redis-3.2.0]# ulimit -n  10032 
可以看到open files  已经变成10032了
[ root@T1 redis-3.2.0]# ulimit -a
core file size          (blocks, -c) 0
data seg size           (kbytes, -d) unlimited
scheduling priority             (-e) 0
file size               (blocks, -f) unlimited
pending signals                 (-i) 15228
max locked memory       (kbytes, -l) 64
max memory size         (kbytes, -m) unlimited
open files                      (-n) 10032
pipe size            (512 bytes, -p) 8
POSIX message queues     (bytes, -q) 819200
real-time priority              (-r) 0
stack size              (kbytes, -s) 10240
cpu time               (seconds, -t) unlimited
max user processes              (-u) 15228
virtual memory          (kbytes, -v) unlimited
file locks                      (-x) unlimited
这种修改在机器重启后失效
永久有效
在/etc/rc.local 中增加一行 ulimit -SHn 10032 
关闭hugepage:# echo never > /sys/kernel/mm/transparent_hugepage/enabled
修改somaxconn :# echo 511 >/proc/sys/net/core/somaxconn
关闭防火墙:# service iptables stop
关闭selinux:# vi /etc/sysconfig/selinux  修改“SELINUX=disabled”
开始安装集群
拷贝bin文件
[ root@T1 src]# cp redis-trib.rb /usr/local/bin/
[ root@T1 src]# cp redis-cli /usr/local/bin/
[ root@T1 src]# cp redis-server /usr/local/bin/
[ root@T1 src]# which redis-trib.rb
/usr/local/bin/redis-trib.rb
这里提到redis集群模型,一般redis进程数是CPU核数的一半。
[ root@T1 src]# cat /proc/cpuinfo
这里单数表示1,master进程,而11,表示从进程。ps有四个物理机,每个物理机有两个主进程两个从进程。

图中failover机制自己体会
配置通用config文件redis-common.conf(每个节点都要设置)
[ root@T1 redis-3.2.0]# mkdir config
[ root@T1 redis-3.2.0]# cd config/
[root@T1 config]# vi redis-common.conf
添加如下代码,注意各节点ip的绑定
#GENERAL
bind 172.16.57.54
daemonize yes
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
databases 16
dir /tmp/redis-3.2.0/data
slave-serve-stale-data yes
slave-read-only yes
#not use default
repl-disable-tcp-nodelay yes
slave-priority 100
appendonly yes
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
cluster-enabled yes
cluster-node-timeout 15000
cluster-migration-barrier 1
slowlog-log-slower-than 10000
cluster-require-full-coverage no
slowlog-max-len 128
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-entries 512
list-max-ziplist-value 64
set-max-intset-entries 512
zset-max-ziplist-entries 128
zset-max-ziplist-value 64
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
红色解释
cluster-require-full-coverage no。默认是yes,只要有结点宕机导致16384个槽没全被覆盖,整个集群就全部停止服务,所以一定要改为no
!!!!!!!!!!!!!注意在conf里面配置优先级和密码认证
masterauth fafa123
requirepass fafa123
[ root@T1 config]# mkdir /tmp/redis-3.2.0/data
说明我们有4个节点,8个master进程,8个slave进程
端口对应如下

节点1配置文件redis-6379.conf, redis-6383.conf, redis-16385.conf,redis-16382.conf
[ root@T1 config]# vi redis-6379.conf
添加如下代码
include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6379
logfile " /tmp/redis-3.2.0 /log/redis-6379.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6379.aof"
dbfilename dump-6379.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6379.conf
auto-aof-rewrite-percentage 80-100

在这里可以加上优先级slave-priority 100
一些解释
绑定地址:bind 192.168.XXX.XXX。不能绑定到127.0.0.1或localhost,否则指导客户端重定向时会报”Connection refused”的错误。
开启Cluster:cluster-enabled yes
集群配置文件:cluster-config-file nodes-7000.conf。这个配置文件不是要我们去配的,而是Redis运行时保存配置的文件,所以我们也不可以修改这个文件。
集群超时时间:cluster-node-timeout 15000。结点超时多久则认为它宕机了。
槽是否全覆盖:cluster-require-full-coverage no。默认是yes,只要有结点宕机导致16384个槽没全被覆盖,整个集群就全部停止服务,所以一定要改为no
后台运行:daemonize yes
输出日志:logfile “./redis.log”
监听端口:port 7000
[ root@T1 config]# vi redis-6383.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6383
logfile " /tmp/redis-3.2.0 /log/redis-6383.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6383.aof"
dbfilename dump-6383.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6383.conf
auto-aof-rewrite-percentage 80-100
从节点
[ root@T1 config]# vi redis-16385.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16385
logfile "/tmp/redis-3.2.0/log/redis-16385.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16385.aof"
dbfilename dump-16385.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16385.conf
auto-aof-rewrite-percentage 80-100
[ root@T1 config]# vi redis-16382.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16382
logfile "/tmp/redis-3.2.0/log/redis-16382.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16382.aof"
dbfilename dump-16382.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16382.conf
auto-aof-rewrite-percentage 80-100


节点2配置文件 redis-16379.conf, redis-6380.conf, redis-6384.conf,redis-16386.conf
[ root@T2 config]# vi redis-6380.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6380
logfile " /tmp/redis-3.2.0 /log/redis-6380.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6380.aof"
dbfilename dump-6380.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6380.conf
auto-aof-rewrite-percentage 80-100
[ root@T2 config]# vi redis-6384.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6384
logfile " /tmp/redis-3.2.0 /log/redis-6384.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6384.aof"
dbfilename dump-6384.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6384.conf
auto-aof-rewrite-percentage 80-100

从节点
[ root@T2 config]# vi redis-16379.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16379
logfile "/tmp/redis-3.2.0/log/redis-16379.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16379.aof"
dbfilename dump-16379.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16379.conf
auto-aof-rewrite-percentage 80-100
[ root@T2 config]# vi redis-16386.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16386
logfile "/tmp/redis-3.2.0/log/redis-16386.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16386.aof"
dbfilename dump-16386.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16386.conf
auto-aof-rewrite-percentage 80-100


节点3配置文件 redis-6385.conf, redis-16380.conf, redis-6381.conf,redis-16384.conf
[ root@T3 config]# vi redis-6385.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6385
logfile " /tmp/redis-3.2.0 /log/redis-6385.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6385.aof"
dbfilename dump-6385.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6385.conf
auto-aof-rewrite-percentage 80-100
[ root@T3 config]# vi redis-6381.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6381
logfile " /tmp/redis-3.2.0 /log/redis-6381.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6381.aof"
dbfilename dump-6381.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6381.conf
auto-aof-rewrite-percentage 80-100

从节点
[ root@T3 config]# vi redis-16380.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16380
logfile "/tmp/redis-3.2.0/log/redis-16380.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16380.aof"
dbfilename dump-16380.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16380.conf
auto-aof-rewrite-percentage 80-100
[ root@T3 config]# vi redis-16384.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16384
logfile "/tmp/redis-3.2.0/log/redis-16384.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16384.aof"
dbfilename dump-16384.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16384.conf
auto-aof-rewrite-percentage 80-100
节点4 配置文件 redis-6386.conf, redis-16383.conf, redis-16381.conf,redis-6382.conf
[ root@T4 config]# vi redis-6386.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6386
logfile " /tmp/redis-3.2.0 /log/redis-6386.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6386.aof"
dbfilename dump-6386.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6386.conf
auto-aof-rewrite-percentage 80-100
[ root@T4 config]# vi redis-6382.conf

include  /tmp/redis-3.2.0 /config/redis-common.conf
port 6382
logfile " /tmp/redis-3.2.0 /log/redis-6382.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-6382.aof"
dbfilename dump-6382.rdb
dir  /tmp/redis-3.2.0 /data
cluster-config-file nodes-6382.conf
auto-aof-rewrite-percentage 80-100

从节点
[ root@T4 config]# vi redis-16383.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16383
logfile "/tmp/redis-3.2.0/log/redis-16383.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16383.aof"
dbfilename dump-16383.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16383.conf
auto-aof-rewrite-percentage 80-100

[ root@T4 config]# vi redis-16381.conf

include /tmp/redis-3.2.0/config/redis-common.conf
port 16381
logfile "/tmp/redis-3.2.0/log/redis-16381.log"
maxmemory 100m
# volatile-lru -> remove the key with an expire set using an LRU algorithm
# allkeys-lru -> remove any key accordingly to the LRU algorithm
# volatile-random -> remove a random key with an expire set
# allkeys-random -> remove a random key, any key
# volatile-ttl -> remove the key with the nearest expire time (minor TTL)
# noeviction -> don't expire at all, just return an error on write operations
maxmemory-policy allkeys-lru
appendfilename "appendonly-16381.aof"
dbfilename dump-16381.rdb
dir /tmp/redis-3.2.0/data
cluster-config-file nodes-16381.conf
auto-aof-rewrite-percentage 80-100
启动redis节点
节点1
[ root@T1 config]# redis-server redis-6379.conf
[ root@T1 config]# redis-server redis-6383.conf 
[ root@T1 config]# redis-server redis-16382.conf
[ root@T1 config]# redis-server redis-16385.conf
节点2
[ root@T2 config]# redis-server redis-6380.conf
[ root@T2 config]# redis-server redis-6384.conf
[ root@T2 config]# redis-server redis-16379.conf
[ root@T2 config]# redis-server redis-16386.conf 
节点3
[ root@T3 config]# redis-server redis-6381.conf
[ root@T3 config]# redis-server redis-6385.conf
[ root@T3 config]# redis-server redis-16380.conf
[ root@T3 config]# redis-server redis-16384.conf 
节点4
[ root@T4 config]# redis-server redis-6386.conf
[ root@T4 config]# redis-server redis-6382.conf
[ root@T4 config]# redis-server redis-16383.conf
[ root@T4 config]# redis-server redis-16381.conf 

在节点1查查看看
[ root@T1 config]# ps -ef |grep redis
root      40535      1  0 14:55 ?        00:00:00 redis-server *:6379 [cluster]
root      40543      1  0 14:58 ?        00:00:00 redis-server *:6383 [cluster]
root      40566      1  0 15:21 ?        00:00:00 redis-server *:16382 [cluster]
root      40570      1  0 15:21 ?        00:00:00 redis-server *:16385 [cluster]
 通过redis-trib创建cluster
#--replicas 则指定了为Redis Cluster中的每个Master节点配备几个Slave节点
[ root@T1 config]# redis-trib.rb create --replicas 1 172.16.57.54:6379 172.16.57.54:6383 172.16.57.55:6380 172.16.57.55:6384 172.16.57.56:6381 172.16.57.56:6385 172.16.57.57:6382 172.16.57.57:6386 172.16.57.55:16379 172.16.57.57:16383 172.16.57.56:16380 172.16.57.56:16384 172.16.57.57:16381 172.16.57.54:16385 172.16.57.54:16382 172.16.57.55:16386
报错
>>> Creating cluster
[ERR] Sorry, can't connect to node 172.16.57.54:6379
原因是
[ root@T1 config]# redis-trib.rb check 127.0.0.1:6379
>>> Performing Cluster Check (using node 127.0.0.1:6379)
M: 3ea77504768534438608cc8282409ad0380cc230 127.0.0.1:6379
   slots: (0 slots) master
   0 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[ERR] Not all 16384 slots are covered by nodes.
需要在 redis-common.conf绑定节点真实ip
注意这里的replicas 是复制集 的意思如果没有slave就可以去掉这个
[ root@T1 config]# redis-trib.rb create --replicas 1 172.16.57.54:6379 172.16.57.54:6383 172.16.57.55:6380 172.16.57.55:6384 172.16.57.56:6381 172.16.57.56:6385 172.16.57.57:6382 172.16.57.57:6386 172.16.57.55:16379 172.16.57.57:16383 172.16.57.56:16380 172.16.57.56:16384 172.16.57.57:16381 172.16.57.54:16385 172.16.57.54:16382 172.16.57.55:16386
>>> Creating cluster
>>> Performing hash slots allocation on 16 nodes...
Using 8 masters:
172.16.57.57:6382
172.16.57.56:6381
172.16.57.55:6380
172.16.57.54:6379
172.16.57.57:6386
172.16.57.56:6385
172.16.57.55:6384
172.16.57.54:6383
Adding replica 172.16.57.56:16380 to 172.16.57.57:6382
Adding replica 172.16.57.57:16383 to 172.16.57.56:6381
Adding replica 172.16.57.54:16385 to 172.16.57.55:6380
Adding replica 172.16.57.55:16379 to 172.16.57.54:6379
Adding replica 172.16.57.56:16384 to 172.16.57.57:6386
Adding replica 172.16.57.57:16381 to 172.16.57.56:6385
Adding replica 172.16.57.54:16382 to 172.16.57.55:6384
Adding replica 172.16.57.55:16386 to 172.16.57.54:6383
M: 3ea77504768534438608cc8282409ad0380cc230 172.16.57.54:6379
   slots:6144-8191 (2048 slots) master
M: adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 172.16.57.54:6383
   slots:14336-16383 (2048 slots) master
M: c1137994639200525ef7f561ce291b3ce38079b3 172.16.57.55:6380
   slots:4096-6143 (2048 slots) master
M: 46f9543f054435dea90aded227f5a53a1383dee2 172.16.57.55:6384
   slots:12288-14335 (2048 slots) master
M: a15269fef298a4e62fb10b3b1bd4ec7178760c34 172.16.57.56:6381
   slots:2048-4095 (2048 slots) master
M: 450e56c837a409ac25b3aaae01fb561699654098 172.16.57.56:6385
   slots:10240-12287 (2048 slots) master
M: 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 172.16.57.57:6382
   slots:0-2047 (2048 slots) master
M: be75716373aa05a16e890427386950e59c917d1f 172.16.57.57:6386
   slots:8192-10239 (2048 slots) master
S: 2f1c88c822a81d22ebeddc3a0816b62997a16dbe 172.16.57.55:16379
   replicates 3ea77504768534438608cc8282409ad0380cc230
S: 2d832131cf4196c83557d0a153775ee63605ed90 172.16.57.57:16383
   replicates a15269fef298a4e62fb10b3b1bd4ec7178760c34
S: ec8ea752576da5eea8bc3934544826d8730e1dfd 172.16.57.56:16380
   replicates 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c
S: 4d6ee6db3875c75fb0f44e1c93106da5b43bd5ba 172.16.57.56:16384
   replicates be75716373aa05a16e890427386950e59c917d1f
S: e9b7be308399f30dd25f0d63b4befa536e91fe60 172.16.57.57:16381
   replicates 450e56c837a409ac25b3aaae01fb561699654098
S: a94b11d778ffd22c3643ee0debcb0e8d52cae037 172.16.57.54:16385
   replicates c1137994639200525ef7f561ce291b3ce38079b3
S: 2c3b29c266cdd2796314f785891bf7dbf39c1764 172.16.57.54:16382
   replicates 46f9543f054435dea90aded227f5a53a1383dee2
S: b1ead2f5918bf1ceb71c6a34ddb57017dbffd7bd 172.16.57.55:16386
   replicates adcdcd04c6d77a0dfa6fbacff68c668f42a727fb
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 172.16.57.54:6379)
M: 3ea77504768534438608cc8282409ad0380cc230 172.16.57.54:6379
   slots:6144-8191 (2048 slots) master
M: adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 172.16.57.54:6383
   slots:14336-16383 (2048 slots) master
M: c1137994639200525ef7f561ce291b3ce38079b3 172.16.57.55:6380
   slots:4096-6143 (2048 slots) master
M: 46f9543f054435dea90aded227f5a53a1383dee2 172.16.57.55:6384
   slots:12288-14335 (2048 slots) master
M: a15269fef298a4e62fb10b3b1bd4ec7178760c34 172.16.57.56:6381
   slots:2048-4095 (2048 slots) master
M: 450e56c837a409ac25b3aaae01fb561699654098 172.16.57.56:6385
   slots:10240-12287 (2048 slots) master
M: 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 172.16.57.57:6382
   slots:0-2047 (2048 slots) master
M: be75716373aa05a16e890427386950e59c917d1f 172.16.57.57:6386
   slots:8192-10239 (2048 slots) master
M: 2f1c88c822a81d22ebeddc3a0816b62997a16dbe 172.16.57.55:16379
   slots: (0 slots) master
   replicates 3ea77504768534438608cc8282409ad0380cc230
M: 2d832131cf4196c83557d0a153775ee63605ed90 172.16.57.57:16383
   slots: (0 slots) master
   replicates a15269fef298a4e62fb10b3b1bd4ec7178760c34
M: ec8ea752576da5eea8bc3934544826d8730e1dfd 172.16.57.56:16380
   slots: (0 slots) master
   replicates 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c
M: 4d6ee6db3875c75fb0f44e1c93106da5b43bd5ba 172.16.57.56:16384
   slots: (0 slots) master
   replicates be75716373aa05a16e890427386950e59c917d1f
M: e9b7be308399f30dd25f0d63b4befa536e91fe60 172.16.57.57:16381
   slots: (0 slots) master
   replicates 450e56c837a409ac25b3aaae01fb561699654098
M: a94b11d778ffd22c3643ee0debcb0e8d52cae037 172.16.57.54:16385
   slots: (0 slots) master
   replicates c1137994639200525ef7f561ce291b3ce38079b3
M: 2c3b29c266cdd2796314f785891bf7dbf39c1764 172.16.57.54:16382
   slots: (0 slots) master
   replicates 46f9543f054435dea90aded227f5a53a1383dee2
M: b1ead2f5918bf1ceb71c6a34ddb57017dbffd7bd 172.16.57.55:16386
   slots: (0 slots) master
   replicates adcdcd04c6d77a0dfa6fbacff68c668f42a727fb
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

检查集群状态
连接任意节点,执行redis-trib.rb
[ root@T1 config]# redis-trib.rb check 172.16.57.55:6380
>>> Performing Cluster Check (using node 172.16.57.55:6380)
M: c1137994639200525ef7f561ce291b3ce38079b3 172.16.57.55:6380
   slots:4096-6143 (2048 slots) master
   1 additional replica(s)
M: 450e56c837a409ac25b3aaae01fb561699654098 172.16.57.56:6385
   slots:10240-12287 (2048 slots) master
   1 additional replica(s)
S: 2f1c88c822a81d22ebeddc3a0816b62997a16dbe 172.16.57.55:16379
   slots: (0 slots) slave
   replicates 3ea77504768534438608cc8282409ad0380cc230
M: 3ea77504768534438608cc8282409ad0380cc230 172.16.57.54:6379
   slots:6144-8191 (2048 slots) master
   1 additional replica(s)
S: 2c3b29c266cdd2796314f785891bf7dbf39c1764 172.16.57.54:16382
   slots: (0 slots) slave
   replicates 46f9543f054435dea90aded227f5a53a1383dee2
M: a15269fef298a4e62fb10b3b1bd4ec7178760c34 172.16.57.56:6381
   slots:2048-4095 (2048 slots) master
   1 additional replica(s)
M: be75716373aa05a16e890427386950e59c917d1f 172.16.57.57:6386
   slots:8192-10239 (2048 slots) master
   1 additional replica(s)
S: a94b11d778ffd22c3643ee0debcb0e8d52cae037 172.16.57.54:16385
   slots: (0 slots) slave
   replicates c1137994639200525ef7f561ce291b3ce38079b3
S: b1ead2f5918bf1ceb71c6a34ddb57017dbffd7bd 172.16.57.55:16386
   slots: (0 slots) slave
   replicates adcdcd04c6d77a0dfa6fbacff68c668f42a727fb
S: ec8ea752576da5eea8bc3934544826d8730e1dfd 172.16.57.56:16380
   slots: (0 slots) slave
   replicates 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c
S: e9b7be308399f30dd25f0d63b4befa536e91fe60 172.16.57.57:16381
   slots: (0 slots) slave
   replicates 450e56c837a409ac25b3aaae01fb561699654098
S: 4d6ee6db3875c75fb0f44e1c93106da5b43bd5ba 172.16.57.56:16384
   slots: (0 slots) slave
   replicates be75716373aa05a16e890427386950e59c917d1f
M: 27dae6d2fcf9a294de7c6c5c10f10c97cb9dc44c 172.16.57.57:6382
   slots:0-2047 (2048 slots) master
   1 additional replica(s)
M: adcdcd04c6d77a0dfa6fbacff68c668f42a727fb 172.16.57.54:6383
   slots:14336-16383 (2048 slots) master
   1 additional replica(s)
S: 2d832131cf4196c83557d0a153775ee63605ed90 172.16.57.57:16383
   slots: (0 slots) slave
   replicates a15269fef298a4e62fb10b3b1bd4ec7178760c34
M: 46f9543f054435dea90aded227f5a53a1383dee2 172.16.57.55:6384
   slots:12288-14335 (2048 slots) master
   1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
查看集群信息
[ root@T1 config]# redis-cli -h 172.16.57.54 -p 6379
172.16.57.54:6379> info all
# Server
redis_version:3.2.0
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:944bfe4b4de6ffd0
redis_mode:cluster
os:Linux 2.6.32-573.el6.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.4.7
process_id:40603
run_id:9a6cf2f57695644606fba6b9e35bafa291cc7652
tcp_port:6379
uptime_in_seconds:1737
uptime_in_days:0
hz:10
lru_clock:4115982
executable:/tmp/redis-3.2.0/config/redis-server
config_file:/tmp/redis-3.2.0/config/redis-6379.conf

# Clients
connected_clients:1
client_longest_output_list:0
client_biggest_input_buf:0
blocked_clients:0

# Memory
used_memory:2552032
used_memory_human:2.43M
used_memory_rss:3080192
used_memory_rss_human:2.94M
used_memory_peak:2552032
used_memory_peak_human:2.43M
total_system_memory:4016713728
total_system_memory_human:3.74G
used_memory_lua:37888
used_memory_lua_human:37.00K
maxmemory:100000000
maxmemory_human:95.37M
maxmemory_policy:allkeys-lru
mem_fragmentation_ratio:1.21
mem_allocator:jemalloc-4.0.3

# Persistence
loading:0
rdb_changes_since_last_save:0
rdb_bgsave_in_progress:0
rdb_last_save_time:1463732560
rdb_last_bgsave_status:ok
rdb_last_bgsave_time_sec:0
rdb_current_bgsave_time_sec:-1
aof_enabled:1
aof_rewrite_in_progress:0
aof_rewrite_scheduled:0
aof_last_rewrite_time_sec:-1
aof_current_rewrite_time_sec:-1
aof_last_bgrewrite_status:ok
aof_last_write_status:ok
aof_current_size:0
aof_base_size:0
aof_pending_rewrite:0
aof_buffer_length:0
aof_rewrite_buffer_length:0
aof_pending_bio_fsync:0
aof_delayed_fsync:0

# Stats
total_connections_received:7
total_commands_processed:1251
instantaneous_ops_per_sec:1
total_net_input_bytes:65484
total_net_output_bytes:38926
instantaneous_input_kbps:0.04
instantaneous_output_kbps:0.00
rejected_connections:0
sync_full:1
sync_partial_ok:0
sync_partial_err:0
expired_keys:0
evicted_keys:0
keyspace_hits:0
keyspace_misses:0
pubsub_channels:0
pubsub_patterns:0
latest_fork_usec:147
migrate_cached_sockets:0

# Replication
role:master
connected_slaves:1
slave0:ip=172.16.57.55,port=16379,state=online,offset=1695,lag=0
master_repl_offset:1695
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:2
repl_backlog_histlen:1694

# CPU
used_cpu_sys:0.83
used_cpu_user:0.50
used_cpu_sys_children:0.00
used_cpu_user_children:0.00

# Commandstats
cmdstat_ping:calls=5,usec=4,usec_per_call=0.80
cmdstat_psync:calls=1,usec=352,usec_per_call=352.00
cmdstat_replconf:calls=1214,usec=2285,usec_per_call=1.88
cmdstat_info:calls=5,usec=241,usec_per_call=48.20
cmdstat_cluster:calls=26,usec=7002,usec_per_call=269.31

# Cluster
cluster_enabled:1

# Keyspace
连接方式
我们连接到集群中的任意一个结点,启动redis-cli时要加-c选项
[root@T2 data]# redis-cli -c -h 172.16.57.55 -p 6380
172.16.57.55:6380> set foo fafa
-> Redirected to slot [12182] located at 172.16.57.56:6385
OK
172.16.57.56:6385> set foo1 fafa1
-> Redirected to slot [13431] located at 172.16.57.55:6384
OK
172.16.57.55:6384> get foo
-> Redirected to slot [12182] located at 172.16.57.56:6385
"fafa"
redis-cli根据指示,不断在6379,6381,6382,6383,6384.......等等。重定向跳转。如果启动时不加-c选项的话,就能看到以错误形式显示出的MOVED重定向消息









  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值