源码安装Redis
源码安装Reids
系统:Ubuntu 22.04
1 | root@redis01:~# wget wget https://download.redis.io/redis-stable.tar.gz |
Redis单实例启动
1 | root@redis01:~# echo "vm.overcommit_memory = 1" >> /etc/sysctl.conf |
创建Redis集群
准备配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16root@redis01:~# tree redis
redis
├── 6001
│ └── redis.conf
├── 6002
│ └── redis.conf
├── 6003
│ └── redis.conf
├── 6004
│ └── redis.conf
├── 6005
│ └── redis.conf
└── 6006
└── redis.conf
6 directories, 6 files配置文件
1
2
3
4
5
6
7port 6001 # 根据目录名称来设置或自定义
cluster-enabled yes # 开启集群
cluster-config-file nodes.conf # 设置集群配置文件
cluster-node-timeout 5000 # 节点超时时间
appendonly yes # 启动AOF持久化
daemonize yes # 后台运行
requirepass 123456 # 设置密码,因为redis默认启动启动保护模式,必须设置密码或者关闭保护模式运行Redis
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
38root@redis01:~/redis# ls
6001 6002 6003 6004 6005 6006
root@redis01:~/redis# cd 6001/
root@redis01:~/redis/6001# redis-server redis.conf
root@redis01:~/redis/6001# cd ../6002/
root@redis01:~/redis/6002# redis-server redis.conf
root@redis01:~/redis/6002# cd ../6003/
root@redis01:~/redis/6003# redis-server redis.conf
root@redis01:~/redis/6003# cd ../6004/
root@redis01:~/redis/6004# redis-server redis.conf
root@redis01:~/redis/6004# cd ../6005/
root@redis01:~/redis/6005# redis-server redis.conf
root@redis01:~/redis/6005# cd ../6006/
root@redis01:~/redis/6006# redis-server redis.conf
LISTEN 0 511 0.0.0.0:16001 0.0.0.0:* users:(("redis-server",pid=9394,fd=9))
LISTEN 0 511 0.0.0.0:16002 0.0.0.0:* users:(("redis-server",pid=9402,fd=9))
LISTEN 0 511 0.0.0.0:16003 0.0.0.0:* users:(("redis-server",pid=9410,fd=9))
LISTEN 0 511 0.0.0.0:16004 0.0.0.0:* users:(("redis-server",pid=9416,fd=9))
LISTEN 0 511 0.0.0.0:16005 0.0.0.0:* users:(("redis-server",pid=9422,fd=9))
LISTEN 0 511 0.0.0.0:16006 0.0.0.0:* users:(("redis-server",pid=9428,fd=9))
LISTEN 0 511 0.0.0.0:6001 0.0.0.0:* users:(("redis-server",pid=9394,fd=6))
LISTEN 0 511 0.0.0.0:6002 0.0.0.0:* users:(("redis-server",pid=9402,fd=6))
LISTEN 0 511 0.0.0.0:6003 0.0.0.0:* users:(("redis-server",pid=9410,fd=6))
LISTEN 0 511 0.0.0.0:6004 0.0.0.0:* users:(("redis-server",pid=9416,fd=6))
LISTEN 0 511 0.0.0.0:6005 0.0.0.0:* users:(("redis-server",pid=9422,fd=6))
LISTEN 0 511 0.0.0.0:6006 0.0.0.0:* users:(("redis-server",pid=9428,fd=6))
LISTEN 0 511 [::]:16001 [::]:* users:(("redis-server",pid=9394,fd=10))
LISTEN 0 511 [::]:16002 [::]:* users:(("redis-server",pid=9402,fd=10))
LISTEN 0 511 [::]:16003 [::]:* users:(("redis-server",pid=9410,fd=10))
LISTEN 0 511 [::]:16004 [::]:* users:(("redis-server",pid=9416,fd=10))
LISTEN 0 511 [::]:16005 [::]:* users:(("redis-server",pid=9422,fd=10))
LISTEN 0 511 [::]:16006 [::]:* users:(("redis-server",pid=9428,fd=10))
LISTEN 0 511 [::]:6001 [::]:* users:(("redis-server",pid=9394,fd=7))
LISTEN 0 511 [::]:6002 [::]:* users:(("redis-server",pid=9402,fd=7))
LISTEN 0 511 [::]:6003 [::]:* users:(("redis-server",pid=9410,fd=7))
LISTEN 0 511 [::]:6004 [::]:* users:(("redis-server",pid=9416,fd=7))
LISTEN 0 511 [::]:6005 [::]:* users:(("redis-server",pid=9422,fd=7))
LISTEN 0 511 [::]:6006 [::]:* users:(("redis-server",pid=9428,fd=7))初始化集群
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
60root@redis01:~/redis/6006# redis-cli --cluster create \
192.168.66.11:6001 \
192.168.66.11:6002 \
192.168.66.11:6003 \
192.168.66.11:6004 \
192.168.66.11:6005 \
192.168.66.11:6006 \
--cluster-replicas 1 \
-a 123456
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 192.168.66.11:6005 to 192.168.66.11:6001
Adding replica 192.168.66.11:6006 to 192.168.66.11:6002
Adding replica 192.168.66.11:6004 to 192.168.66.11:6003
>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 09dffc30ed9c3a337596b0adb301e16830c226ac 192.168.66.11:6001
slots:[0-5460] (5461 slots) master
M: 8ed9d30ee063c708a5208c7aca8daffb70ecd710 192.168.66.11:6002
slots:[5461-10922] (5462 slots) master
M: 945afa23a9d0f0db653404f850e9327b3e16a5c2 192.168.66.11:6003
slots:[10923-16383] (5461 slots) master
S: 6ce8cf89caec9561fb70d37956a3f2a8261c3c5e 192.168.66.11:6004
replicates 8ed9d30ee063c708a5208c7aca8daffb70ecd710
S: 8b8f2fce9e06991ef7bc37d4096258ac75c69b50 192.168.66.11:6005
replicates 945afa23a9d0f0db653404f850e9327b3e16a5c2
S: 8a3210ce900daf7196128008d2fa679cffffa195 192.168.66.11:6006
replicates 09dffc30ed9c3a337596b0adb301e16830c226ac
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 192.168.66.11:6001)
M: 09dffc30ed9c3a337596b0adb301e16830c226ac 192.168.66.11:6001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: 945afa23a9d0f0db653404f850e9327b3e16a5c2 192.168.66.11:6003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 8a3210ce900daf7196128008d2fa679cffffa195 192.168.66.11:6006
slots: (0 slots) slave
replicates 09dffc30ed9c3a337596b0adb301e16830c226ac
S: 8b8f2fce9e06991ef7bc37d4096258ac75c69b50 192.168.66.11:6005
slots: (0 slots) slave
replicates 945afa23a9d0f0db653404f850e9327b3e16a5c2
S: 6ce8cf89caec9561fb70d37956a3f2a8261c3c5e 192.168.66.11:6004
slots: (0 slots) slave
replicates 8ed9d30ee063c708a5208c7aca8daffb70ecd710
M: 8ed9d30ee063c708a5208c7aca8daffb70ecd710 192.168.66.11:6002
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
[OK] All nodes agree about slots configuration.
>> Check for open slots...
>> Check slots coverage...
[OK] All 16384 slots covered.查看集群
1
2
3
4
5
6
7
8root@redis01:~# redis-cli -c -p 6001 -a 123456 cluster nodes
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
945afa23a9d0f0db653404f850e9327b3e16a5c2 192.168.66.11:6003@16003 master - 0 1691733745292 3 connected 10923-16383
8a3210ce900daf7196128008d2fa679cffffa195 192.168.66.11:6006@16006 slave 09dffc30ed9c3a337596b0adb301e16830c226ac 0 1691733746298 1 connected
09dffc30ed9c3a337596b0adb301e16830c226ac 192.168.66.11:6001@16001 myself,master - 0 1691733745000 1 connected 0-5460
8b8f2fce9e06991ef7bc37d4096258ac75c69b50 192.168.66.11:6005@16005 slave 945afa23a9d0f0db653404f850e9327b3e16a5c2 0 1691733747304 3 connected
6ce8cf89caec9561fb70d37956a3f2a8261c3c5e 192.168.66.11:6004@16004 slave 8ed9d30ee063c708a5208c7aca8daffb70ecd710 0 1691733746600 2 connected
8ed9d30ee063c708a5208c7aca8daffb70ecd710 192.168.66.11:6002@16002 master - 0 1691733746801 2 connected 5461-10922
本博客所有文章除特别声明外,均采用 CC BY-NC-SA 4.0 许可协议。转载请注明来自 尤妤!