首先部署redis-5.0.3,请参考我的另一篇文章

https://www.cnblogs.com/djlsunshine/p/10592174.html

启动redis服务

# redis-server /root/redis-5.0.3/redis.conf

[root@localhost ~]# redis-server /root/redis-5.0./redis.conf
:C Mar ::01.274 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::01.274 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::01.274 # Configuration loaded

查看进程

# ps aux | grep redis

[root@localhost ~]# ps aux | grep redis
root 0.0 0.4 ? Ssl : : redis-server 192.168.2.80:
root 0.0 0.0 pts/ S+ : : grep --color=auto redis

创建6个节点

# mkdir cluster-test

# cd cluster-test/

# mkdir 7000 7001 7002 7003 7004 7005

[root@localhost redis-5.0.]# mkdir cluster-test
[root@localhost redis-5.0.]#
[root@localhost redis-5.0.]# ls
-RELEASENOTES cluster-test COPYING dump.rdb Makefile README.md runtest runtest-sentinel src utils
BUGS CONTRIBUTING deps INSTALL MANIFESTO redis.conf runtest-cluster sentinel.conf tests
[root@localhost redis-5.0.]#
[root@localhost redis-5.0.]# cd cluster-test/
[root@localhost cluster-test]#
[root@localhost cluster-test]# mkdir
[root@localhost cluster-test]# ls

分别在这6个节点文件夹下写入redis配置文件

以节点7000为例

port                           //端口7000,7002,7003
daemonize yes //redis后台运行
bind 192.168.2.80 //设置节点的IP
requirepass 123456 //设置连接节点的密码
appendfilename "appendonly.aof" //aof模式持久化文件的名字(appendonly默认是no,yes就是打开aof持久化)
pidfile /var/run/redis_7000.pid //pidfile文件对应7000,7002,7003
cluster-enabled yes //开启集群
cluster-config-file nodes_7000.conf //集群的配置 配置文件首次启动自动生成 7000,7001,7002
cluster-node-timeout //请求超时 设置5秒够了
appendonly yes //aof日志开启 有需要就开启,它会每次写操作都记录一条日志

启动各节点

