Redis集群

本文详细描述了如何在Linux环境中安装、配置并启动Redis7.0.10集群,包括创建节点、编辑配置文件、编写启动和关闭脚本,以及使用redis-cli进行集群管理和验证。
摘要由CSDN通过智能技术生成

1.在opt/redis-7.0.10下 mkdir redisCluster文件目录

cp redis.conf redisCluster

2.vim redis6379.conf

创建6379 6380 6381 6389 6390 6391 六个结点的配置文件

cp redis6379.conf redis6380.conf    ........

include /root/myredis/redis.conf
port 6379
pidfile "/var/run/redis_6379.pid"
dbfilename "dump6379.rdb"
cluster-enabled yes
cluster-config-file nodes-6379.conf
cluster-node-timeout 15000

修改每个配置文件中的内容

3.添加脚本命令:touch start.sh

#!/bin/sh
redis-server redis6379.conf &
redis-server redis6380.conf &
redis-server redis6381.conf &
redis-server redis6389.conf &
redis-server redis6390.conf &
redis-server redis6391.conf &
 要求:redis6379名称要与创建的配置文件名称一致

4.关闭脚本vim shutdown.sh

#!/bin/sh
redis-cli -p 6379 shutdown &
redis-cli -p 6380 shutdown &
redis-cli -p 6381 shutdown &
redis-cli -p 6389 shutdown &
redis-cli -p 6390 shutdown &
redis-cli -p 6391 shutdown &

5.执行脚本

#启动redis
sh start.sh   

#关闭redis
sh shutdown.sh

6.启动6 个服务

[root@localhost redisCluster]# redis-server redis6379.conf
[root@localhost redisCluster]# redis-server redis6380.conf
[root@localhost redisCluster]# redis-server redis6381.conf
[root@localhost redisCluster]# redis-server redis6389.conf
[root@localhost redisCluster]# redis-server redis6390.conf
[root@localhost redisCluster]# redis-server redis6391.conf
[root@localhost redisCluster]# ps -ef | grep redis
root      13471  10062  0 17:57 pts/1    00:00:00 cp -i redis.conf redisCluster
root      13813      1  0 18:11 ?        00:00:00 redis-server *:6379 [cluster]
root      13814      1  0 18:11 ?        00:00:00 redis-server *:6380 [cluster]
root      13815      1  0 18:11 ?        00:00:00 redis-server *:6391 [cluster]
root      13816      1  0 18:11 ?        00:00:00 redis-server *:6381 [cluster]
root      13817      1  0 18:11 ?        00:00:00 redis-server *:6389 [cluster]
root      13818      1  0 18:11 ?        00:00:00 redis-server *:6390 [cluster]
root      13987  10062  0 18:20 pts/1    00:00:00 grep --color=auto redis
 

切换到opt/redis-7.0.10/src

运行

redis-cli --cluster create --cluster-replicas 1 192.168.126.128:6379 192.168.126.128:6380 192.168.126.128:6381 192.168.126.128:6389 192.168.126.128:6390 192.168.126.128:6391

7.登录查看

[root@localhost /]# redis-cli -c -p 6379

登录指令添加 -c 代表以集群方式登录

8.查看集群信息

192.168.126.128:6381> CLUSTER NODES


 

  • 13
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值