redis安装过程:

redis6.2.6安装与学习_wtl1992的博客-CSDN博客_redis6安装1、redis在Linux上的安装github地址:Releases · redis/redis · GitHubhttps://github.com/redis/redis/releases下载后,解压:yum install -y gcc然后:cd redis-6.2.6makemake install PREFIX=/data/soft/redis-6.2.6make的时候报错:致命错误:jemalloc/jemalloc.h:没有那个文件或目录解https://blog.csdn.net/wtl1992/article/details/121727360

主机分配:

主机IP
192.168.233.201
192.168.233.202
192.168.233.203
192.168.233.204
192.168.233.205
192.168.233.206

所有IP主机进行以下操作:

编辑redis.conf:

启动redis-server:

/etc/init.d/redis_init_script start

然后:

在其中一个主机节点上运行:

 ./redis-cli -a wtl1992 --cluster create  192.168.233.201:6379 192.168.233.202:6379 192.168.233.203:6379 192.168.233.204:6379 192.168.233.205:6379  192.168.233.206:6379 --cluster-replicas 1
[root@192 bin]# ./redis-cli -a wtl1992 --cluster create  192.168.233.201:6379 192.168.233.202:6379 192.168.233.203:6379 192.168.233.204:6379 192.168.233.205:6379  192.168.233.206:6379 --cluster-replicas 1
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica 192.168.233.205:6379 to 192.168.233.201:6379
Adding replica 192.168.233.206:6379 to 192.168.233.202:6379
Adding replica 192.168.233.204:6379 to 192.168.233.203:6379
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379slots:[0-5460] (5461 slots) master
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379slots:[5461-10922] (5462 slots) master
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379slots:[10923-16383] (5461 slots) master
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379replicates c6b66129b403c69d8a4cdefba835d230e642bd1b
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379replicates a3af0897c202515165659b21478405c01b87e2af
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379replicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
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.233.201:6379)
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379slots: (0 slots) slavereplicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379slots: (0 slots) slavereplicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379slots: (0 slots) slavereplicates c6b66129b403c69d8a4cdefba835d230e642bd1b
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

检查健康状态:

 ./redis-cli -a wtl1992 --cluster  check 192.168.233.202:6379

check后面的IP可以是以上的IP中的一个。

集群连接:

./redis-cli -c -a wtl1992 -h 192.168.233.202 -p 6379

查看状态:

./redis-cli -a wtl1992 cluster nodes

-a 是auth的意思,意思是授权密码。

——————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

动态添加一对主从节点:

主机IP
192.168.233.207
192.168.233.208

查看状态:

./redis-cli -a wtl1992 cluster nodes

-a 是auth的意思,意思是授权密码。

添加一组集群节点:

方法:先添加主节点,然后添加从节点

添加主节点:

redis-cli --cluster add-node 新节点IP:端口 已存在节点IP:端口 
./redis-cli -a wtl1992 --cluster add-node 192.168.233.207:6379 192.168.233.205:6379
[root@192 bin]# ./redis-cli -a wtl1992 --cluster add-node 192.168.233.207:6379 192.168.233.205:6379
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.233.207:6379 to cluster 192.168.233.205:6379
>>> Performing Cluster Check (using node 192.168.233.205:6379)
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379slots: (0 slots) slavereplicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379slots: (0 slots) slavereplicates c6b66129b403c69d8a4cdefba835d230e642bd1b
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379slots: (0 slots) slavereplicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.233.207:6379 to make it join the cluster.
[OK] New node added correctly.

添加新节点 (添加从节点):

--slave:设置该参数,则新节点以slave的角色加入集群 
--master-id:这个参数需要设置了--slave才能生效,--master-id用来指定新节点的master节点。如果不设置该参数,则会随机为节点选择master节点。

