Redis5-集群搭建实验
集群规划:
nodeA:192.168.29.22(22-master,23-slave)
nodeB:192.168.29.23(23-master,24-slave)
nodeC:192.168.29.24(24-master,22-slave)
下载:
http://download.redis.io/releases/redis-5.0.7.tar.gz
安装
yum install -y gcc
tar zxvf redis-5.0..tar.gz
mv redis-5.0. /usr/local/redis-5.0.
mkdir /usr/local/redis5
cd /usr/local/redis-5.0./
make
make install PREFIX=/usr/local/redis5
mkdir /usr/local/redis5/conf
mkdir /usr/local/redis5/log
mkdir /usr/local/redis5/data
echo 'export PATH=$PATH:/usr/local/redis5/bin' >> ~/.bash_profile
source ~/.bash_profile
设置开机启动
vim /usr/lib/systemd/system/redis.service
[Unit]
Description=Redis Server
After=network.target [Service]
Type=simple
# User=redis
# Group=redis
PIDFile=/var/run/22m_6379.pid
ExecStart=/usr/local/redis5/bin/redis-server /usr/local/redis5/conf/redis-22m.conf --daemonize no
# ExecStop=/usr/local/redis5/bin/redis-cli shutdown
ExecStop=/usr/local/redis5/bin/redis-cli -p shutdown
Restart=always [Install]
WantedBy=multi-user.target
vim /usr/lib/systemd/system/redisb.service
[Unit]
Description=Redis Server
After=network.target [Service]
Type=simple
# User=redis
# Group=redis
PIDFile=/var/run/23s_7379.pid
ExecStart=/usr/local/redis5/bin/redis-server /usr/local/redis5/conf/redis-23s.conf --daemonize no
# ExecStop=/usr/local/redis5/bin/redis-cli shutdown
ExecStop=/usr/local/redis5/bin/redis-cli -p shutdown
Restart=always [Install]
WantedBy=multi-user.target
systemctl daemon-reload
systemctl start redis
systemctl enable redis
systemctl start redisb
systemctl enable redisb
配置
cp redis.conf /usr/local/redis5/conf/redis-22m.conf
#修改配置文件redis.conf,IP、端口、配置文件类推
192.168.29.22: redis-22m.conf
192.168.29.22: redis-23s.conf
192.168.29.23: redis-23m.conf
192.168.29.23: redis-24s.conf
192.168.29.24: redis-24m.conf
192.168.29.24: redis-22s.conf
vim redis-22m.conf
port # 监听端口(从节点改成7379)
bind 0.0.0.0 # 监听 ip
dir /usr/local/redis5/data-22m # 指定文件存放路径 ( .rdb .aof nodes-xxxx.conf 这样的文件都会在此路径下)
cluster-enabled yes # 启动集群模式
cluster-config-file redis-22m-.conf # 集群节点配置文件
daemonize yes # 后台启动
pidfile /var/run/22m_6379.conf
cluster-node-timeout # 集群节点超时时间
appendonly yes # 指定持久化方式,开启 AOF 模式
protected-mode no # 非保护模式
创建集群
redis-cli --cluster create 192.168.29.22: 192.168.29.23: 192.168.29.24: 192.168.29.23: 192.168.29.24: 192.168.29.22: --cluster-replicas 1
#--replicas 1 表示为集群中的每个主节点创建一个从节点
连接集群
redis-cli -c -h 192.168.29.22 -p
# -c参数为连接集群节点使用,此选项可防止moved和ask异常。
#连接任意节点均可进入集群
查看集群信息
[root@redis-A redis5]# redis-cli -c -h 192.168.29.23
192.168.29.23:> cluster info
cluster_state:ok
cluster_slots_assigned:
cluster_slots_ok:
...........
查看节点信息
192.168.29.23:> cluster nodes
#可展示主从关系
或
[root@redis-A redis5]# redis-cli --cluster check 192.168.29.23:6379
集群崩溃条件:当存活的 Master 节点小于总节点数的一半时
添加master节点
redis-cli --cluster add-node 192.168.30.3: 192.168.29.23:
#192.168..3为新增节点,192.168..23为集群中任意一正常节点,无论主从
新增的节点没有分配slot,需要reshard分配slot
redis-cli --cluster reshard 192.168.29.22:6379
>>> Performing Cluster Check (using node 192.168.29.22:6379)
M: 9dce6a67f400b958692079779420af9008d4424d 192.168.29.22:6379
slots:[0-5460] (5461 slots) master
1 additional replica(s)
......
M: 1a1bb454fce513283392a321147c975713fe6f55 192.168.30.3:6379
slots: (0 slots) master
......
M: 564c09d468dcb372d93ff86e44971aede4748d1f 192.168.29.23:6379
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.
How many slots do you want to move (from 1 to 16384)? 2048 #想要分配的slot数
What is the receiving node ID? 1a1bb454fce513283392a321147c975713fe6f55 #分配给哪个node,这里选新增的节点
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #1: all #从哪些节点分配,这里填all
......
Moving slot 309 from 9dce6a67f400b958692079779420af9008d4424d
......
Do you want to proceed with the proposed reshard plan (yes/no)?yes #选yes
......
Moving slot 11587 from 192.168.29.24:6379 to 192.168.30.3:6379:
......
添加 Slave 节点
redis-cli --cluster add-node 192.168.30.3: 192.168.29.22: --cluster-slave --cluster-master-id 1a1bb454fce513283392a321147c975713fe6f55
#192.168.30.3: 为新增节点;192.168.29.22:6379为集群中任意正常节点;--cluster-master-id指定master节点
如果不指定会随机分配给一个Mater节点
平衡各节点槽数量
新加 Master 节点后各节点的槽可能会分配不均匀,可以重新分配。
#查看slots信息
redis-cli --cluster info 192.168.30.3:
192.168.30.3: (1a1bb454...) -> keys | slots | slaves.
192.168.29.22: (9dce6a67...) -> keys | slots | slaves.
192.168.29.23: (564c09d4...) -> keys | slots | slaves.
192.168.29.24: (ae5b2268...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
#平衡slots
redis-cli --cluster rebalance --cluster-threshold 192.168.30.3:
>>> Performing Cluster Check (using node 192.168.30.3:)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
>>> Rebalancing across nodes. Total weight = 4.00
Moving slots from 192.168.29.24: to 192.168.30.3:
......
#再次查看
redis-cli --cluster info 192.168.30.3:
192.168.30.3: (1a1bb454...) -> keys | slots | slaves.
192.168.29.22: (9dce6a67...) -> keys | slots | slaves.
192.168.29.23: (564c09d4...) -> keys | slots | slaves.
192.168.29.24: (ae5b2268...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
Slave 节点重新分配
redis-cli -c -h 192.168.30.3 -p
192.168.30.3:> cluster replicate 9dce6a67f400b958692079779420af9008d4424d
OK
#(ID为目标Mater节点)
删除节点
slave节点
redis-cli --cluster del-node 192.168.30.3: e34bbd847a135012582a7b2b3259aec2fd7668bd
>>> Removing node e34bbd847a135012582a7b2b3259aec2fd7668bd from cluster 192.168.30.3:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
#ID为slave节点192.168.30.:7379的ID
Master节点
- 如果 Master 节点有 Slave 节点,则首先要将 Slave 节点重新分配到其他 Master 节点或者删除。
- 如果 Master 节点有槽(slot),则需要去掉分配的槽(slot),然后再删除主节点
#查看slot信息
redis-cli --cluster info 192.168.30.3:
192.168.30.3: (1a1bb454...) -> keys | slots | slaves.
192.168.29.22: (9dce6a67...) -> keys | slots | slaves.
192.168.29.23: (564c09d4...) -> keys | slots | slaves.
192.168.29.24: (ae5b2268...) -> keys | slots | slaves.
[OK] keys in masters.
0.00 keys per slot on average.
#将192.168.30.:6379的slots转移到另一个Master节点
redis-cli --cluster reshard 192.168.30.3:
>>> Performing Cluster Check (using node 192.168.30.3:)
M: 1a1bb454fce513283392a321147c975713fe6f55 192.168.30.3:
slots:[-],[-],[-] ( slots) master
M: 9dce6a67f400b958692079779420af9008d4424d 192.168.29.22:
slots:[-] ( slots) master
additional replica(s)
......
M: ae5b2268339d38874cd3da6487c33aace4d24d3a 192.168.29.24:
slots:[-] ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
How many slots do you want to move (from to )? #192.168.30.3:6379的slots的个数
What is the receiving node ID? 9dce6a67f400b958692079779420af9008d4424d #准备接手slots的192.168.29.:6379的ID
Please enter all the source node IDs.
Type 'all' to use all the nodes as source nodes for the hash slots.
Type 'done' once you entered all the source nodes IDs.
Source node #: 1a1bb454fce513283392a321147c975713fe6f55 #192.168.30.3:6379的ID
Source node #: done #没有第二个节点
......
Moving slot from 1a1bb454fce513283392a321147c975713fe6f55
......
Do you want to proceed with the proposed reshard plan (yes/no)? yes
Moving slot from 192.168.30.3: to 192.168.29.22::
#再次查看节点信息可见节点已没有slots
redis-cli -p cluster nodes
9dce6a67f400b958692079779420af9008d4424d 192.168.29.22:@ master - connected - -
564c09d468dcb372d93ff86e44971aede4748d1f 192.168.29.23:@ master - connected -
de62d7694375f615f6d4cfe7af10a3367cac0569 192.168.29.22:@ slave ae5b2268339d38874cd3da6487c33aace4d24d3a connected
2e71ff865f43170d91802f12199a896632e2473e 192.168.29.24:@ slave 564c09d468dcb372d93ff86e44971aede4748d1f connected
ec028f2f4d44ebfad7add0fcbc26f328f2ec55dd 192.168.29.23:@ slave 9dce6a67f400b958692079779420af9008d4424d connected
1a1bb454fce513283392a321147c975713fe6f55 192.168.30.3:@ myself,master - connected
ae5b2268339d38874cd3da6487c33aace4d24d3a 192.168.29.24:@ master - connected - #删除Master节点,ID为要删除的节点ID
redis-cli --cluster del-node 192.168.29.22: 1a1bb454fce513283392a321147c975713fe6f55
>>> Removing node 1a1bb454fce513283392a321147c975713fe6f55 from cluster 192.168.29.22:
>>> Sending CLUSTER FORGET messages to the cluster...
>>> SHUTDOWN the node.
集群升级
升级 Slave 节点
升级 Slave 节点比较简单,只需要停止 Slave 节点,然后升级 Redis 程序,最后重启即可。
升级 Master 节点
升级 Master 节点
1、使用 debug segfault 使 Master 节点发生故障转换为 Slave 节点。
redis-cli -h 192.168.29.22 -p debug segfault
2、然后再照升级 Slave 节点的方法升级此节点。
Redis5-集群搭建实验的更多相关文章
- Linux(Centos7)下redis5集群搭建和使用
1.简要说明 2018年十月 Redis 发布了稳定版本的 5.0 版本,推出了各种新特性,其中一点是放弃 Ruby的集群方式,改为 使用 C语言编写的 redis-cli的方式,是集群的构建方式复杂 ...
- redis5集群搭建步骤
通常情况下为了redis的高可用,我们一般不会使用redis的单实例去运行,一般都会搭建一个 redis 的集群去运行.此处记录一下 redis5 以后 cluster 集群的搭建. 一.需求 red ...
- Keepalived & Lvs集群搭建实验
实验拓扑图: 实验原理: Keepalived 是基于 LVS ,并与 LVS 高度融合的 LVS和keepalived的关系:lvs起的是负载均衡功能,而keepalived则是高可用(热 备)的支 ...
- 基于.NetCore的Redis5.0.3(最新版)快速入门、源码解析、集群搭建与SDK使用【原创】
1.[基础]redis能带给我们什么福利 Redis(Remote Dictionary Server)官网:https://redis.io/ Redis命令:https://redis.io/co ...
- docker实验--redis集群搭建
背景介绍: 我经常在做一些小项目的时候,采用了Redis来做缓存,但是都是基于单节点的,一旦redis挂了,整个项目就挂了.于是乎,想到了多节点集群的方式来使用,就开始折腾着怎么去搭建这个集群.在网上 ...
- Redis5版本集群搭建
一.简介 1.1 Redis是什么 Redis是一个开源的,使用ANSI C 编写,高性能的Key-Value的NoSQL数据库. 1.2 Redis特点 (1)基于内存 (2)可持久化数据 (3)具 ...
- redis5.0.0集群搭建【实战经历】
redis集群搭建 作者:陈土锋 时间:2020年6月2日 目录 一.环境介绍... 1 1.机器准备... 1 2.关闭防护墙和selinux. 1 3.时间同步... 1 二.Redis Clus ...
- redis5.0 Cluster集群搭建
安装redis sudo apt update sudo apt install build-essential tcl cd ~ mkdir document/ cd document/ curl ...
- 【Oracle 集群】Linux下Oracle RAC集群搭建之基本测试与使用(九)
Oracle 11G RAC数据库安装(九) 概述:写下本文档的初衷和动力,来源于上篇的<oracle基本操作手册>.oracle基本操作手册是作者研一假期对oracle基础知识学习的汇总 ...
- (转)高性能网站架构之缓存篇—Redis集群搭建
看过 高性能网站架构之缓存篇--Redis安装配置和高性能网站架构之缓存篇--Redis使用配置端口转发 这两篇文章的,相信你已经对redis有一定的了解,并能够安装上,进行简单的使用了,但是在咱们的 ...
随机推荐
- JS中0.1+0.2!=0.3
在控制台输入0.1+0.2,会得出以下结果 即不等于0.3.下面我们说一下原因. 一.存储原理 1.在计算机中数字无论是定点数还是浮点数都是以多位二进制的方式进行存储的.2.在JS中数字采用的IEEE ...
- Dictionary的基本用法
1.创建泛型哈希表,然后加入元素 Dictionary<string,string> openWith=new Dictionary<string, string>(); op ...
- FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecate;的解决办法
踩坑场景 报错FutureWarning: Passing (type, 1) or '1type' as a synonym of type is deprecate; 解决办法 1.升级numpy ...
- js获取时间及转化
有关Javascript的本地时间获取,下面我直接用代码来进行举例吧 let time = new Date(); let month = time.getMonth()+1; //获取的月份0~11 ...
- element使用
官方网址: 点击 全局使用 1.创建项目 vue init webpack vue-ele 配置 2.安装依赖 npm install 3.安装loader模块(开发) npm install sty ...
- 关于Apache Tomcat 文件包含漏洞(CVE-2020-1938)威胁整改
1.昨天收到关于这个漏洞的整改通告(https://mp.weixin.qq.com/s/qIG_z9imxdLUobviSv7knw),考虑到版本升级可能带来其他问题,所以采用如下方式: 2.用的a ...
- script标签的async和defer
兼容性 IE对于defer一直都支持,async属性IE6-9都没有支持,IE10及以上支持 相同点与不同点 带有async或defer的script都会立刻下载并不阻塞页面解析,而且都提供一个可选的 ...
- super().__init__()方法
class first(object): def __init__(self,age,name): self.age = age self.name = name class second(first ...
- tcp_demo
代码讲解: server import socket def main(): # 创建tcp服务器套接字 tcp_server = socket.socket(socket.AF_INET, sock ...
- SQL Server Varchar 中文乱码问题与使用SQL Server Management Studio管理软件查询出来的字段限制
问题:不管是用varchar 还是nvarchar,插入记录为中文时,都会显示乱码?? 即使建表时指明了某个字段的语言也没用 COLLATE Chinese_PRC_CS_AS_WS 原因:可能是安装 ...