Linux环境下Redis集群实践
环境:centos 7
一、编译及安装redis源码
源码地址:redis版本发布列表
cd redis-3.2.8
sudo make && make install
二、创建节点
创建Redis-Cluster 文件夹,并创建7000-7005共6个文件夹

复制源码中的redis.conf文件并修改以下内容后分别放入7000-7005文件夹
【7000】示例
bind 192.168.1.105
port 7000
cluster-enabled yes
cluster-config-file /home/jabben/Redis-Cluster/7000/nodes-7000.conf
pidfile /home/jabben/Redis-Cluster/7000/redis_7000.pid
cluster-node-timeout 5000
daemonize yes
分别启动6个Redis节点:
redis-server 7000/redis.conf
redis-server 7001/redis.conf
redis-server 7002/redis.conf
redis-server 7003/redis.conf
redis-server 7004/redis.conf
redis-server 7005/redis.conf
查看redis进程是否已经启动:
ps -ef | grep redis

三、创建集群
复制redis-trib.rb文件到bin目录下
cd /home/jabben/Redis-Cluster/Source/redis-3.2./src
sudo cp redis-trib.rb /usr/local/bin/
安装ruby环境
yum install ruby
安装rubygems组件
yum install rubygems
安装gem-redis
gem install redis
创建集群
redis-trib.rb create --replicas 192.168.1.105: 192.168.1.105: 192.168.1.105: 192.168.1.105: 192.168.1.105: 192.168.1.105:
>>> Creating cluster
>>> Performing hash slots allocation on nodes...
Using masters:
192.168.1.105:
192.168.1.105:
192.168.1.105:
Adding replica 192.168.1.105: to 192.168.1.105:
Adding replica 192.168.1.105: to 192.168.1.105:
Adding replica 192.168.1.105: to 192.168.1.105:
M: 339aafedd6bd7f6bd5cd98407f7ebe8cb0c4efbd 192.168.1.105:
slots:- ( slots) master
M: 7bd0b20971d5fc929f8454c6ff388f780cc70e77 192.168.1.105:
slots:- ( slots) master
M: aaa4b5109c5bcf1aa868621f59b51fb4d6feef9c 192.168.1.105:
slots:- ( slots) master
S: e731c1918fad61f972fbca4ab6523da1d9f827af 192.168.1.105:
replicates 339aafedd6bd7f6bd5cd98407f7ebe8cb0c4efbd
S: c16b520a5075b0fee0840cc26cf1f7f27bad8e45 192.168.1.105:
replicates 7bd0b20971d5fc929f8454c6ff388f780cc70e77
S: 990a4e7a2831d8d9ba8f9835557be6a394d393a4 192.168.1.105:
replicates aaa4b5109c5bcf1aa868621f59b51fb4d6feef9c
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.1.105:)
M: 339aafedd6bd7f6bd5cd98407f7ebe8cb0c4efbd 192.168.1.105:
slots:- ( slots) master
additional replica(s)
S: 990a4e7a2831d8d9ba8f9835557be6a394d393a4 192.168.1.105:
slots: ( slots) slave
replicates aaa4b5109c5bcf1aa868621f59b51fb4d6feef9c
S: e731c1918fad61f972fbca4ab6523da1d9f827af 192.168.1.105:
slots: ( slots) slave
replicates 339aafedd6bd7f6bd5cd98407f7ebe8cb0c4efbd
M: aaa4b5109c5bcf1aa868621f59b51fb4d6feef9c 192.168.1.105:
slots:- ( slots) master
additional replica(s)
S: c16b520a5075b0fee0840cc26cf1f7f27bad8e45 192.168.1.105:
slots: ( slots) slave
replicates 7bd0b20971d5fc929f8454c6ff388f780cc70e77
M: 7bd0b20971d5fc929f8454c6ff388f780cc70e77 192.168.1.105:
slots:- ( slots) master
additional replica(s)
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All slots covered.
至此集群搭建完毕
四、测试
使用redis-cli客户端连接到刚创建的集群
redis-cli -c -h 192.168.1.105 -p
查询集群相关信息
192.168.1.105:> CLUSTER INFO
cluster_state:ok
cluster_slots_assigned:
cluster_slots_ok:
cluster_slots_pfail:
cluster_slots_fail:
cluster_known_nodes:
cluster_size:
cluster_current_epoch:
cluster_my_epoch:
cluster_stats_messages_sent:
cluster_stats_messages_received:
【数据写入测试】
192.168.1.105:> set name zhangsan
-> Redirected to slot [] located at 192.168.1.105:
OK
192.168.1.105:> get name
"zhangsan"
【集群线性扩展】
待完善
【失效转移】
待完善
五、集群相关常用命令
链接:https://redis.io/commands
CLUSTER INFO 打印集群的信息
CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息。
//节点
CLUSTER MEET <ip> <port> 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。
CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。
CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。
CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。
CLUSTER ADDSLOTS <slot> [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。
CLUSTER DELSLOTS <slot> [slot ...] 移除一个或多个槽对当前节点的指派。
CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。
CLUSTER SETSLOT <slot> NODE <node_id> 将槽 slot 指派给 node_id 指定的节点。
CLUSTER SETSLOT <slot> MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。
CLUSTER SETSLOT <slot> IMPORTING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。
CLUSTER SETSLOT <slot> STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。
//键
CLUSTER KEYSLOT <key> 计算键 key 应该被放置在哪个槽上。
CLUSTER COUNTKEYSINSLOT <slot> 返回槽 slot 目前包含的键值对数量。
CLUSTER GETKEYSINSLOT <slot> <count> 返回 count 个 slot 槽中的键。
//新增
CLUSTER SLAVES node-id 返回一个master节点的slaves 列表
Linux环境下Redis集群实践的更多相关文章
- Linux环境下Hadoop集群搭建
Linux环境下Hadoop集群搭建 前言: 最近来到了武汉大学,在这里开始了我的研究生生涯.昨天通过学长们的耐心培训,了解了Hadoop,Hdfs,Hive,Hbase,MangoDB等等相关的知识 ...
- Windows及Linux环境搭建Redis集群
一.Windows环境搭建Redis集群 参考资料:Windows 环境搭建Redis集群 二.Linux环境搭建Redis集群 参考资料:Redis Cluster的搭建与部署,实现redis的分布 ...
- Linux环境下SolrCloud集群环境搭建关键步骤
Linux环境下SolrCloud集群环境搭建关键步骤. 前提条件:已经完成ZooKeeper集群环境搭建. 一.下载介质 官网下载地址:http://www.apache.org/dyn/close ...
- Linux环境下HDFS集群环境搭建关键步骤
Linux环境下HDFS集群环境搭建关键步骤记录. 介质版本:hadoop-2.7.3.tar.gz 节点数量:3节点. 一.下载安装介质 官网下载地址:http://hadoop.apache.or ...
- Linux环境下ZooKeeper集群环境搭建关键步骤
ZooKeeper版本:zookeeper-3.4.9 ZooKeeper节点:3个节点 以下为Linux环境下ZooKeeper集群环境搭建关键步骤: 前提条件:已完成在Linux环境中安装JDK并 ...
- Linux环境下nginx集群搭建
#确保安装nginx,stream模块默认不安装的,需要手动添加参数:–with-stream, nginx1.9或以上版本 #nginx.conf文件中,添加以下内容(只供参考),这个不能放在htt ...
- linux环境(CentOS-6.7)下redis集群的搭建全过程
linux环境下redis集群的搭建全过程: 使用mount命令将光盘挂载到/mnt/cdrom目录下: [root@hadoop03 ~]# mount -t iso9660 -o ro /dev/ ...
- Linux 下Redis集群安装部署及使用详解(在线和离线两种安装+相关错误解决方案)
一.应用场景介绍 本文主要是介绍Redis集群在Linux环境下的安装讲解,其中主要包括在联网的Linux环境和脱机的Linux环境下是如何安装的.因为大多数时候,公司的生产环境是在内网环境下,无外网 ...
- CentOS下redis集群安装
环境: 一台CentOS虚拟机上部署六个节点,创建3个master,3个slave节点 1.下载并解压 cd /root wget http://download.redis.io/releases/ ...
随机推荐
- Virtualbox下克隆CentOS 网络配置
Virtualbox下克隆虚拟机非常容易,也使得我们在平常搭建测试环境方便了许多.不过克隆以后的虚机并不能够直接联网,这是由于网卡的MAC地址引起的.在"控制->复制"弹出的 ...
- mac book pro macOS10.13.3安装qt、qt creator C++开发环境,qt5.11.1,并解决cmake构建:qt mac this file is not part of any project the code
因为之前在Ubuntu下使用的是qtcreator开发,现在想在mac上装一个系统,因为许久未装了,还是花了点时间,不如写个博客,下次就更快安装了.在Mac OS X下使用Qt开发,需要配置Qt库和编 ...
- unfortunately,*********** has stopped及卸载模拟器上的多余不用apk
虽然不知道是怎么了,但是项目进不去了,害的我一脸雾水,百度了下好像没什么人遇到过这问题,都没找到解决办法,那只好来个简单粗暴的,卸载重新安装apk ,希望有大神知道原因和其他方法的欢迎留言或者评价给出 ...
- LocalDate的使用
LocalDate的一些使用方法 今天半天的时间都用在了LocalDate上,然后呢,也是自己的第一次写博客. 首先来看看会用上的方法吧. 两个构造器,用的是静态工厂方法 static Local ...
- 安装setuptools 报错缺少zlib
# yum install zlib # yum install zlib-devel 下载成功后,进入python2.7的目录,重新执行 #make #make install 此时先前执行的 软连 ...
- MMU二级页表
https://blog.csdn.net/forDreamYue/article/details/78887035
- Beyond Compare 4 提示错误“这个授权密钥已被吊销”的解决办法
错误提示: 这个授权密钥已被吊销. 解决方法: 删除以下目录中的所有文件即可. C:\Users\Administrator\AppData\Roaming\Scooter Software\Beyo ...
- 关于HTML5中的sessionStorage的会话级缓存使用
sessionStorage作为HTML5的Web Storage的两种存储方式之一. 用于本地存储一个会话(session)中的数据,这些数据只有在同一个会话中的页面才能访问并且当会话结束后数 ...
- centos7 端口3306无法连接问题
MySQL建用户的时候会指定一个host,默认是127.0.0.1/localhost,那么这个用户就只能本机访问,其它机器用这个用户帐号访问会提示没有权限,host改为%,表示允许所有机器访问. G ...
- Oracle lag()/lead() over()分析函数
with tmp as(select '1' id ,'aa' name ,'22' age from dual union allselect '2' id ,'bb' name ,'20' age ...