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、配置文件详情

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

  

  

  

  

  

  

  

  

posted @   苍茫宇宙  阅读(526)  评论(0编辑  收藏  举报
编辑推荐:
· 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)
点击右上角即可分享
微信分享提示