三、redis集群搭建
系列导航
环境:centos7
需要的安装包: redis-4.0.10.tar.gz
说明:如下演示环境都在一台服务器上,生产环境需要放在多台服务器上使用
安装步骤
1、安装包解压
拷贝redis-4.0.10.tar.gz 到/opt目录下
cd /opt
tar -xzvf redis-4.0.10.tar.gz
2、编译
[root]# cd /opt/redis-4.0.10
[root]# make
3、修改配置文件
cd /opt/redis-4.0.10
mkdir 7001
mkdir 7002
mkdir 7003
mkdir 7004
mkdir 7005
mkdir 7006
创建配置文件(其他redis_7002.conf,redis_7003.conf, redis_7004.conf, redis_7005.conf,redis_7006.conf配置文件照样例创建)
vi redis_7001.conf
#添加如下内容:
port 7001
bind 127.0.0.1
#关闭保护模式
protected-mode no
port 7001
tcp-backlog 511
timeout 0
tcp-keepalive 300
#开启守护进程模式
daemonize yes
supervised no
#修改pidfile指向路径
pidfile /opt/redis-4.0.10/7001/redis.pid
loglevel verbose
logfile "/opt/redis-4.0.10/7001/redis_log.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir ./
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-disable-tcp-nodelay no
slave-priority 100
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-lazy-flush no
appendonly yes
appendfilename "appendonly.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-7001.conf
cluster-node-timeout 5000
slowlog-max-len 128
latency-monitor-threshold 0
notify-keyspace-events ""
hash-max-ziplist-entries 512
hash-max-ziplist-value 64
list-max-ziplist-size -2
list-compress-depth 0
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
4、启动redis
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7001.conf
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7002.conf
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7003.conf
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7004.conf
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7005.conf
[root@minio4 redis-4.0.10]# /opt/redis-4.0.10/src/redis-server /opt/redis-4.0.10/redis_7006.conf
5、ruby安装(这个很讨厌)
[root@minio4 ~]# rpm -qa | grep ruby
[root@minio4 ~]# yum install ruby
ruby安装后是2.0版本需要升级到3.0版(需要和redis的版本匹配,本利redis4.0版)
如何升级参考如下道友写的博客亲测有用
https://www.cnblogs.com/name-lizonglin/p/12069114.html
6、创建集群
[root@minio4 src]# cd /opt/redis-4.0.10/src
[root@minio4 src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006
>>> Creating cluster
>>> Performing hash slots allocation on 6 nodes...
Using 3 masters:
127.0.0.1:7001
127.0.0.1:7002
127.0.0.1:7003
Adding replica 127.0.0.1:7005 to 127.0.0.1:7001
Adding replica 127.0.0.1:7006 to 127.0.0.1:7002
Adding replica 127.0.0.1:7004 to 127.0.0.1:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: ef2efc3117d9da0a399cba785ecc0b3e000fdfe6 127.0.0.1:7001
slots:0-5460 (5461 slots) master
M: 276d90d980c5db413f65abe761c68c12429906a3 127.0.0.1:7002
slots:5461-10922 (5462 slots) master
M: 7bdbb165ac29d6bd803be1d69a122800a2803bd9 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
S: 0cac24e2a8891b24a33974e239873c4ee7a7167f 127.0.0.1:7004
replicates 7bdbb165ac29d6bd803be1d69a122800a2803bd9
S: 4612663207fc597112cc5f9211c9b75b393fa717 127.0.0.1:7005
replicates ef2efc3117d9da0a399cba785ecc0b3e000fdfe6
S: d1098bdc5d592f2269603765c4b75f30d899c9b4 127.0.0.1:7006
replicates 276d90d980c5db413f65abe761c68c12429906a3
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 127.0.0.1:7001)
M: ef2efc3117d9da0a399cba785ecc0b3e000fdfe6 127.0.0.1:7001
slots:0-5460 (5461 slots) master
1 additional replica(s)
M: 7bdbb165ac29d6bd803be1d69a122800a2803bd9 127.0.0.1:7003
slots:10923-16383 (5461 slots) master
1 additional replica(s)
M: 276d90d980c5db413f65abe761c68c12429906a3 127.0.0.1:7002
slots:5461-10922 (5462 slots) master
1 additional replica(s)
S: d1098bdc5d592f2269603765c4b75f30d899c9b4 127.0.0.1:7006
slots: (0 slots) slave
replicates 276d90d980c5db413f65abe761c68c12429906a3
S: 0cac24e2a8891b24a33974e239873c4ee7a7167f 127.0.0.1:7004
slots: (0 slots) slave
replicates 7bdbb165ac29d6bd803be1d69a122800a2803bd9
S: 4612663207fc597112cc5f9211c9b75b393fa717 127.0.0.1:7005
slots: (0 slots) slave
replicates ef2efc3117d9da0a399cba785ecc0b3e000fdfe6
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
7、测试集群
[root@minio4 7001]# cd /opt/redis-4.0.10/src
[root@minio4 src]# ./redis-cli -c -h localhost -p 7001
localhost:7001> set foo bar
-> Redirected to slot [12182] located at 127.0.0.1:7003
OK
127.0.0.1:7003> set hello world
-> Redirected to slot [866] located at 127.0.0.1:7001
OK
127.0.0.1:7001>
cluster info :打印集群的信息
cluster nodes :列出集群当前已知的所有节点( node),以及这些节点的相关信息
如下:
127.0.0.1:7003> cluster nodes
7bdbb165ac29d6bd803be1d69a122800a2803bd9 127.0.0.1:7003@17003 myself,master - 0 1620472701000 3 connected 10923-16383
4612663207fc597112cc5f9211c9b75b393fa717 127.0.0.1:7005@17005 slave ef2efc3117d9da0a399cba785ecc0b3e000fdfe6 0 1620472701000 5 connected
ef2efc3117d9da0a399cba785ecc0b3e000fdfe6 127.0.0.1:7001@17001 master - 0 1620472701000 1 connected 0-5460
0cac24e2a8891b24a33974e239873c4ee7a7167f 127.0.0.1:7004@17004 slave 7bdbb165ac29d6bd803be1d69a122800a2803bd9 0 1620472702285 4 connected
d1098bdc5d592f2269603765c4b75f30d899c9b4 127.0.0.1:7006@17006 slave 276d90d980c5db413f65abe761c68c12429906a3 0 1620472702584 6 connected
276d90d980c5db413f65abe761c68c12429906a3 127.0.0.1:7002@17002 master - 0 1620472701284 2 connected 5461-10922
127.0.0.1:7003> 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:3
cluster_stats_messages_ping_sent:634
cluster_stats_messages_pong_sent:662
cluster_stats_messages_meet_sent:4
cluster_stats_messages_sent:1300
cluster_stats_messages_ping_received:660
cluster_stats_messages_pong_received:638
cluster_stats_messages_meet_received:2
cluster_stats_messages_received:1300
到此集群搭建成功
如果后期集群不好用之后彻底恢复
cd /opt/redis-4.0.10
rm -f appendonly.aof dump.rdb nodes-7001.conf nodes-7002.conf nodes-7003.conf nodes-7004.conf nodes-7005.conf nodes-7006.conf
然后重建集群
[root@minio4 src]# cd /opt/redis-4.0.10/src
[root@minio4 src]# ./redis-trib.rb create --replicas 1 127.0.0.1:7001 127.0.0.1:7002 127.0.0.1:7003 127.0.0.1:7004 127.0.0.1:7005 127.0.0.1:7006

