环境准备
- 下载redis安装包
这次是从github上下载的安装包,下载链接:redis安装包(6.2.16)
单机模式
把下载好的redis安装包放到/opt目录下,如下所示:
[root@localhost opt]# pwd
/opt
[root@localhost opt]# ll redis-6.2.16.tar.gz
-rwxr--r--. 1 root root 2518442 Oct 31 09:54 redis-6.2.16.tar.gz
解压redis-6.2.16.tar.gz,如下所示:
[root@localhost opt]# tar -zxf redis-6.2.16.tar.gz
[root@localhost opt]# ll redis-6.2.16
total 244
-rw-rw-r--. 1 root root 42203 Oct 3 04:13 00-RELEASENOTES
-rw-rw-r--. 1 root root 51 Oct 3 04:13 BUGS
-rw-rw-r--. 1 root root 5026 Oct 3 04:13 CONDUCT
-rw-rw-r--. 1 root root 3384 Oct 3 04:13 CONTRIBUTING
-rw-rw-r--. 1 root root 1487 Oct 3 04:13 COPYING
drwxrwxr-x. 7 root root 145 Oct 3 04:13 deps
-rw-rw-r--. 1 root root 11 Oct 3 04:13 INSTALL
-rw-rw-r--. 1 root root 151 Oct 3 04:13 Makefile
-rw-rw-r--. 1 root root 6888 Oct 3 04:13 MANIFESTO
-rw-rw-r--. 1 root root 21567 Oct 3 04:13 README.md
-rw-rw-r--. 1 root root 93849 Oct 3 04:13 redis.conf
-rwxrwxr-x. 1 root root 279 Oct 3 04:13 runtest
-rwxrwxr-x. 1 root root 283 Oct 3 04:13 runtest-cluster
-rwxrwxr-x. 1 root root 1117 Oct 3 04:13 runtest-moduleapi
-rwxrwxr-x. 1 root root 281 Oct 3 04:13 runtest-sentinel
-rw-rw-r--. 1 root root 13768 Oct 3 04:13 sentinel.conf
drwxrwxr-x. 3 root root 4096 Oct 3 04:13 src
drwxrwxr-x. 11 root root 182 Oct 3 04:13 tests
-rw-rw-r--. 1 root root 3055 Oct 3 04:13 TLS.md
drwxrwxr-x. 9 root root 4096 Oct 3 04:13 utils
[root@localhost opt]#
进入/opt/redis-6.2.16目录下,执行如下命令安装redis:
[root@localhost opt]# cd redis-6.2.16/
[root@localhost redis-6.2.16]# make && make install
在/opt目录下创建standalone目录:
[root@localhost opt]# mkdir standalone
[root@localhost opt]#
复制/opt/redis-6.2.16/redis.conf 到/opt/standalone/目录下:
[root@localhost opt]# cp /opt/redis-6.2.16/redis.conf /opt/standalone/
启动redis:
[root@localhost standalone]# redis-server /opt/standalone/redis.conf
7513:C 31 Oct 2024 13:42:37.390 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7513:C 31 Oct 2024 13:42:37.390 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=7513, just started
7513:C 31 Oct 2024 13:42:37.390 # Configuration loaded
7513:M 31 Oct 2024 13:42:37.391 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7513:M 31 Oct 2024 13:42:37.391 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 7513
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7513:M 31 Oct 2024 13:42:37.392 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7513:M 31 Oct 2024 13:42:37.392 # Server initialized
7513:M 31 Oct 2024 13:42:37.392 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7513:M 31 Oct 2024 13:42:37.393 * Ready to accept connections
连接redis,验证安装是否成功:
[root@localhost standalone]# redis-cli -p 6379
127.0.0.1:6379> get a
(nil)
127.0.0.1:6379> set a 1
OK
127.0.0.1:6379> get a
"1"
127.0.0.1:6379>
主从模式
在/opt目录下创建三个目录分别为:7001、7002、7003,如下所示:
[root@localhost opt]# mkdir 7001 7002 7003
[root@localhost opt]#
在/opt目录下的7001、7002、7003目录下创建redis.conf文件,文件内容分别如下:
/opt/7001/redis.conf
appendonly no
# save ""
port 7001
dir /opt/7001/
replica-announce-ip 192.168.79.136
bind 192.168.79.136
/opt/7002/redis.conf
appendonly no
# save ""
port 7002
dir /opt/7002/
replica-announce-ip 192.168.79.136
bind 192.168.79.136
/opt/7003/redis.conf
appendonly no
# save ""
port 7003
dir /opt/7003/
replica-announce-ip 192.168.79.136
bind 192.168.79.136
启动三个redis服务:
[root@localhost opt]# redis-server /opt/7001/redis.conf
7885:C 31 Oct 2024 14:02:16.412 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7885:C 31 Oct 2024 14:02:16.412 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=7885, just started
7885:C 31 Oct 2024 14:02:16.412 # Configuration loaded
7885:M 31 Oct 2024 14:02:16.413 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7885:M 31 Oct 2024 14:02:16.413 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 7001
| `-._ `._ / _.-' | PID: 7885
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7885:M 31 Oct 2024 14:02:16.414 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7885:M 31 Oct 2024 14:02:16.414 # Server initialized
7885:M 31 Oct 2024 14:02:16.414 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7885:M 31 Oct 2024 14:02:16.414 * Ready to accept connections
[root@localhost opt]# redis-server /opt/7002/redis.conf
7951:C 31 Oct 2024 14:03:03.537 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
7951:C 31 Oct 2024 14:03:03.537 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=7951, just started
7951:C 31 Oct 2024 14:03:03.537 # Configuration loaded
7951:M 31 Oct 2024 14:03:03.538 * Increased maximum number of open files to 10032 (it was originally set to 1024).
7951:M 31 Oct 2024 14:03:03.538 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 7002
| `-._ `._ / _.-' | PID: 7951
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
7951:M 31 Oct 2024 14:03:03.539 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
7951:M 31 Oct 2024 14:03:03.539 # Server initialized
7951:M 31 Oct 2024 14:03:03.539 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
7951:M 31 Oct 2024 14:03:03.539 * Ready to accept connections
[root@localhost opt]# redis-server /opt/7003/redis.conf
8019:C 31 Oct 2024 14:05:12.251 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8019:C 31 Oct 2024 14:05:12.251 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=8019, just started
8019:C 31 Oct 2024 14:05:12.251 # Configuration loaded
8019:M 31 Oct 2024 14:05:12.252 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8019:M 31 Oct 2024 14:05:12.252 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 7003
| `-._ `._ / _.-' | PID: 8019
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8019:M 31 Oct 2024 14:05:12.253 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8019:M 31 Oct 2024 14:05:12.253 # Server initialized
8019:M 31 Oct 2024 14:05:12.253 # WARNING Memory overcommit must be enabled! Without it, a background save or replication may fail under low memory condition. Being disabled, it can can also cause failures without low memory condition, see https://github.com/jemalloc/jemalloc/issues/1328. To fix this issue add 'vm.overcommit_memory = 1' to /etc/sysctl.conf and then reboot or run the command 'sysctl vm.overcommit_memory=1' for this to take effect.
8019:M 31 Oct 2024 14:05:12.253 * Ready to accept connections
设置7002为7001的从节点:
[root@localhost opt]# redis-cli -h 192.168.79.136 -p 7002
192.168.79.136:7002> slaveof 192.168.79.136 7001
OK
192.168.79.136:7002>
设置7003为7001的从节点:
[root@localhost opt]# redis-cli -h 192.168.79.136 -p 7003
192.168.79.136:7003> slaveof 192.168.79.136 7001
OK
192.168.79.136:7003>
验证:
往7001节点插入数据:
[root@localhost opt]# redis-cli -h 192.168.79.136 -p 7001
192.168.79.136:7001> set a 1
OK
192.168.79.136:7001>
查看7002和7003节点数据:
[root@localhost opt]# redis-cli -h 192.168.79.136 -p 7002
192.168.79.136:7002> get a
"1"
192.168.79.136:7002>
[root@localhost opt]# redis-cli -h 192.168.79.136 -p 7003
192.168.79.136:7003> get a
"1"
192.168.79.136:7003>
哨兵模式
在主从的基础上搭建哨兵模式,在/opt/目录下创建s1、s2、s3目录:
[root@localhost opt]# mkdir s1 s2 s3
[root@localhost opt]#
在/opt目录下的s1、s2、s3目录下分别创建sentinel.conf文件,具体内容如下:
s1:
port 27001
sentinel announce-ip "192.168.79.136"
sentinel monitor mymaster 192.168.79.136 7001 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
dir "/opt/s1"
s2:
port 27002
sentinel announce-ip "192.168.79.136"
sentinel monitor mymaster 192.168.79.136 7001 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
dir "/opt/s2"
s3:
port 27003
sentinel announce-ip "192.168.79.136"
sentinel monitor mymaster 192.168.79.136 7001 2
sentinel down-after-milliseconds mymaster 5000
sentinel failover-timeout mymaster 60000
dir "/opt/s3"
启动哨兵集群:
s1:
[root@localhost opt]# redis-sentinel /opt/s1/sentinel.conf
8452:X 31 Oct 2024 14:27:27.623 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8452:X 31 Oct 2024 14:27:27.623 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=8452, just started
8452:X 31 Oct 2024 14:27:27.623 # Configuration loaded
8452:X 31 Oct 2024 14:27:27.624 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8452:X 31 Oct 2024 14:27:27.624 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 27001
| `-._ `._ / _.-' | PID: 8452
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8452:X 31 Oct 2024 14:27:27.625 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8452:X 31 Oct 2024 14:27:27.630 # Sentinel ID is 9b692cb8762c485acbf4886b14cdb06241387abe
8452:X 31 Oct 2024 14:27:27.630 # +monitor master mymaster 192.168.79.136 7001 quorum 2
8452:X 31 Oct 2024 14:27:27.631 * +slave slave 192.168.79.136:7002 192.168.79.136 7002 @ mymaster 192.168.79.136 7001
8452:X 31 Oct 2024 14:27:27.633 * +slave slave 192.168.79.136:7003 192.168.79.136 7003 @ mymaster 192.168.79.136 7001
s2:
[root@localhost opt]# clear
[root@localhost opt]# redis-sentinel /opt/s2/sentinel.conf
8478:X 31 Oct 2024 14:28:27.089 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8478:X 31 Oct 2024 14:28:27.090 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=8478, just started
8478:X 31 Oct 2024 14:28:27.090 # Configuration loaded
8478:X 31 Oct 2024 14:28:27.090 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8478:X 31 Oct 2024 14:28:27.090 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 27002
| `-._ `._ / _.-' | PID: 8478
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8478:X 31 Oct 2024 14:28:27.090 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8478:X 31 Oct 2024 14:28:27.092 # Sentinel ID is 58f8bfad79fa2029a64af6be1696c099edfaf470
8478:X 31 Oct 2024 14:28:27.092 # +monitor master mymaster 192.168.79.136 7001 quorum 2
8478:X 31 Oct 2024 14:28:27.095 * +slave slave 192.168.79.136:7002 192.168.79.136 7002 @ mymaster 192.168.79.136 7001
8478:X 31 Oct 2024 14:28:27.098 * +slave slave 192.168.79.136:7003 192.168.79.136 7003 @ mymaster 192.168.79.136 7001
8478:X 31 Oct 2024 14:28:28.638 * +sentinel sentinel 9b692cb8762c485acbf4886b14cdb06241387abe 192.168.79.136 27001 @ mymaster 192.168.79.136 7001
s3:
[root@localhost opt]# redis-sentinel /opt/s3/sentinel.conf
8497:X 31 Oct 2024 14:29:47.944 # oO0OoO0OoO0Oo Redis is starting oO0OoO0OoO0Oo
8497:X 31 Oct 2024 14:29:47.944 # Redis version=6.2.16, bits=64, commit=00000000, modified=0, pid=8497, just started
8497:X 31 Oct 2024 14:29:47.944 # Configuration loaded
8497:X 31 Oct 2024 14:29:47.944 * Increased maximum number of open files to 10032 (it was originally set to 1024).
8497:X 31 Oct 2024 14:29:47.944 * monotonic clock: POSIX clock_gettime
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.16 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in sentinel mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 27003
| `-._ `._ / _.-' | PID: 8497
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
8497:X 31 Oct 2024 14:29:47.945 # WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128.
8497:X 31 Oct 2024 14:29:47.948 # Sentinel ID is 25661e0fbc422aece8178958aba89391a99ecfb8
8497:X 31 Oct 2024 14:29:47.948 # +monitor master mymaster 192.168.79.136 7001 quorum 2
8497:X 31 Oct 2024 14:29:47.948 * +slave slave 192.168.79.136:7002 192.168.79.136 7002 @ mymaster 192.168.79.136 7001
8497:X 31 Oct 2024 14:29:47.951 * +slave slave 192.168.79.136:7003 192.168.79.136 7003 @ mymaster 192.168.79.136 7001
8497:X 31 Oct 2024 14:29:48.075 * +sentinel sentinel 9b692cb8762c485acbf4886b14cdb06241387abe 192.168.79.136 27001 @ mymaster 192.168.79.136 7001
8497:X 31 Oct 2024 14:29:48.740 * +sentinel sentinel 58f8bfad79fa2029a64af6be1696c099edfaf470 192.168.79.136 27002 @ mymaster 192.168.79.136 7001
分区模式
在/opt目录下创建集群目录:
[root@localhost opt]# mkdir 7001 7002 7003 8001 8002 8003
[root@localhost opt]#
在/opt目录下的7001、7002、7003、8001、8002、8003目录下分别创建redis.conf文件,分别如下:
7001:
port 7001
cluster-enabled yes
cluster-config-file /opt/7001/nodes.config
cluster-node-timeout 5000
dir /opt/7001
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/7001/run.log
7002:
port 7002
cluster-enabled yes
cluster-config-file /opt/7002/nodes.config
cluster-node-timeout 5000
dir /opt/7002
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/7002/run.log
7003:
port 7003
cluster-enabled yes
cluster-config-file /opt/7003/nodes.config
cluster-node-timeout 5000
dir /opt/7003
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/7003/run.log
8001:
port 8001
cluster-enabled yes
cluster-config-file /opt/8001/nodes.config
cluster-node-timeout 5000
dir /opt/8001
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/8001/run.log
8002:
port 8002
cluster-enabled yes
cluster-config-file /opt/8002/nodes.config
cluster-node-timeout 5000
dir /opt/8002
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/8002/run.log
8003:
port 8003
cluster-enabled yes
cluster-config-file /opt/8003/nodes.config
cluster-node-timeout 5000
dir /opt/8003
bind 0.0.0.0
daemonize yes
replica-announce-ip 192.168.79.136
protected-mode no
databases 1
logfile /opt/8003/run.log
启动6个redis服务:
[root@localhost opt]# redis-server /opt/7001/redis.conf
[root@localhost opt]# redis-server /opt/7002/redis.conf
[root@localhost opt]# redis-server /opt/7003/redis.conf
[root@localhost opt]# redis-server /opt/8001/redis.conf
[root@localhost opt]# redis-server /opt/8002/redis.conf
[root@localhost opt]# redis-server /opt/8003/redis.conf
[root@localhost opt]#
组建集群:
[root@localhost opt]# redis-cli --cluster create --cluster-replicas 1 192.168.79.136:7001 192.168.79.136:7002 192.168.79.136:7003 192.168.79.136:8001 192.168.79.136:8002 192.168.79.136:8003
>>> 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.79.136:8002 to 192.168.79.136:7001
Adding replica 192.168.79.136:8003 to 192.168.79.136:7002
Adding replica 192.168.79.136:8001 to 192.168.79.136:7003
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: 6810a7f730d1c1e322c49446021728bfc4ab1c8d 192.168.79.136:7001
slots:[0-5460] (5461 slots) master
M: f069a8392b53e3b96a82a2e62876fa05bae0c63d 192.168.79.136:7002
slots:[5461-10922] (5462 slots) master
M: d1052a320d2ec078ca0ada91a61956db24f41515 192.168.79.136:7003
slots:[10923-16383] (5461 slots) master
S: cff97715f26cf41abfe9148bab0fb714b8f9a147 192.168.79.136:8001
replicates 6810a7f730d1c1e322c49446021728bfc4ab1c8d
S: 2e149cf8391cfd9de14682bb4e88871f6b53a935 192.168.79.136:8002
replicates f069a8392b53e3b96a82a2e62876fa05bae0c63d
S: a3cd0a8c42e45155c59e310b7b1d462064e47cb2 192.168.79.136:8003
replicates d1052a320d2ec078ca0ada91a61956db24f41515
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.79.136:7001)
M: 6810a7f730d1c1e322c49446021728bfc4ab1c8d 192.168.79.136:7001
slots:[0-5460] (5461 slots) master
1 additional replica(s)
S: 2e149cf8391cfd9de14682bb4e88871f6b53a935 192.168.79.136:8002
slots: (0 slots) slave
replicates f069a8392b53e3b96a82a2e62876fa05bae0c63d
S: cff97715f26cf41abfe9148bab0fb714b8f9a147 192.168.79.136:8001
slots: (0 slots) slave
replicates 6810a7f730d1c1e322c49446021728bfc4ab1c8d
M: d1052a320d2ec078ca0ada91a61956db24f41515 192.168.79.136:7003
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: a3cd0a8c42e45155c59e310b7b1d462064e47cb2 192.168.79.136:8003
slots: (0 slots) slave
replicates d1052a320d2ec078ca0ada91a61956db24f41515
M: f069a8392b53e3b96a82a2e62876fa05bae0c63d 192.168.79.136:7002
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.
查看集群状态:
[root@localhost opt]# redis-cli -p 7001 cluster nodes
2e149cf8391cfd9de14682bb4e88871f6b53a935 192.168.79.136:8002@18002 slave f069a8392b53e3b96a82a2e62876fa05bae0c63d 0 1730358227997 2 connected
cff97715f26cf41abfe9148bab0fb714b8f9a147 192.168.79.136:8001@18001 slave 6810a7f730d1c1e322c49446021728bfc4ab1c8d 0 1730358228000 1 connected
d1052a320d2ec078ca0ada91a61956db24f41515 192.168.79.136:7003@17003 master - 0 1730358228505 3 connected 10923-16383
a3cd0a8c42e45155c59e310b7b1d462064e47cb2 192.168.79.136:8003@18003 slave d1052a320d2ec078ca0ada91a61956db24f41515 0 1730358228000 3 connected
6810a7f730d1c1e322c49446021728bfc4ab1c8d 192.168.79.136:7001@17001 myself,master - 0 1730358227000 1 connected 0-5460
f069a8392b53e3b96a82a2e62876fa05bae0c63d 192.168.79.136:7002@17002 master - 0 1730358229015 2 connected 5461-10922
[root@localhost opt]#
连接集群:
[root@localhost opt]# redis-cli -c -p 7001
127.0.0.1:7001> set a 1
-> Redirected to slot [15495] located at 192.168.79.136:7003
OK
192.168.79.136:7003>