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、软件安装
使用以下命令下载,提取和编译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、配置文件路径

data /opt/redis/redis7001/data
log /opt/redis/redis7001/log
config /opt/redis/redis7001/config

3、配置文件详情

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、配置文件需要修改项

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脚本

[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)

[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、查看集群状态

[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、设置密码

./redis-cli -c -h 172.21.210.49 -p 7001
config set masterauth 123456
config set requirepass 123456
auth  123456
config rewrite

  

  

  

  

  

  

  

  

posted @ 2021-03-11 11:23  苍茫宇宙  阅读(507)  评论(0编辑  收藏  举报