三、redis集群搭建的更多相关文章
- Redis集群搭建的三种方式
一.Redis主从 1.1 Redis主从原理 和MySQL需要主从复制的原因一样,Redis虽然读取写入的速度都特别快,但是也会产生性能瓶颈,特别是在读压力上,为了分担压力,Redis支持主从复制. ...
- Redis集群搭建 三主三从
Redis集群介绍 Redis 是一个开源的 key-value 存储系统,由于出众的性能,大部分互联网企业都用来做服务器端缓存.Redis在3.0版本之前只支持单实例模式 虽然支持主从模式,哨兵模式 ...
- Redis 集群搭建详细指南
先有鸡还是先有蛋? 最近有朋友问了一个问题,说毕业后去大城市还是小城市?去大公司还是小公司?我的回答都是大城市!大公司! 为什么这么说呢,你想一下,无论女孩男孩找朋友都喜欢找个子高胸大的.同样的道理嘛 ...
- 二、redis集群搭建
redis集群搭建 redis3.0后支持集群.集群中应该至少有三个节点,每个节点有一备份节点.需要6台服务器.搭建伪分布式,需要6个redis实例.搭建集群的步骤: 一.安装单机版redis 第一步 ...
- redis集群搭建及注意事项
上一篇:redis的安装及注意事项 这里,在一个Linux虚拟机上搭建6个节点的redis伪集群,思路很简单,一台虚拟机上开启6个redis实例,每个redis实例有自己的端口.这样的话,相当于模拟出 ...
- Linux Redis集群搭建与集群客户端实现(Python)
硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...
- [转载] Redis集群搭建最佳实践
转载自http://blog.csdn.net/sweetvvck/article/details/38315149?utm_source=tuicool 要搭建Redis集群,首先得考虑下面的几个问 ...
- Linux Redis集群搭建与集群客户端实现
硬件环境 本文适用的硬件环境如下 Linux版本:CentOS release 6.7 (Final) Redis版本: Redis已经成功安装,安装路径为/home/idata/yangfan/lo ...
- redis集群搭建及设置账户(转)
Redis集群搭建以及为集群设置密码 介绍安装环境与版本 用两台虚拟机模拟6个节点,一台机器3个节点,创建出3 master.3 salve 环境. redis 采用 redis-3.2.4 版本. ...
- redis 集群搭建: redis-cluster
前言 redis数据存储在内存中, 就会受到内存的限制, 大家都知道, 一台电脑, 硬盘可以有1T, 但是内存, 没有听说有1T的内存吧. 那如果数据非常多, 超过一台电脑的内存空间, 怎么办呢? 正 ...
随机推荐
- [AGC024F] Simple Subsequence Problem
Problem Statement You are given a set $S$ of strings consisting of 0 and 1, and an integer $K$. Find ...
- Spring Cache + Caffeine的整合与使用
前言 对于一些项目里需要对数据库里的某些数据一直重复请求的,且这些数据基本是固定的,在这种情况下,可以借助简单使用本地缓存来缓存这些数据.这些介绍一下Spring Cache和Caffeine的使用. ...
- 解决URLEncoder.encode 编码空格变 + 号
jdk自带的URL编码工具类 URLEncoder 在对字符串进行URI编码的时候,会把空格编码为 + 号. 空格的URI编码其实是:%20 解决办法:对编码后的字符串,进行 + 号替换为 %20.总 ...
- 介绍一款轻量型 Web SCADA 组态软件
随着互联网.物联网技术的快速发展,图扑物联基于多年研发积累和私有部署实践打磨.以及对业务场景的深入理解,推出了适用于物联网应用场景的轻量型云组态软件. 该产品采用 B/S 架构,提供 Web 管理 ...
- 反转数组、打印数组元素、加强(增强)for循环
package com.guoba.array; public class Demo04 { public static void main(String[] args) { int[] arr = ...
- parameterType的用法
在mybatis映射接口的配置中,有select,insert,update,delete等元素都提到了parameterType的用法,parameterType为输入参数,在配置的时候,配置相应的 ...
- MinIO客户端之license
MinIO提供了一个命令行程序mc用于协助用户完成日常的维护.管理类工作. 官方资料 mc license mc license info mc license register mc license ...
- 春秋云镜 - CVE-2022-32991
靶标介绍: 该CMS的welcome.php中存在SQL注入攻击. 访问页面,先注册,使用邮箱加密码登录. bp抓包,后台挂上sqlipy然后去测welcome.php,常用的语句都没成功但过一会就有 ...
- Plant-Earth-wp
Earth 信息收集 开放了80,443 只能访问到443,试了试msf里面frado的远古rce都不成功.然后注意到有域名解析 添加到hosts里面再访问,当前页面有几串密文,经尝试在message ...
- python脚本抢大麦网演唱会门票 ---保姆级教程 python脚本抢大麦网演唱会门票
python脚本抢大麦网演唱会门票 流程: 1.下载并安装anaconda:https://repo.continuum.io/archive/ 下载对应linux/mac/windows版本 2.下 ...