./redis-cli -a wtl1992 --cluster add-node  新节点IP地址:端口    存在节点IP:端口 --cluster-slave --cluster-master-id (master节点的ID)
./redis-cli -a wtl1992 --cluster add-node 192.168.233.208:6379 192.168.233.207:6379 --cluster-slave  --cluster-master-id 68df4ed4c8798625124bc13ce9671d4f6f85b345
[root@192 bin]# ./redis-cli -a wtl1992 --cluster add-node 192.168.233.208:6379 192.168.233.207:6379 --cluster-slave  --cluster-master-id 68df4ed4c8798625124bc13ce9671d4f6f85b345
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Adding node 192.168.233.208:6379 to cluster 192.168.233.207:6379
>>> Performing Cluster Check (using node 192.168.233.207:6379)
M: 68df4ed4c8798625124bc13ce9671d4f6f85b345 192.168.233.207:6379slots: (0 slots) master
M: c6b66129b403c69d8a4cdefba835d230e642bd1b 192.168.233.203:6379slots:[10923-16383] (5461 slots) master1 additional replica(s)
S: 9a06ce836fcebe0f4ebc484d08b3004dba8f2b2d 192.168.233.206:6379slots: (0 slots) slavereplicates 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f
M: a3af0897c202515165659b21478405c01b87e2af 192.168.233.201:6379slots:[0-5460] (5461 slots) master1 additional replica(s)
M: 0cf2ceea1abb9b85efa261bb95d4bd0936a2333f 192.168.233.202:6379slots:[5461-10922] (5462 slots) master1 additional replica(s)
S: 2a35c451b8dcc2a14cd2144e57d284af98c1cc22 192.168.233.205:6379slots: (0 slots) slavereplicates a3af0897c202515165659b21478405c01b87e2af
S: 6f1cb55e71c696c1d5147bdfc9bbb1bed2d44313 192.168.233.204:6379slots: (0 slots) slavereplicates c6b66129b403c69d8a4cdefba835d230e642bd1b
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Send CLUSTER MEET to node 192.168.233.208:6379 to make it join the cluster.
Waiting for the cluster to join>>> Configure node as replica of 192.168.233.207:6379.
[OK] New node added correctly.

上面新增的master和slave不能分片,所以要重新集群内平衡!!!

rebalance平衡集群节点slot数量:

语法:

rebalance       host:port--weight <arg>--auto-weights--threshold <arg>--use-empty-masters--timeout <arg>--simulate--pipeline <arg>host:port:这个是必传参数,用来从一个节点获取整个集群信息,相当于获取集群信息的入口。
--weight <arg>:节点的权重,格式为node_id=weight,如果需要为多个节点分配权重的话,需要添加多个--weight <arg>参数,即--weight b31e3a2e=5 --weight 60b8e3a1=5,node_id可为节点名称的前缀,只要保证前缀位数能唯一区分该节点即可。没有传递–weight的节点的权重默认为1。
--auto-weights:这个参数在rebalance流程中并未用到。
--threshold <arg>:只有节点需要迁移的slot阈值超过threshold,才会执行rebalance操作。具体计算方法可以参考下面的rebalance命令流程的第四步。
--use-empty-masters:rebalance是否考虑没有节点的master,默认没有分配slot节点的master是不参与rebalance的,设置--use-empty-masters可以让没有分配slot的节点参与rebalance。
--timeout <arg>:设置migrate命令的超时时间。
--simulate:设置该参数,可以模拟rebalance操作,提示用户会迁移哪些slots,而不会真正执行迁移操作。
--pipeline <arg>:与reshar的pipeline参数一样,定义cluster getkeysinslot命令一次取出的key数量,不传的话使用默认值为10。
./redis-cli -a wtl1992 --cluster rebalance 192.168.233.207:6379 --cluster-threshold 1 --cluster-use-empty-masters --cluster-pipeline 10
[root@192 bin]# ./redis-cli -a wtl1992 --cluster rebalance 192.168.233.207:6379 --cluster-threshold 1 --cluster-use-empty-masters --cluster-pipeline 10
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing Cluster Check (using node 192.168.233.207:6379)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Rebalancing across 4 nodes. Total weight = 4.00
Moving 1366 slots from 192.168.233.202:6379 to 192.168.233.207:6379
######################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving 1365 slots from 192.168.233.201:6379 to 192.168.233.207:6379
#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################
Moving 1365 slots from 192.168.233.203:6379 to 192.168.233.207:6379
#####################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################################

—————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————————

从集群彻底删除节点:

查看状态:

./redis-cli -a wtl1992 cluster nodes

从集群中移除 node_id 指定的节点:

redis-cli cluster forget 68df4ed4c8798625124bc13ce9671d4f6f85b345返回
OK### 从集群中删除节点
del-node可以把某个节点从集群中删除。del-node只能删除没有分配slot的节点。删除命令传递两个参数:host:port:从该节点获取集群信息。
node_id:需要删除的节点id。redis-cli cluster del-node 192.168.233.207:6379  68df4ed4c8798625124bc13ce9671d4f6f85b345

