Redis cluster 3.2安装文档

架构方面:

四组,四主四备

第一步:下载

wget http://download.redis.io/releases/redis-3.2.11.tar.gz

第二步:编译安装

系统需要安装

yum install gcc -y

yum install jemalloc-devel  jemalloc -y

yum install readline-devel -y

yum install ruby -y

 

#安装到/usr/local/redis目录

mkdir -p /usr/local/

#编译

tar xzvf redis-3.2.11.tar.gz -C /usr/local/

mkdir -p /usr/local/redis

cd  /usr/local/redis-3.2.11

cd deps

每一个都进行一下make 一下

make PREFIX=/usr/local/redis  install

mkdir -p /usr/local/redis/{log,conf,rdb,run}

cd /usr/local/redis-3.2.11

cp src/redis-trib.rb /usr/local/redis/bin/

gem install -l redis-3.3.5.gem

 

https://rubygems.org/downloads/redis-3.3.5.gem

 

修改系统的配置

启动redis实例前先修改一些系统级别的配置

Vi /etc/rc.local

echo never > /sys/kernel/mm/transparent_hugepage/enabled

# 打开/etc/sysctl.conf,追加如下内容

vm.overcommit_memory = 1

net.core.somaxconn= 1024

#使配置生效

sysctl -p

 

 

配置

bind 0.0.0.0

daemonize yes

pidfile /usr/local/redis/run/redis-6379.pid

port 6379

tcp-backlog 511

timeout 0

tcp-keepalive 0

loglevel notice

logfile "/usr/local/redis/log/redis-6379.log"

databases 16

#save 900 1

#save 300 10

#save 60 10000

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dbfilename dump-6379.rdb

dir /usr/local/redis/rdb

slave-serve-stale-data yes

slave-read-only yes

repl-diskless-sync no

repl-diskless-sync-delay 5

repl-disable-tcp-nodelay no

slave-priority 100

#appendonly yes

appendfilename "redis-6379.aof"

appendfsync everysec

no-appendfsync-on-rewrite no

auto-aof-rewrite-percentage 100

auto-aof-rewrite-min-size 64mb

aof-load-truncated yes

lua-time-limit 5000

cluster-enabled yes

cluster-config-file nodes-6379.conf

cluster-node-timeout 15000

slowlog-log-slower-than 10000

slowlog-max-len 128

latency-monitor-threshold 0

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

hll-sparse-max-bytes 3000

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

maxmemory 12000000000   #最大内存使用率

maxmemory-policy volatile-lru  #则删冷数据

 

maxmemory:12000000000

maxmemory_human:11.18G

maxmemory_policy:volatile-lru

 

cd  /usr/local/redis/bin/redis-server /usr/local/redis/conf/redis.conf

./redis-server  /usr/local/redis/conf/redis.conf

./redis-server  /usr/local/redis/conf/redis.conf

./redis-server  /usr/local/redis/conf/redis.conf

./redis-server  /usr/local/redis/conf/redis.conf

./redis-server  /usr/local/redis/conf/redis.conf

./redis-server   /usr/local/redis/conf/redis.conf

 

创建集群:

./redis-trib.rb create  10.0.0.71:6379 10.0.0.72:6379  10.0.0.73:6379

 

 

10.1.235.185:6383 10.1.235.185:6384 10.1.235.185:6385 10.1.235.185:6386

 

/root/redis-3.0.3/src/redis-trib.rb create 10.1.235.185:6381 10.1.235.185:6382 10.1.235.185:6383

 

/root/redis-3.0.3/src/redis-trib.rb add-node --slave --master-id 74407797c0120dcdc4141c11313c9e89d3ea9da2 10.1.235.185:6384 10.1.235.185:6381

 

/root/redis-3.0.3/src/redis-trib.rb add-node 10.1.235.185:6382 10.1.235.185:6381

 

/root/redis-3.0.3/src/redis-trib.rb del-node 10.1.235.185:6382(集群任意节点) db6374e57fda139711d4f9e70b9e0ca72314368a

(若db6374e57fda139711d4f9e70b9e0ca72314368a这个节点已经挂掉,这个命令删不掉这个节点,会报此节点在集群中不存在,需要使用 cluster forget命令把此节点删除)

 

/root/redis-3.0.3/src/redis-trib.rb check 10.1.235.185:6381(集群任意节点)

 

