redis 3.0.7 cluster 集群部署

本文涉及的产品
云数据库 Tair(兼容Redis),内存型 2GB
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
简介:

一、环境描述

DB:redis 3.0.7 最新稳定版

OS:centos 6.6_x64


二、安装步骤

1.基本软件包安装

[root@mysql-121 ~]# yum -y install ruby

[root@mysql-121 ~]# yum -y install rubygems

下载路径,上传到/tmp路径下

https://rubygems.org/gems/redis/versions/3.0.0

[root@mysql-121 ~]# cd /tmp

[root@mysql-121 tmp]# ls

orbit-gdm  pulse-hnvCTnUHwlDW  pulse-ua8DXn7r5gA8  redis-3.0.0.gem

[root@mysql-121 tmp]# gem install -l redis-3.0.0.gem

[root@mysql-121 tmp]# cd /tmp

[root@mysql-121 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

[root@mysql-121 tmp]# 


2.解压缩

[root@mysql-121 tmp]# tar -zxvf redis-3.0.7.tar.gz

3.编译

[root@mysql-121 tmp]# cd redis-3.0.7

[root@mysql-121 redis-3.0.7]# 

[root@mysql-121 redis-3.0.7]# make

4.安装

[root@mysql-121 redis-3.0.7]# make install 

5.测试

[root@mysql-121 redis-3.0.7]# yum install tcl

[root@mysql-121 redis-3.0.7]# make test 

6.可执行命令统一路径

[root@mysql-121 src]# cd /tmp/redis-3.0.7/src

[root@mysql-121 src]# cp redis-trib.rb /usr/local/bin

[root@mysql-121 src]# cd /usr/local/bin

[root@mysql-121 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.创建目录

[root@mysql-121 bin]# mkdir -p /data/redis/conf

[root@mysql-121 bin]# mkdir -p /data/redis/log

[root@mysql-121 bin]# mkdir -p /data/redis/data


8.配置参数

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6379.conf

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6380.conf

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6381.conf

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6382.conf

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6383.conf

[root@mysql-121 redis-3.0.7]# cp redis.conf /data/redis/conf/redis_6384.conf


[root@mysql-121 redis-3.0.7]# cd /data/redis/conf/

[root@mysql-121 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.启动集群相关节点(必须是空节点)

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6379.conf 

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6380.conf   

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6381.conf  

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6382.conf  

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6383.conf  

[root@mysql-121 conf]# redis-server /data/redis/conf/redis_6384.conf 

[root@mysql-121 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)构建集群

[root@mysql-121 ~]# redis-trib.rb help

[root@mysql-121 ~]# 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.检查集群状态

 

[root@mysql-121 ~]# 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.登陆集群

[root@mysql-121 ~]# 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 











本文转自 roidba 51CTO博客,原文链接:http://blog.51cto.com/roidba/1877894,如需转载请自行联系原作者
相关实践学习
基于Redis实现在线游戏积分排行榜
本场景将介绍如何基于Redis数据库实现在线游戏中的游戏玩家积分排行榜功能。
云数据库 Redis 版使用教程
云数据库Redis版是兼容Redis协议标准的、提供持久化的内存数据库服务,基于高可靠双机热备架构及可无缝扩展的集群架构,满足高读写性能场景及容量需弹性变配的业务需求。 产品详情:https://www.aliyun.com/product/kvstore     ------------------------------------------------------------------------- 阿里云数据库体验:数据库上云实战 开发者云会免费提供一台带自建MySQL的源数据库 ECS 实例和一台目标数据库 RDS实例。跟着指引,您可以一步步实现将ECS自建数据库迁移到目标数据库RDS。 点击下方链接,领取免费ECS&RDS资源,30分钟完成数据库上云实战!https://developer.aliyun.com/adc/scenario/51eefbd1894e42f6bb9acacadd3f9121?spm=a2c6h.13788135.J_3257954370.9.4ba85f24utseFl
目录
相关文章
|
7月前
|
NoSQL Java Redis
Redis进阶-Jedis以及Spring Boot操作 Redis 5.x Cluster
Redis进阶-Jedis以及Spring Boot操作 Redis 5.x Cluster
112 0
|
6月前
|
存储 运维 NoSQL
Redis Cluster集群模式部署
Redis Cluster集群模式部署
128 4
|
7月前
|
存储 监控 负载均衡
redis 集群 (主从复制 哨兵模式 cluster)
redis 集群 (主从复制 哨兵模式 cluster)
|
4月前
|
存储 NoSQL 算法
深入理解Redis分片Cluster原理
本文深入探讨了Redis Cluster的分片原理,作为Redis官方提供的高可用性和高性能解决方案,Redis Cluster通过数据分片和横向扩展能力,有效降低单个主节点的压力。
深入理解Redis分片Cluster原理
|
4月前
|
缓存 NoSQL 网络协议
【Azure Redis 缓存】Azure Redis Cluster 在增加分片数时失败分析
【Azure Redis 缓存】Azure Redis Cluster 在增加分片数时失败分析
|
4月前
|
缓存 NoSQL Redis
【Azure Redis 缓存】Windows版创建 Redis Cluster 实验 (精简版)
【Azure Redis 缓存】Windows版创建 Redis Cluster 实验 (精简版)
|
4月前
|
NoSQL Redis
Redis——单机迁移cluster集群如何快速迁移
Redis——单机迁移cluster集群如何快速迁移
153 0
|
7月前
|
存储 NoSQL Redis
docker搭建Redis Cluster集群环境
docker搭建Redis Cluster集群环境
198 1
|
7月前
|
存储 负载均衡 监控
redis 集群模式(redis cluster)介绍
redis 集群模式(redis cluster)介绍
|
7月前
|
存储 缓存 运维
软件体系结构 - 缓存技术(5)Redis Cluster
【4月更文挑战第20天】软件体系结构 - 缓存技术(5)Redis Cluster
188 10