redis三主三从部署集群以及动态添加节点和删除节点相关推荐

  1. Docker 三剑客-------docker swam,visualizer监控、stack部署集群、Portainer可视化

    Docker 三剑客-------docker swam.visualizer监控.stack部署集群.Portainer可视化 文章目录 Docker 三剑客-------docker swam.v ...

  2. Redis三主三从集群搭建(三台机器)

    介绍 redis三种模式 一.主从模式 Redis虽然读取写入的速度都特别快,但是也会产生读压力特别大的情况.为了分担读压力,Redis支持主从复制,Redis的主从结构可以采用一主多从或者级联结构. ...

  3. Redis搭建集群,三主三从集群模式

    几种常见的redis集群模式: 方案一:主从复制 优点: 支持主从复制,主机会自动将数据同步到从机,可以进行读写分离 为了分载Master的读操作压力,Slave服务器可以为客户端提供只读操作的服务, ...

  4. 手把手搭建redis集群-三台虚拟机(三主三从)

    Redis集群环境搭建: Redis 集群简介: Redis 是一个开源的 key-value 分布式存储系统,由于其出众的性能,大部分互联网企业将其用来作为服务端分布式缓存使用.Redis 在 3. ...

  5. 两台服务器安装redis集群_redis 集群搭建,小白也能搭三主三从的集群环境

    redis集群简介: Redis集群是一个程序集,它提供在多个 Redis节点之间共享数据. 一个 Redis集群不支持同时处理多个键的 Redis命令,因为这要求将数据移动到多个节点之间,这会降低 ...

  6. Redis三主三从集群搭建

    一.引子 主从复制以及哨兵,他们可以提高读的并发,但是单个master容量有限,数据达到一定程度会有瓶颈,这个时候可以通过水平扩展为多master-slave集群(看原理图). 所以一起来学习redi ...

  7. redis相关的详细介绍,包括三主三从集群的搭建

    文章目录 1. 数据结构 1.1 String 1.2 hash 3. 如何搭建redis集群 3.2 哈希槽 1.4 LIST 1.5 SET 1.6 Redis HyperLogLog 1. 数据 ...

  8. Docker高级篇笔记(七)在docker里面进行redis三主三从的集群案例搭建步骤

    目录 搭建三主三从集群 数据读写存储 主从容错的切换迁移 主从扩容 主从缩容 搭建三主三从集群 1 先启动docker 2 拉取redis镜像 3 创建6个redis容器 docker run -d ...

  9. REDIS三主三从集群搭建笔记(redis版本5.0.8)

    mkdir -p /app/redis tar -zxvf redis-5.0.8.tar.gz -C /app/redis cd /app/redis/redis-5.0.8编译安装: make & ...

最新文章

  1. NSUserDefaults删除整个plist文件
  2. Konstrukt PHP REST框架 教程二
  3. .NET平台相关概念(简单了解)
  4. java 比较算法_JAVA排序算法实现和比较:冒泡,桶,选择,快排,归并
  5. Oracle 监听(Listener) 中 services 说明
  6. 创建vue项目(一)搭建vue-cli、项目文件介绍、简单配置
  7. echarts我常用的参数总结
  8. python基础小白题2
  9. autocomplete的使用
  10. 个人简历中计算机应用能力,年中计算机应用专业个人简历模板.docx
  11. 2020 年,Serverless 将给大前端带来什么样的变化?
  12. 数据可视化网页内容自动抓取工具
  13. 2022年PMP考试安排
  14. 程序上线【起飞检查清单】-让事故和教训转变为实用的清单
  15. 怎样获取网页视频下载链接
  16. 为了不被晒黑,这届年轻人有多拼?| 小红书防晒趋势洞察
  17. 教你用 Python 快速批量转换 HEIC 文件
  18. Android视频播放器ExoPlayer
  19. 子集生成的两种方法 (增量构造法 和 位向量法)
  20. 第三章 Elasticsearch Query DSL -- 查询

热门文章

  1. 云上中国年,阿里云CDN猪年春节高峰流量再创新高
  2. Win10 U盘插入无法识别,显示(脱机,签名冲突),解决办法
  3. php 安装fileinfo扩展
  4. git合并commit
  5. 2022年阿里云新春特惠活动怎么样?
  6. 2021诺诺百度搜索指数批量查询工具【免验证码】
  7. cyq.data 连接mysql_cyq.data 常见使用方法
  8. 零基础学习3D建模:14个建模小技巧!零基础入门必备!
  9. mysql 字符编码查询
  10. 一个在校大学生和我的Email交流,希望能引起共鸣和思考~~纯属交流~~