/root/redis-3.0.3/src/redis-trib.rb fix 10.1.235.185:6381(集群任意节点)

 

master分配槽位:echo -e "500\n${newId}\nall\nyes"|/root/redis-3.0.3/src/redis-trib.rb reshard $newNode(任意节点即可)

slave拷贝master(变成slave):/root/redis-3.0.3/src/redis-cli -h 10.1.238.8 -p ${newPort} cluster replicate ${oldmasterId}

 

/root/redis-3.0.3/src/redis-trib.rb reshard --from all --to 02c4ff22093ba0ba9c79f01e1d81376a5961bcba --slots 100 --yes 10.1.235.185:6381

 

./redis-trib.rb reshard --from <node-id> --to <node-id> --slots <number of slots> --yes <host>:<port>

 

./redis-trib.rb add-node --slave --master-id 3c3a0c74aae0b56170ccb03a76b60cfe7dc1912e 127.0.0.1:7006 127.0.0.1:7000

 

/root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6381 get name

 

/root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6383 shutdown

 

/root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6383 cluster nodes

 

/root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6381 bgrewriteaof

 

/root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6381 cluster forget 11157fc40e2696e87acf7fb92cf8354936af08d6

(forget后面是需要删除的node id,必须通知集群中的每个节点forget这个节点,即连接每个节点执行cluster forget命令才可以,否则1分钟后这个节点会被重新添加到集群中,并且是handshake状态)

 

 

docker run -itd --name r_restore_test1 -v /root/redis/cluster/6481:/etc/redis/data --net=host redis:dcp_1.0

 

 

1fc13f4b537eb390b1a052cdc85c0728fa4a8173 10.1.238.8:6384 slave f059f45e50588cfdf1f6bdfc2e24a54702b2792a 0 1449204613525 4 connected

d5e2b9f2d0f0f3cc392a9373bfa0b2007e5d7aa1 10.1.238.8:6387 master - 0 1449204608016 7 connected 0-1364 5461-6826 10923-12287

c56b12ca9c373fbde9154c432ec18ddfb3f5d431 10.1.238.8:6386 slave f839ee0ccb7c1ace6a0803f03551032a9af1756d 0 1449204612022 6 connected

f839ee0ccb7c1ace6a0803f03551032a9af1756d 10.1.238.8:6383 master - 0 1449204610019 3 connected 12288-16383

899ec6a5cdc9a71898115a8cc7a2b6f593d311e7 10.1.238.8:6385 slave ac85b53a736be5440832576f35764fdd82f91df6 0 1449204609019 5 connected

f059f45e50588cfdf1f6bdfc2e24a54702b2792a 10.1.238.8:6381 master - 0 1449204613024 1 connected 1365-5460

db6374e57fda139711d4f9e70b9e0ca72314368a 10.1.238.8:6388 slave d5e2b9f2d0f0f3cc392a9373bfa0b2007e5d7aa1 0 1449204611020 7 connected

ac85b53a736be5440832576f35764fdd82f91df6 10.1.238.8:6382 myself,master - 0 0 2 connected 6827-10922

 

 

[root@ai185 ~]# /root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6481 cluster nodes

LOADING Redis is loading the dataset in memory

 

 

[root@ai185 data]# /root/redis-3.0.3/src/redis-cli -c -h ai185 -p 6481 cluster nodes

0817fc4fa5ecb688c9a7154b9911a15e3439accf 10.1.235.185:6481 myself,master - 0 0 4 connected 0-16383

aaba740dae057dd39066ca70137a4a0b7a65b2a2 10.1.235.185:6482 master - 1450077515614 1450077510822 2 connected

c37e1e7ae7990c2773d1468efdec4c03ae9df965 10.1.235.185:6483 master - 1450077515614 1450077510822 3 connected

 

 

 

192.168.206.110:6379

192.168.206.111:6379  

192.168.206.112:6379

统计Redis实例每秒的处理能力

 

 

 

监控:

Redis监控:

第一:端口死活:

Redis  6379

第二:cpu使用率

redis-cli info:下面二个大于90告警

used_cpu_sys:

used_cpu_user:

 

第三:内存

系统内存使用率高于60%告警

 

第四:集群节点个数,根据集群有几个节点来判断

redis-cli cluster nodes 小于3告警

本站公众号
   欢迎关注本站公众号,获取更多程序园信息
开发小院