redis-cluster集群6.2.0安装
规划
名称
|
ip
|
端口
|
redis集群6.2.0
|
172.21.210.49
|
7001、7002
|
redis集群6.2.0
|
172.21.210.50
|
7001、7002
|
redis集群6.2.0
|
172.21.210.51
|
7001、7002
|
环境:centos7
yum -y install gcc
1、软件安装
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | 使用以下命令下载,提取和编译Redis: $ wget https: //download .redis.io /releases/redis-6 .2.1. tar .gz $ tar xzf redis-6.2.1. tar .gz $ cd redis-6.2.1 $ make 注意:【Redis】编译错误zmalloc.h:50:31: fatal error: jemalloc /jemalloc .h: No such file or directory 解决: make MALLOC=libc src 目录 中现在提供了已编译的二进制文件 。使用以下命令运行Redis: $ src /redis-server 您可以使用内置客户端与Redis进行交互: $ src /redis-cli redis> set foo bar OK redis> get foo "bar" |
2、配置文件路径
1 2 3 | data /opt/redis/redis7001/data log /opt/redis/redis7001/log config /opt/redis/redis7001/config |
3、配置文件详情
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 | bind 172.21.210.49 protected-mode no port 7001 tcp-backlog 511 timeout 0 tcp-keepalive 300 daemonize yes pidfile /opt/redis/redis7001/config/redis .pid loglevel notice logfile "/opt/redis/redis7001/log/redis.log" databases 16 save 3600 1 save 300 100 save 60 10000 always-show-logo no set -proc-title yes proc-title-template "{title} {listen-addr} {server-mode}" stop-writes-on-bgsave-error yes rdbcompression yes rdbchecksum yes dbfilename dump.rdb rdb-del- sync -files no dir /opt/redis/redis7001/data/ replica-serve-stale-data yes replica- read -only yes repl-diskless- sync no repl-diskless- sync -delay 5 repl-diskless-load disabled repl-disable-tcp-nodelay no replica-priority 100 acllog-max-len 128 lazyfree-lazy-eviction no lazyfree-lazy-expire no lazyfree-lazy-server-del no replica-lazy-flush no lazyfree-lazy-user-del no lazyfree-lazy-user-flush no oom-score-adj no oom-score-adj-values 0 200 800 disable-thp yes appendonly no appendfilename "appendonly.aof" appendfsync everysec no-appendfsync-on-rewrite no auto-aof-rewrite-percentage 100 auto-aof-rewrite-min-size 64mb aof-load-truncated yes aof-use-rdb-preamble yes lua- time -limit 5000 cluster-enabled yes cluster-config- file nodes.conf cluster-node-timeout 15000 slowlog-log-slower-than 10000 slowlog-max-len 128 latency-monitor-threshold 0 notify-keyspace-events "" hash -max-ziplist-entries 512 hash -max-ziplist-value 64 list-max-ziplist-size -2 list-compress-depth 0 set -max-intset-entries 512 zset-max-ziplist-entries 128 zset-max-ziplist-value 64 hll-sparse-max-bytes 3000 stream-node-max-bytes 4096 stream-node-max-entries 100 activerehashing yes client-output-buffer-limit normal 0 0 0 client-output-buffer-limit replica 256mb 64mb 60 client-output-buffer-limit pubsub 32mb 8mb 60 hz 10 dynamic-hz yes aof-rewrite-incremental-fsync yes rdb-save-incremental-fsync yes jemalloc- bg -thread yes |
4、配置文件需要修改项
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | bind 172.21.210.49 protected-mode no port 7001 daemonize yes pidfile /opt/redis/redis7001/config/redis .pid logfile "/opt/redis/redis7001/log/redis.log" save 3600 1 save 300 100 save 60 10000 dbfilename dump.rdb dir /opt/redis/redis7001/data/ cluster-enabled yes cluster-config- file nodes.conf cluster-node-timeout 15000 |
5、启动redis脚本
1 2 3 4 5 6 7 8 9 10 | [root@host] # cat start.sh #!/bin/bash dir =$( cd ` dirname $0`; pwd ) cd $ dir bin /redis-server config /redis .conf [root@host] # chmod u+x start.sh 配置其他节点,拷贝文件修改config,然后都启动 /opt/redis/redis7001/start .sh /opt/redis/redis7002/start .sh |
6、创建集群(低版本用的pury脚本,高版本直接redis-cli)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | [root@host-172-21-210-49 bin] # ./redis-cli --cluster create --cluster-replicas 1 172.21.210.49:7001 172.21.210.49:7002 172.21.210.50:7001 172.21.210.50:7002 172.21.210.51:7001 172.21.210.51:7002 >>> Performing hash slots allocation on 6 nodes... Master[0] -> Slots 0 - 5460 Master[1] -> Slots 5461 - 10922 Master[2] -> Slots 10923 - 16383 Adding replica 172.21.210.50:7002 to 172.21.210.49:7001 Adding replica 172.21.210.51:7002 to 172.21.210.50:7001 Adding replica 172.21.210.49:7002 to 172.21.210.51:7001 M: 6ba72e5deed297988a13aa489a50ab511f57832b 172.21.210.49:7001 slots:[0-5460] (5461 slots) master S: 51c07a2503cb4538cec28914383c5928256edbd4 172.21.210.49:7002 replicates 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d M: 185d409bed817b9ce3eb0a37b67c73da015e4dd9 172.21.210.50:7001 slots:[5461-10922] (5462 slots) master S: dd04963417efae84e3f34679972138ea13cbfecc 172.21.210.50:7002 replicates 6ba72e5deed297988a13aa489a50ab511f57832b M: 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d 172.21.210.51:7001 slots:[10923-16383] (5461 slots) master S: da882be5c6ac4c75fc02d13040503751c0d69e4a 172.21.210.51:7002 replicates 185d409bed817b9ce3eb0a37b67c73da015e4dd9 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 172.21.210.49:7001) M: 6ba72e5deed297988a13aa489a50ab511f57832b 172.21.210.49:7001 slots:[0-5460] (5461 slots) master 1 additional replica(s) M: 185d409bed817b9ce3eb0a37b67c73da015e4dd9 172.21.210.50:7001 slots:[5461-10922] (5462 slots) master 1 additional replica(s) S: dd04963417efae84e3f34679972138ea13cbfecc 172.21.210.50:7002 slots: (0 slots) slave replicates 6ba72e5deed297988a13aa489a50ab511f57832b S: 51c07a2503cb4538cec28914383c5928256edbd4 172.21.210.49:7002 slots: (0 slots) slave replicates 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d M: 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d 172.21.210.51:7001 slots:[10923-16383] (5461 slots) master 1 additional replica(s) S: da882be5c6ac4c75fc02d13040503751c0d69e4a 172.21.210.51:7002 slots: (0 slots) slave replicates 185d409bed817b9ce3eb0a37b67c73da015e4dd9 [OK] All nodes agree about slots configuration. >>> Check for open slots... >>> Check slots coverage... [OK] All 16384 slots covered. |
7、查看集群状态
1 2 3 4 5 6 7 | [root@host-172-21-210-49 bin] # ./redis-cli -h 172.21.210.49 -p 7001 -c cluster nodes 185d409bed817b9ce3eb0a37b67c73da015e4dd9 172.21.210.50:7001@17001 master - 0 1615369178943 3 connected 5461-10922 dd04963417efae84e3f34679972138ea13cbfecc 172.21.210.50:7002@17002 slave 6ba72e5deed297988a13aa489a50ab511f57832b 0 1615369176939 1 connected 51c07a2503cb4538cec28914383c5928256edbd4 172.21.210.49:7002@17002 slave 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d 0 1615369177000 5 connected 2dfba2c4f639ff02c3ec8b6779536fad529a1b2d 172.21.210.51:7001@17001 master - 0 1615369177000 5 connected 10923-16383 da882be5c6ac4c75fc02d13040503751c0d69e4a 172.21.210.51:7002@17002 slave 185d409bed817b9ce3eb0a37b67c73da015e4dd9 0 1615369178000 3 connected 6ba72e5deed297988a13aa489a50ab511f57832b 172.21.210.49:7001@17001 myself,master - 0 1615369179000 1 connected 0-5460 |
8、设置密码
1 2 3 4 5 | . /redis-cli -c -h 172.21.210.49 -p 7001 config set masterauth 123456 config set requirepass 123456 auth 123456 config rewrite |
做一个决定,并不难,难的是付诸行动,并且坚持到底。
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· C#/.NET/.NET Core优秀项目和框架2025年2月简报
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 【杭电多校比赛记录】2025“钉耙编程”中国大学生算法设计春季联赛(1)