首先部署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. 浅谈log4j-3-不同输出样式

    public static void main(String[] args) { Logger logger=Logger.getLogger(Appendable.class); //设置输出等级 ...

  2. postgresql的基本使用,以及数据库的备份与恢复

    安装过程没什么说的,基本是一直下一步下一步,就是中间需要输入密码之类的 postgresql使用模式是数据库表,视图等的集合,我们可以自荐创建一个schema 创建表的方法 进入sql命令行窗口的方法 ...

  3. Cassandra如何保证数据最终一致性

    Cassandra如何保证数据最终一致性:1.逆熵机制(Anti-Entropy)使用默克尔树(Merkle Tree)来确认多个副本数据一致,对于不一致数据,根据时间戳来获取最新数据. 2.读修复机 ...

  4. HotSpot VM GC 的种类

    collector种类 GC在 HotSpot VM 5.0里有四种: incremental (sometimes called train) low pause collector已被废弃,不在介 ...

  5. lnmp安装总结

    1.安装准备 建一个目录用于存放各软件包的压缩文件, 如我把我的源码文件都放在了 /software目录下 切换到/software目录下,执行 wget http://dev.mysql.com/g ...

  6. mysql——创建索引、修改索引、删除索引的命令语句

    查看表中已经存在 index:show index from table_name; 创建和删除索引索引的创建可以在CREATE TABLE语句中进行,也可以单独用CREATE INDEX或ALTER ...

  7. [转载] IIS来搭建一个只能实现基本功能的FTP服务器

    转自  http://blog.sina.com.cn/s/blog_3f7e47f20100haur.html 本文介绍通过win7自带的IIS来搭建一个只能实现基本功能的FTP服务器,第一次装好W ...

  8. ubuntu忘记登录密码解决方法

    1.重启系统,长按Shift键,直到出现下面菜单.选择recovery mode(恢复模式).2.接下来会进入如下界面,选择Drop to root shell prompt ,也就是获取root权限 ...

  9. 《JavaScript设计模式与开发》笔记 3.call和apply

    1.改变this指向 2.Function.prototype.bind 3.借用其他对象方法 1.借用实现继承 2.实现恶心的 Array.prototype.push.call Array.pro ...

  10. php each和list的用法

    each与list的用法(PHP学习) 1.each的用法 先看API array each ( array &$array ) api里是这么描述的:each — 返回数组中当前的键/值对并 ...