redis3.0.7 cluster 集群部署
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了redis3.0.7 cluster 集群部署相关的知识,希望对你有一定的参考价值。
一、环境描述
DB:redis 3.0.7 最新稳定版
OS:centos 6.6_x64
二、安装步骤
1.基本软件包安装
[[email protected] ~]# yum -y install ruby
[[email protected] ~]# yum -y install rubygems
下载路径,上传到/tmp路径下
https://rubygems.org/gems/redis/versions/3.0.0
[[email protected] ~]# cd /tmp
[[email protected] tmp]# ls
orbit-gdm pulse-hnvCTnUHwlDW pulse-ua8DXn7r5gA8 redis-3.0.0.gem
[[email protected] tmp]# gem install -l redis-3.0.0.gem
[[email protected] tmp]# cd /tmp
[[email protected] tmp]# ll
total 1360
drwx------ 2 gdm gdm 4096 Sep 1 09:13 orbit-gdm
drwx------. 2 gdm gdm 4096 Sep 1 09:13 pulse-hnvCTnUHwlDW
drwx------. 2 root root 4096 Aug 1 17:07 pulse-ua8DXn7r5gA8
drwxrwxr-x 6 root root 4096 Jan 25 2016 redis-3.0.7
-rw-r--r-- 1 root root 1375200 Nov 25 10:01 redis-3.0.7.tar.gz
[[email protected] tmp]#
2.解压缩
[[email protected] tmp]# tar -zxvf redis-3.0.7.tar.gz
3.编译
[[email protected] tmp]# cd redis-3.0.7
[[email protected] redis-3.0.7]#
[[email protected] redis-3.0.7]# make
4.安装
[[email protected] redis-3.0.7]# make install
5.测试
[[email protected] redis-3.0.7]# yum install tcl
[[email protected] redis-3.0.7]# make test
6.可执行命令统一路径
[[email protected] src]# cd /tmp/redis-3.0.7/src
[[email protected] src]# cp redis-trib.rb /usr/local/bin
[[email protected] src]# cd /usr/local/bin
[[email protected] bin]# ll
total 15968
-rwxr-xr-x 1 root root 4587299 Nov 29 17:43 redis-benchmark
-rwxr-xr-x 1 root root 22177 Nov 29 17:43 redis-check-aof
-rwxr-xr-x 1 root root 45387 Nov 29 17:43 redis-check-dump
-rwxr-xr-x 1 root root 4696506 Nov 29 17:43 redis-cli
lrwxrwxrwx 1 root root 12 Nov 29 17:43 redis-sentinel -> redis-server
-rwxr-xr-x 1 root root 6469255 Nov 29 17:43 redis-server
-rwxr-xr-x 1 root root 60527 Nov 29 17:55 redis-trib.rb
7.创建目录
[[email protected] bin]# mkdir -p /data/redis/conf
[[email protected] bin]# mkdir -p /data/redis/log
[[email protected] bin]# mkdir -p /data/redis/data
8.配置参数
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6379.conf
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6380.conf
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6381.conf
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6382.conf
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6383.conf
[[email protected] redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6384.conf
[[email protected] redis-3.0.7]# cd /data/redis/conf/
[[email protected] conf]# grep -v -E ‘(^#|^$)‘ redis_6379.conf
vi redis_6379.conf
##########general##########
daemonize yes
pidfile /data/redis/data/redis_6379.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile "/data/redis/log/redis_6379.log"
##########rdb##########
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 /data/redis/data/
##########slave##########
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
##########aof##########
appendonly yes
appendfilename "appendonly_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##########
lua-time-limit 5000
##########cluster##########
cluster-enabled yes
cluster-config-file nodes_6379.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-migration-barrier 1
cluster-require-full-coverage no
##########slowlog##########
slowlog-log-slower-than 10000
slowlog-max-len 128
##########optimize##########
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
###########################################
vi redis_6379.conf 替换 :%s/6379/6380
vi redis_6379.conf 替换 :%s/6379/6381 以此类推
三、创建集群
1.启动集群相关节点(必须是空节点)
[[email protected] conf]# redis-server /data/redis/conf/redis_6379.conf
[[email protected] conf]# redis-server /data/redis/conf/redis_6380.conf
[[email protected] conf]# redis-server /data/redis/conf/redis_6381.conf
[[email protected] conf]# redis-server /data/redis/conf/redis_6382.conf
[[email protected] conf]# redis-server /data/redis/conf/redis_6383.conf
[[email protected] conf]# redis-server /data/redis/conf/redis_6384.conf
[[email protected] conf]# ps -ef |grep redis
root 7702 1 0 18:36 ? 00:00:00 redis-server *:6379 [cluster]
root 7708 1 0 18:37 ? 00:00:00 redis-server *:6380 [cluster]
root 7712 1 0 18:37 ? 00:00:00 redis-server *:6381 [cluster]
root 7716 1 0 18:37 ? 00:00:00 redis-server *:6382 [cluster]
root 7720 1 0 18:37 ? 00:00:00 redis-server *:6383 [cluster]
root 7724 1 0 18:37 ? 00:00:00 redis-server *:6384 [cluster]
2.使用自带的ruby工具(redis-trib.rb)构建集群
[[email protected] ~]# redis-trib.rb help
[[email protected] ~]# redis-trib.rb create --replicas 1 192.168.80.121:6379 192.168.80.121:6380 192.168.80.121:6381 192.168.80.121:6382 192.168.80.121:6383 192.168.80.121:6384
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
192.168.80.121:6379
192.168.80.121:6380
192.168.80.121:6381
Adding replica 192.168.80.121:6382 to 192.168.80.121:6379
Adding replica 192.168.80.121:6383 to 192.168.80.121:6380
Adding replica 192.168.80.121:6384 to 192.168.80.121:6381
M: b2e0265c1ae983c339eaa362235455d3cc54a025 192.168.80.121:6379
slots:0-5460 (5461 slots) master
M: dedffe5ad37787d4cad6cc2d2426ba4d504b3c44 192.168.80.121:6380
slots:5461-10922 (5462 slots) master
M: e6af78beb2457fa34b9530c7e11d6caeac579732 192.168.80.121:6381
slots:10923-16383 (5461 slots) master
S: 41ca12c81e4acd7212b550904e8050c9b604734c 192.168.80.121:6382
replicates b2e0265c1ae983c339eaa362235455d3cc54a025
S: 3e3afb6769c4bdfbd8373f058dc54f18baeba585 192.168.80.121:6383
replicates dedffe5ad37787d4cad6cc2d2426ba4d504b3c44
S: 31feff8d759aa78699d428546b0d775457626ac6 192.168.80.121:6384
replicates e6af78beb2457fa34b9530c7e11d6caeac579732
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 192.168.80.121:6379)
M: b2e0265c1ae983c339eaa362235455d3cc54a025 192.168.80.121:6379
slots:0-5460 (5461 slots) master
M: dedffe5ad37787d4cad6cc2d2426ba4d504b3c44 192.168.80.121:6380
slots:5461-10922 (5462 slots) master
M: e6af78beb2457fa34b9530c7e11d6caeac579732 192.168.80.121:6381
slots:10923-16383 (5461 slots) master
M: 41ca12c81e4acd7212b550904e8050c9b604734c 192.168.80.121:6382
slots: (0 slots) master
replicates b2e0265c1ae983c339eaa362235455d3cc54a025
M: 3e3afb6769c4bdfbd8373f058dc54f18baeba585 192.168.80.121:6383
slots: (0 slots) master
replicates dedffe5ad37787d4cad6cc2d2426ba4d504b3c44
M: 31feff8d759aa78699d428546b0d775457626ac6 192.168.80.121:6384
slots: (0 slots) master
replicates e6af78beb2457fa34b9530c7e11d6caeac579732
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
3.检查集群状态
[[email protected] ~]# redis-trib.rb check 192.168.80.121:6379
>>> Performing Cluster Check (using node 192.168.80.121:6379)
M: b2e0265c1ae983c339eaa362235455d3cc54a025 192.168.80.121:6379
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: e6af78beb2457fa34b9530c7e11d6caeac579732 192.168.80.121:6381
slots:10923-16383 (5461 slots) master
1 additional replica(s)
S: 31feff8d759aa78699d428546b0d775457626ac6 192.168.80.121:6384
slots: (0 slots) slave
replicates e6af78beb2457fa34b9530c7e11d6caeac579732
S: 3e3afb6769c4bdfbd8373f058dc54f18baeba585 192.168.80.121:6383
slots: (0 slots) slave
replicates dedffe5ad37787d4cad6cc2d2426ba4d504b3c44
S: 41ca12c81e4acd7212b550904e8050c9b604734c 192.168.80.121:6382
slots: (0 slots) slave
replicates b2e0265c1ae983c339eaa362235455d3cc54a025
M: dedffe5ad37787d4cad6cc2d2426ba4d504b3c44 192.168.80.121:6380
slots:5461-10922 (5462 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.
4.登陆集群
[[email protected] ~]# redis-cli -c -p 6379
127.0.0.1:6379> cluster info
cluster_state:ok
cluster_slots_assigned:16384
cluster_slots_ok:16384
cluster_slots_pfail:0
cluster_slots_fail:0
cluster_known_nodes:6
cluster_size:3
cluster_current_epoch:6
cluster_my_epoch:1
cluster_stats_messages_sent:1089
cluster_stats_messages_received:1089
127.0.0.1:6379> cluster nodes
e6af78beb2457fa34b9530c7e11d6caeac579732 192.168.80.121:6381 master - 0 1480417102632 3 connected 10923-16383
31feff8d759aa78699d428546b0d775457626ac6 192.168.80.121:6384 slave e6af78beb2457fa34b9530c7e11d6caeac579732 0 1480417101630 6 connected
3e3afb6769c4bdfbd8373f058dc54f18baeba585 192.168.80.121:6383 slave dedffe5ad37787d4cad6cc2d2426ba4d504b3c44 0 1480417102632 5 connected
41ca12c81e4acd7212b550904e8050c9b604734c 192.168.80.121:6382 slave b2e0265c1ae983c339eaa362235455d3cc54a025 0 1480417099627 4 connected
dedffe5ad37787d4cad6cc2d2426ba4d504b3c44 192.168.80.121:6380 master - 0 1480417100630 2 connected 5461-10922
b2e0265c1ae983c339eaa362235455d3cc54a025 192.168.80.121:6379 myself,master - 0 0 1 connected 0-5460
127.0.0.1:6379>
127.0.0.1:6379> cluster slots
1) 1) (integer) 10923
2) (integer) 16383
3) 1) "192.168.80.121"
2) (integer) 6381
4) 1) "192.168.80.121"
2) (integer) 6384
2) 1) (integer) 5461
2) (integer) 10922
3) 1) "192.168.80.121"
2) (integer) 6380
4) 1) "192.168.80.121"
2) (integer) 6383
3) 1) (integer) 0
2) (integer) 5460
3) 1) "192.168.80.121"
2) (integer) 6379
4) 1) "192.168.80.121"
2) (integer) 6382
四、告警处理
1.告警
7702:M 29 Nov 18:36:50.952 # WARNING: The TCP backlog setting of 511 cannot be enforced
because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7702:M 29 Nov 18:36:50.952 # Server started, Redis version 3.0.7
7702:M 29 Nov 18:36:50.952 # WARNING overcommit_memory is set to 0! Background save may fail under low memory condition. To fix this issue add ‘vm.overcommit_memory = 1‘ to /etc/sysctl.conf and then reboot or run the command ‘sysctl vm.overcommit_memory=1‘ for this to take effect.
7702:M 29 Nov 18:36:50.952 # WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis. To fix this issue run the command ‘echo never > /sys/kernel/mm/transparent_hugepage/enabled‘ as root, and add it to your /etc/rc.local in order to retain the setting after a reboot. Redis must be restarted after THP is disabled.
2.处理方法
1)backlog
echo 511 >/proc/sys/net/core/somaxconn
echo "net.core.somaxconn = 511" >> /etc/sysctl.conf
2)overcommit_memory
echo 1 > /proc/sys/vm/overcommit_memory
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf
3)Transparent Huge Pages (THP)
echo never > /sys/kernel/mm/transparent_hugepage/enabled
vi /etc/rc.local
if test -f /sys/kernel/mm/transparent_hugepage/enabled; then
echo never > /sys/kernel/mm/transparent_hugepage/enabled
fi
if test -f /sys/kernel/mm/transparent_hugepage/defrag; then
echo never > /sys/kernel/mm/transparent_hugepage/defrag
fi
sysctl -p
#################################################################################
本文出自 “dba003” 博客,请务必保留此出处http://dba003.blog.51cto.com/12318731/1877891
以上是关于redis3.0.7 cluster 集群部署的主要内容,如果未能解决你的问题,请参考以下文章