首先部署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. 《DSP using MATLAB》Problem 5.27

    代码: %% +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ %% Outp ...

  2. 【liunx】时间处理函数

    一.脚本示例 [mylinuxaccount@linux01 ~]$ date +%Y%m%d 20171224 [mylinuxaccount@linux01 ~]$ date +%F 2017-1 ...

  3. 几种常见的微服务架构方案简述——ZeroC IceGrid、Spring Cloud、基于消息队列

    微服务架构是当前很热门的一个概念,它不是凭空产生的,是技术发展的必然结果.虽然微服务架构没有公认的技术标准和规范草案,但业界已经有一些很有影响力的开源微服务架构平台,架构师可以根据公司的技术实力并结合 ...

  4. Java数组逆序排列

    //逆序排列原理 /* A: 数组逆序原理* a: 题目分析* 通过观察发现,本题目要实现原数组元素倒序存放操作.即原数组存储元素为{12,69,852,25,89,588},逆序后为原数组存储元素变 ...

  5. day 55 jQuery 之事件 绑定等

    属性选择器: [attribute] [attribute=value]// 属性等于 列入 $("input[value='male']").prop('chekced') 注意 ...

  6. 创建一个简单的terraform module

      terraform module可以实现代码的复用,同时方便分享,下面创建一个简单的基于localfile && template provider 的module module ...

  7. microcks 微服务mocks 工具&&运行时

    microcks 是一个方便的微服务mock 工具,我们可以用来mock request.response,同时获取api 的服务契约,microcks 支持的部署模式也比较多,docker-comp ...

  8. drone 1.0 新功能试用以及说明

    drone 1.0 rc 已经发布,新的功能很强大,界面比旧版本更加人性化,和git 的集成也更高了 测试环境准备 试用gogs 做为git 管理工具 docker-compose 文件 versio ...

  9. 一般化数值算法(accumluate,inner_product,partial_sum,adjacent_difference)

    accumulate template<class InputIterator, class T> T accumulate( InputIterator _First, InputIte ...

  10. 学习笔记:Javascript 变量 包装对象

    学习笔记:Javascript 变量 包装对象 如下代码,可以输出字符的长度. var str = "Tony"; str.length; 这时再试试以下代码,返回是 undefi ...