[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::32.393 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::32.393 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::32.393 # Configuration loaded
[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::37.603 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::37.603 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::37.603 # Configuration loaded
[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::41.394 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::41.394 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::41.394 # Configuration loaded
[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::44.487 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::44.487 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::44.487 # Configuration loaded
[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::26.168 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::26.168 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::26.168 # Configuration loaded
[root@localhost ~]#
[root@localhost ~]# redis-server redis-5.0./cluster-test//redis.conf
:C Mar ::31.677 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
:C Mar ::31.677 # Redis version=5.0., bits=, commit=, modified=, pid=, just started
:C Mar ::31.677 # Configuration loaded
[root@localhost ~]#

查看进程信息

[root@localhost ~]# ps aux | grep redis
root 0.2 0.4 ? Ssl Mar25 : redis-server 192.168.2.80:
root 0.1 0.4 ? Ssl : : redis-server *: [cluster]
root 0.1 0.4 ? Ssl : : redis-server *: [cluster]
root 0.1 0.4 ? Ssl : : redis-server *: [cluster]
root 0.1 0.4 ? Ssl : : redis-server *: [cluster]
root 0.2 0.4 ? Ssl : : redis-server *: [cluster]
root 0.1 0.4 ? Ssl : : redis-server *: [cluster]
root 0.0 0.0 pts/ R+ : : grep --color=auto redis

集群创建

# redis-cli --cluster create 127.0.0.1:7000 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 --cluster-replicas 1

# redis-cli -a 123456 --cluster create 192.168.2.80:7000 192.168.2.80:7001 192.168.2.80:7002 192.168.2.80:7003 192.168.2.80:7004 192.168.2.80:7005 --cluster-replicas 1

--cluster-replicas 1(每个创建的主服务器都有一个从服)

[root@localhost ~]# redis-cli -a  --cluster create 192.168.2.80: 192.168.2.80: 192.168.2.80: 192.168.2.80: 192.168.2.80: 192.168.2.80: --cluster-replicas
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
>>> Performing hash slots allocation on nodes...
Master[] -> Slots -
Master[] -> Slots -
Master[] -> Slots -
Adding replica 192.168.2.80: to 192.168.2.80:
Adding replica 192.168.2.80: to 192.168.2.80:
Adding replica 192.168.2.80: to 192.168.2.80:
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 69f17d424b855c3e18265d2c807a7b8e1ad9328d 192.168.2.80:
slots:[-] ( slots) master
M: d59b01f910c2adb972bd380ec07458e1866a248d 192.168.2.80:
slots:[-] ( slots) master
M: 137f1ccf4be0c6479e76befd6b96a72dd642ce75 192.168.2.80:
slots:[-] ( slots) master
S: 83bf3a15381bd624669b3e7f964b1ce26a87e619 192.168.2.80:
replicates 137f1ccf4be0c6479e76befd6b96a72dd642ce75
S: df8c31bc9c417571aa38745349607a366309d208 192.168.2.80:
replicates 69f17d424b855c3e18265d2c807a7b8e1ad9328d
S: 70193c889ce1ea1a4fbd811c101af3208691264f 192.168.2.80:
replicates d59b01f910c2adb972bd380ec07458e1866a248d
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.2.80:)
M: 69f17d424b855c3e18265d2c807a7b8e1ad9328d 192.168.2.80:
slots:[-] ( slots) master
additional replica(s)
M: d59b01f910c2adb972bd380ec07458e1866a248d 192.168.2.80:
slots:[-] ( slots) master
additional replica(s)
S: 70193c889ce1ea1a4fbd811c101af3208691264f 192.168.2.80:
slots: ( slots) slave
replicates d59b01f910c2adb972bd380ec07458e1866a248d
M: 137f1ccf4be0c6479e76befd6b96a72dd642ce75 192.168.2.80:
slots:[-] ( slots) master
additional replica(s)
S: df8c31bc9c417571aa38745349607a366309d208 192.168.2.80:
slots: ( slots) slave
replicates 69f17d424b855c3e18265d2c807a7b8e1ad9328d
S: 83bf3a15381bd624669b3e7f964b1ce26a87e619 192.168.2.80:
slots: ( slots) slave
replicates 137f1ccf4be0c6479e76befd6b96a72dd642ce75
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.

查看redis监听端口

# netstat -tnlp | grep redis

[root@localhost ~]# netstat -tnlp | grep redis
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 192.168.2.80: 0.0.0.0:* LISTEN /redis-server
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp 0.0.0.0: 0.0.0.0:* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *
tcp6 ::: :::* LISTEN /redis-server *

查看集群节点的常用参数

# redis-cli --cluster help

[root@localhost ~]# redis-cli --cluster help
Cluster Manager Commands:
create host1:port1 ... hostN:portN
--cluster-replicas <arg>
check host:port
--cluster-search-multiple-owners
info host:port
fix host:port
--cluster-search-multiple-owners
reshard host:port
--cluster-from <arg>
--cluster-to <arg>
--cluster-slots <arg>
--cluster-yes
--cluster-timeout <arg>
--cluster-pipeline <arg>
--cluster-replace
rebalance host:port
--cluster-weight <node1=w1...nodeN=wN>
--cluster-use-empty-masters
--cluster-timeout <arg>
--cluster-simulate
--cluster-pipeline <arg>
--cluster-threshold <arg>
--cluster-replace
add-node new_host:new_port existing_host:existing_port
--cluster-slave
--cluster-master-id <arg>
del-node host:port node_id
call host:port command arg arg .. arg
set-timeout host:port milliseconds
import host:port
--cluster-from <arg>
--cluster-copy
--cluster-replace
help For check, fix, reshard, del-node, set-timeout you can specify the host and port of any working node in the cluster. [root@localhost ~]#

官方文档地址:

https://redis.io/topics/cluster-tutorial

参考文章:

https://www.cnblogs.com/yuanermen/p/5717885.html

redis-5.0.3集群搭建的更多相关文章

  1. Redis 5.0.5集群搭建

    Redis 5.0.5集群搭建 一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):s ...

  2. Redis 3.0.2集群搭建以及相关问题汇总

    Redis3 正式支持了 cluster,是为了解决构建redis集群时的诸多不便 (1)像操作单个redis一样操作key,不用操心key在哪个节点上(2)在线动态添加.删除redis节点,不用停止 ...

  3. 转:Redis 3.2.1集群搭建

    Redis 3.2.1集群搭建   一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2) ...

  4. Redis单机安装以及集群搭建

    今天主要来看一下Redis的安装以及集群搭建(我也是第一次搭建). 环境:CentOS 7.1,redis-5.0.7 一.单机安装 1.将Redis安装包放置服务器并解压 2.进入redis安装目录 ...

  5. Redis 3.0 Cluster集群配置

    Redis 3.0 Cluster集群配置 安装环境依赖 安装gcc:yum install gcc 安装zlib:yum install zib 安装ruby:yum install ruby 安装 ...

  6. 配置redis 4.0.11 集群

    配置redis 4.0.11 集群 准备redis 软件和redis配置文件 启动Redis服务 /data/soft/redis/src/redis-check-aof --fix /log/red ...

  7. 分布式缓存技术redis学习系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)

    本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...

  8. Redis 3.2.1集群搭建

    一.概述 Redis3.0版本之后支持Cluster. 1.1.redis cluster的现状 目前redis支持的cluster特性: 1):节点自动发现 2):slave->master ...

  9. 分布式缓存技术redis学习(四)——redis高级应用(集群搭建、集群分区原理、集群操作)

    本文是redis学习系列的第四篇,前面我们学习了redis的数据结构和一些高级特性,点击下面链接可回看 <详细讲解redis数据结构(内存模型)以及常用命令> <redis高级应用( ...

  10. java_redis3.0.3集群搭建

    redis3.0版本之后支持Cluster,具体介绍redis集群我就不多说,了解请看redis中文简介. 首先,直接访问redis.io官网,下载redis.tar.gz,现在版本3.0.3,我下面 ...

随机推荐

  1. js---通配符选择器

    原味转自:http://blog.sina.com.cn/s/blog_6e001be701017kaz.html 1.选择器 (1)通配符: $("input[id^='code']&qu ...

  2. C++中的继承和多继承

    一.学习笔记 1.继承 class Student : public Person { ... } 2.继承时权限派生类中可以直接访问父类的protected成员,但是不能访问其private成员,若 ...

  3. Modern Data Lake with Minio : Part 2

    转自: https://blog.minio.io/modern-data-lake-with-minio-part-2-f24fb5f82424 In the first part of this ...

  4. 如何让你的 KiCad 在缩放时不眩晕?

    如何让你的 KiCad 在缩放时不眩晕? 使用 KiCAD 第一感觉是打开速度非常快,而且 PCB 拉线也非常快,封装库又多. 但有一个问题,缩放时总给人一种眩晕,原来是因为鼠标自动跑到屏幕中间去了, ...

  5. Spring Boot 历史

    2012年10月,Mike Youngstrom在Spring jira中创建了一个功能需求,要求在Spring框架中支持无容器Web应用程序体系结构.他建议通过main方法引导的Spring容器内配 ...

  6. 我对 前端 Js 开发方式 架构方向 的 一些看法

    有 网友 提到 : “复杂的页面,一个页面加载的模块多,各种异步请求,页面渲染,jquery链式编程操作dom数过于频繁.现在的前台越来越复杂,逻辑臃肿.” 哎, 所以 我说, 要改成用 同步调用 . ...

  7. redis设计与实现-数据结构

    1,redis存储有5种数据对象,有7种数据结构底层实现 2,sds简单字符串 不直接使用字符数组或是string 封装了长度变量,加快获得字符串长度 杜绝缓冲区溢出(拼接字符串的时候不会因为内存里连 ...

  8. Mongo导出mongoexport和导入mongoimport介绍

    最近爬取mobike和ofo单车数据,需要存储在csv文件中,因为设计的程序没有写存储csv文件的方法,为了偷懒所以就继续存储到了MongoDB中.恰好MongoDB支持导出的数据可以是csv文件和j ...

  9. SQL2008:WITH MOVE 子句可用于重新定位一个或多个文件

    sql2008数据库 还原备份文件还原产生这个错误的原因是:还原目录下存在多个同名文件, 如图所示,只需要将第2个以及以后的mdf文件改成其它名字就行了,比如s.mdf,s1.mdf等等.

  10. Spring Cloud(Dalston.SR5)--Eureka 注册中心高可用-服务提供和消费

    由于 Eureka 注册中心只是在内存中保存服务注册实例,并且没有将服务注册实例进行同步,因此我们需要对服务提供和消费进行调整,需要指定服务提供和消费的注册.服务发现的具体Eureka 注册中心配置, ...