欢迎访问 如意编程网!

如意编程网

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

redis 分布式集群部署

发布时间:2024/5/15 编程问答 3 豆豆
如意编程网 收集整理的这篇文章主要介绍了 redis 分布式集群部署 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

redis 分布式集群

参考视频

redis下载

最好下载一份新的redis.conf

我redis7.0.0 报错,后重新下载了一份 redis.conf ,解决

*** FATAL CONFIG FILE ERROR (Redis 7.0.0) *** replicaof directive not allowed in cluster mode***致命配置文件错误(Redis 7.0.0)*** 集群模式下不允许复制指令

配置文件

一个配置文件,然后修改出6个配置文件

include /Users/software/redis-7.0colony/conf/redis.conf# 端口号 port 7001# redis进程文件 pidfile /Users/software/redis-7.0colony/conf/redis7001.pid# rdb文件名 dbfilename redis7001.rdb# aof文件名 appendfilename "appendonly7001.aof"# 集群 cluster-enabled yes# 生成node文件 cluster-config-file nodes7001.conf# 后台启动 daemonize yes#aof、rdb文件存储目录 dir /Users/software/redis-7.0colony/data/bind 0.0.0.0# 设置密码 requirepass 123456masterauth 123456

创建配置文件

redis7001.conf

redis7002.conf

redis7003.conf

redis7004.conf

redis7005.conf

redis7006.conf

只需要修改路径7001的修改和文件端口保持一致

启动

redis-server ../conf/redis7001.conf redis-server ../conf/redis7002.conf redis-server ../conf/redis7003.conf redis-server ../conf/redis7004.conf redis-server ../conf/redis7005.conf redis-server ../conf/redis7006.conf

检查是否启动成功

redis-cli -p 7001 auth 123456

创建集群

最好将data目录下的数据删除

# -a 设置登录密码,如不填加,则报错 # [ERR] Node 192.168.0.104:6379 NOAUTH Authentication required. # –replicas 1 采用最简单的方式配置集群,一台主机,一台从机,正好三组redis-cli --cluster create --cluster-replicas 1 \ 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 \ 127.0.0.1:7006 -a 123456

控制台输出 输入 yes

Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe. >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 127.0.0.1:7005 to 127.0.0.1:7001 Adding replica 127.0.0.1:7006 to 127.0.0.1:7002 Adding replica 127.0.0.1:7004 to 127.0.0.1:7003 >>> Trying to optimize slaves allocation for anti-affinity [WARNING] Some slaves are in the same host as their master M: 017b198cb3fcc5de5cd77c07cadb5282fffb5879 127.0.0.1:7001slots:[0-5460] (5461 slots) master M: ca6095d7b57e0b950617796217dd489cc263a853 127.0.0.1:7002slots:[5461-10922] (5462 slots) master M: 50c1b922e5cdb9943639453bda4f3323bec8ca16 127.0.0.1:7003slots:[10923-16383] (5461 slots) master S: c8f0da41569f05b92837e24158d6e3d3120363f3 127.0.0.1:7004replicates 017b198cb3fcc5de5cd77c07cadb5282fffb5879 S: d346af98e7a4539029aa6166af7d0fbc98ef49b4 127.0.0.1:7005replicates ca6095d7b57e0b950617796217dd489cc263a853 S: cbbc608ed00c5146fcf60b5275efc4de28be6679 127.0.0.1:7006replicates 50c1b922e5cdb9943639453bda4f3323bec8ca16 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 127.0.0.1:7001) M: 017b198cb3fcc5de5cd77c07cadb5282fffb5879 127.0.0.1:7001slots:[0-5460] (5461 slots) master1 additional replica(s) M: 50c1b922e5cdb9943639453bda4f3323bec8ca16 127.0.0.1:7003slots:[10923-16383] (5461 slots) master1 additional replica(s) S: cbbc608ed00c5146fcf60b5275efc4de28be6679 127.0.0.1:7006slots: (0 slots) slavereplicates 50c1b922e5cdb9943639453bda4f3323bec8ca16 S: d346af98e7a4539029aa6166af7d0fbc98ef49b4 127.0.0.1:7005slots: (0 slots) slavereplicates ca6095d7b57e0b950617796217dd489cc263a853 S: c8f0da41569f05b92837e24158d6e3d3120363f3 127.0.0.1:7004slots: (0 slots) slavereplicates 017b198cb3fcc5de5cd77c07cadb5282fffb5879 M: ca6095d7b57e0b950617796217dd489cc263a853 127.0.0.1:7002slots:[5461-10922] (5462 slots) master1 additional replica(s) [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered.

登录集群

# -p 端口号 登录那个输入那个端口号 # -c 采用集群策略连接,如果不输入密码 set a a 时会报错 (error) NOAUTH Authentication required. # -a 指定密码 设置数据会自动切换到相应的写主机 redis-cli -p 7001 -c -a 123456# 查看当前角色和从数 info info Replication # 控制台输出 # role:master 当前角色 master # connected_slaves:1 从机1台 # slave0:ip=127.0.0.1,port=7006,state=online,offset=2206,lag=0 state=online在线 # master_failover_state:no-failover # master_replid:e9d5a48afba173d807c3e48b4b3bdd43fb0e0787 # master_replid2:0000000000000000000000000000000000000000 # master_repl_offset:2206 # second_repl_offset:-1 # repl_backlog_active:1 # repl_backlog_size:1048576 # repl_backlog_first_byte_offset:1 # repl_backlog_histlen:2206

总结

以上是如意编程网为你收集整理的redis 分布式集群部署的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得如意编程网网站内容还不错,欢迎将如意编程网推荐给好友。