Redis5.0版本以上安装Redis单机多实例集群
2023-09-14 08:57:34 时间
1.下载地址: http://www.redis.cn/download.html 2. 解压:
tar -zxvf redis-5.0.5.tgz
cd redis-5.0.5/
mkdir redis-cluster
cd redis-cluster
mkdir 7001 7002 7003 7004 7005 7006
3.修改配置文件
port 7001
cluster-enabled yes
cluster-config-file 7001.conf
cluster-node-timeout 5000
appendonly yes
修改好一个配置文件将其copy到 7001 —— 7006的每一个文件中,注意:修改每一个文件的端口号
4. 启动实例 :
vim redis-cluster-start.sh
redis-server /usr/local/redis-cluster/7001/redis.conf
redis-server /usr/local/redis-cluster/7002/redis.conf
redis-server /usr/local/redis-cluster/7003/redis.conf
redis-server /usr/local/redis-cluster/7004/redis.conf
redis-server /usr/local/redis-cluster/7005/redis.conf
redis-server /usr/local/redis-cluster/7006/redis.conf
设置可执行权限,并执行
chmod 777 redis-cluster-start.sh
./redis-cluster-start.sh
5. 创建集群
redis-cli --cluster create 192.168.75.130:7001 192.168.75.130:7002 192.168.75.130:7003 192.168.75.130:7004 192.168.75.130:7005 192.168.75.130:7006 --cluster-replicas 1
6.连接集群
root@ubuntu:/home/song# redis-cli -c -h 192.168.75.130 -p 7001
192.168.75.130:7001>
7.查看集群节点:
192.168.75.130:7001> cluster nodes
d76081af88b93f8a0fac9aa7d0b6ffd17b6b828a 192.168.75.130:7001@17001 myself,slave 1e1dd73067d05da1c0f0e21dbfd8d6b159a939ed 0 1569243825000 1 connected
3ea5e4740f60d3a98fc212ca07e76387c6781de1 192.168.75.130:6379@16379 slave 2f5915eeebec20192de7ce855d7fb9babcad369b 0 1569243824000 2 connected
1e1dd73067d05da1c0f0e21dbfd8d6b159a939ed 192.168.75.130:7004@17004 master - 0 1569243824000 7 connected 0-5460
9b614e352a24b51c9f196159e5e42718f82472d9 192.168.75.130:7006@17006 slave f5e00df5c63181ecc911ea8e457f7f58b661178e 0 1569243824000 6 connected
2f5915eeebec20192de7ce855d7fb9babcad369b 192.168.75.130:7002@17002 master - 0 1569243825558 2 connected 5461-10922
f5e00df5c63181ecc911ea8e457f7f58b661178e 192.168.75.130:7003@17003 master - 0 1569243823749 3 connected 10923-16383
2d267501b538930e3577f63e0e7e1a4b674caabc 192.168.75.130:7005@17005 slave 2f5915eeebec20192de7ce855d7fb9babcad369b 0 1569243824754 5 connected
192.168.75.130:7001>
8. 集群操作: cluster
- CLUSTER INFO 打印集群的信息
- CLUSTER NODES 列出集群当前已知的所有节点(node),以及这些节点的相关信息
节点(node)
- CLUSTER MEET 将 ip 和 port 所指定的节点添加到集群当中,让它成为集群的一份子。
- CLUSTER FORGET <node_id> 从集群中移除 node_id 指定的节点。
- CLUSTER REPLICATE <node_id> 将当前节点设置为 node_id 指定的节点的从节点。
- CLUSTER SAVECONFIG 将节点的配置文件保存到硬盘里面。
槽(slot)
- CLUSTER ADDSLOTS [slot ...] 将一个或多个槽(slot)指派(assign)给当前节点。
- CLUSTER DELSLOTS [slot ...] 移除一个或多个槽对当前节点的指派。
- CLUSTER FLUSHSLOTS 移除指派给当前节点的所有槽,让当前节点变成一个没有指派任何槽的节点。
- CLUSTER SETSLOT NODE <node_id> 将槽 slot 指派给 node_id 指定的节点,如果槽已经指派给另一个节点,那么先让另一个节点删除该槽>,然后再进行指派。
- CLUSTER SETSLOT MIGRATING <node_id> 将本节点的槽 slot 迁移到 node_id 指定的节点中。
- CLUSTER SETSLOT importING <node_id> 从 node_id 指定的节点中导入槽 slot 到本节点。
- CLUSTER SETSLOT STABLE 取消对槽 slot 的导入(import)或者迁移(migrate)。
键 (key)
- CLUSTER KEYSLOT 计算键 key 应该被放置在哪个槽上。
- CLUSTER COUNTKEYSINSLOT 返回槽 slot 目前包含的键值对数量。
- CLUSTER GETKEYSINSLOT 返回 count 个 slot 槽中的键。
示例:
例如将 6379的节点添加到集群之中的操作如下:
1. 配置redis 6379的集群配置
protected-mode yes
# Accept connections on the specified port, default is 6379 (IANA #815344).
# If port 0 is specified Redis will not listen on a TCP socket.
port 6379
cluster-enabled yes
# Every cluster node has a cluster configuration file. This file is not
# intended to be edited by hand. It is created and updated by Redis nodes.
# Every Redis Cluster node requires a different cluster configuration file.
# Make sure that instances running in the same system do not have
# overlapping cluster configuration file names.
cluster-config-file nodes-6379.conf
# Cluster node timeout is the amount of milliseconds a node must be unreachable
# for it to be considered in failure state.
# Most other internal time limits are multiple of the node timeout.
#
cluster-node-timeout 15000
2. 开启实例
redis-server /usr/local/redis-5.0.5/redis.conf
3. 连接集群
root@ubuntu:/home/song# redis-cli -c -h 192.168.75.130 -p 7001
192.168.75.130:7001>
4. 添加从节点:
192.168.75.130:7001> CLUSTER MEET 192.168.75.130 6379
OK
192.168.75.130:7001>
192.168.75.130:7001> cluster nodes
5.删除从节点:
192.168.75.130:7001> CLUSTER FORGET 3ea5e4740f60d3a98fc212ca07e76387c6781de1
OK
设置当前节点为master:
相关文章
- redis主从+ 哨兵模式(sentinel)+漂移VIP实现高可用系统
- Shiro缓存使用Redis、Ehcache、自带的MpCache实现的三种方式实例
- Redis学习(3)-redis启动
- 再谈Redis应用场景(转)
- Redis-Cluster实战--5.使用redis-cli安装
- DOCKER简明教程 : 通过容器连接REDIS数据库
- Redis配置文件详解(redis.conf)
- Redis为什么使用单进程单线程方式
- 专访高德地图开放平台的负责人童遥:跨机房同步和多路写入Redis集群方案将得到充分发展
- Redis短连接性能优化
- Redis常用数据类型介绍、使用场景及其操作命令
- Redis 单机部署redis实例
- Atitit redis使用 attilax 艾提拉总结 1.1. Redis默认有16个库,默认连接的是 index=0 的那一个。解决与原来不方便查询查看的问题1 1.2. redis不是现
- Redis整合Spring结合使用缓存实例
- 〖Python 数据库开发实战 - Python与Redis交互篇②〗- 利用 redis-py 实现字符串类型的常用指令操作
- 云小课|云小课教您如何选择Redis实例类型
- 【架构师修炼之路】Redis 极简教程 : 基本数据结构, 跳表原理, Spring Boot 项目使用实例...
- 深入浅出Redis-redis哨兵集群
- Redis使用示例及在PHP环境中用redis存储session
- redis_05 _ 内存快照:宕机后,Redis如何实现快速恢复
- Redis 5.0 redis-cli --cluster help说明
- centos7 shell 安装docker redis mongodb 等
- redis 分布式锁的 5个坑,真是又大又深
- Redis源码剖析--列表t_list实现
- redis的持久化方式RDB和AOF的区别
- C/C++编程操作Redis数据库,hiredis包装redis数据库操作接口及测试(增删改查与连接)
- ASP.NET Core微服务(六)——【redis操作】
- 【redis】Redis为什么能抗住10万并发?