redis-cluster集群搭建
程序员文章站
2022-05-22 08:22:42
...
环境:centos7.6
云主机:192.168.1.129 192.168.1.128 192.168.1.127
软件版本:redis-5.0.8.tar.gz
1,在3台同时解压,编译
yum -y install gcc
tar -xf redis-5.0.8.tar.gz
cd redis-5.0.8 && make && cd src/ && make install
2,maste:192.168.1.129
mv redis-5.0.8 /usr/local/redis
cp /usr/local/redis/redis.conf /data/redis/6380/conf/
cp /usr/local/redis/redis.conf /data/redis/6381/conf/
3,修改配置文件,密码先不要配置,配置完集群在设置密码,最后2行先不要
第一个redis 6380文件
[aaa@qq.com ~]# grep -vE '^#|^$' /data/redis/6380/conf/redis.conf
bind 0.0.0.0
protected-mode yes
port 6380 #修改端口
tcp-backlog 511
timeout 60
tcp-keepalive 300
daemonize yes #deamon 进程运行
supervised no
pidfile "/data/redis/6380/redis.pid" #修改pid的存放路径
loglevel notice
logfile "/data/redis/6380/log/redis.log" #修改log 的路径
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/redis/6380/db"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
maxclients 60000 #修改最大连接
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes #开启aof
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-6380.conf" #nodes 信息配置文件
cluster-node-timeout 60000 #集群的超时时间
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
masterauth "1ZdqlgWBfw" #这个是从访问mater密码
requirepass "1ZdqlgWBfw" # master 密码
第二个redis 6381 文件
[aaa@qq.com ~]# grep -vE '^#|^$' /data/redis/6381/conf/redis.conf
bind 0.0.0.0
protected-mode yes
port 6381
tcp-backlog 511
timeout 60
tcp-keepalive 300
daemonize yes
supervised no
pidfile "/data/redis/6381/redis.pid"
loglevel notice
logfile "/data/redis/6381/log/redis.log"
databases 16
always-show-logo yes
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename "dump.rdb"
dir "/data/redis/6381/db"
replica-serve-stale-data yes
replica-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
replica-priority 100
maxclients 60000
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no
appendonly yes
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-6381.conf"
cluster-node-timeout 60000
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
masterauth "1ZdqlgWBfw"
requirepass "1ZdqlgWBfw"
把文件拷贝到另外2台机器
scp -r /data 192.168.1.127:/
scp -r /data 192.168.1.128:/
4,启动6个redis,每台执行
redis-server /data/redis/6380/conf/redis.conf
redis-server /data/redis/6381/conf/redis.conf
5,开始启动集群,这个是5.0以后集群启动的方式,和以前的不同,下面的截图是其他地方的
redis-cli --cluster create 192.168.1.129:6380 192.168.1.128:6380 192.168.1.127:6380 192.168.1.129:6381 192.168.1.128:6381 192.168.1.127:6381 --cluster-replicas 1
查看集群是否成功
redis-cli --cluster check 192.168.1.129:6380 -a '1ZdqlgWBfw'
[aaa@qq.com ~]# redis-cli --cluster check 192.168.1.129:6380 -a '1ZdqlgWBfw'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.129:6380 (e6ddbe2f...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.127:6380 (ad1b9da3...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.128:6380 (3f6be144...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.129:6380)
M: e6ddbe2f529128d328a4e5ca60a7c7d5bbc62187 192.168.1.129:6380
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: ad1b9da391ec465a142c8d3073b1559af0480b82 192.168.1.127:6380
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 0639a2f95184af02567d76d69a652dbf1e3e1c7c 192.168.1.129:6381
slots: (0 slots) slave
replicates ad1b9da391ec465a142c8d3073b1559af0480b82
M: 3f6be14408c85b389c141cb65c588bc398a3ee27 192.168.1.128:6380
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 082036736369d990603cb9ae98697c7aafc52d17 192.168.1.128:6381
slots: (0 slots) slave
replicates e6ddbe2f529128d328a4e5ca60a7c7d5bbc62187
S: d93c05bf28d127c2592bab018f88d8502f6bd0b8 192.168.1.127:6381
slots: (0 slots) slave
replicates 3f6be14408c85b389c141cb65c588bc398a3ee27
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
集群搭建完毕,开始设置密码,6个节点都要设置,下面拿一个举例
redis-cli -h 192.168.1.127 -p 6381
[aaa@qq.com ~]# redis-cli -h 192.168.1.127 -p 6381
192.168.1.127:6381> config set masterauth 1ZdqlgWBfw
OK
192.168.1.127:6381> config set requirepass 1ZdqlgWBfw
OK
192.168.1.127:6381> auth 1ZdqlgWBfw
OK
192.168.1.127:6381> config rewrite
OK
192.168.1.127:6381> exit
最后设置完后再次查看集群状态
[aaa@qq.com ~]# redis-cli --cluster check 192.168.1.129:6380 -a '1ZdqlgWBfw'
Warning: Using a password with '-a' or '-u' option on the command line interface may not be safe.
192.168.1.129:6380 (e6ddbe2f...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.127:6380 (ad1b9da3...) -> 0 keys | 5461 slots | 1 slaves.
192.168.1.128:6380 (3f6be144...) -> 0 keys | 5462 slots | 1 slaves.
[OK] 0 keys in 3 masters.
0.00 keys per slot on average.
>>> Performing Cluster Check (using node 192.168.1.129:6380)
M: e6ddbe2f529128d328a4e5ca60a7c7d5bbc62187 192.168.1.129:6380
slots:[0-5460] (5461 slots) master
1 additional replica(s)
M: ad1b9da391ec465a142c8d3073b1559af0480b82 192.168.1.127:6380
slots:[10923-16383] (5461 slots) master
1 additional replica(s)
S: 0639a2f95184af02567d76d69a652dbf1e3e1c7c 192.168.1.129:6381
slots: (0 slots) slave
replicates ad1b9da391ec465a142c8d3073b1559af0480b82
M: 3f6be14408c85b389c141cb65c588bc398a3ee27 192.168.1.128:6380
slots:[5461-10922] (5462 slots) master
1 additional replica(s)
S: 082036736369d990603cb9ae98697c7aafc52d17 192.168.1.128:6381
slots: (0 slots) slave
replicates e6ddbe2f529128d328a4e5ca60a7c7d5bbc62187
S: d93c05bf28d127c2592bab018f88d8502f6bd0b8 192.168.1.127:6381
slots: (0 slots) slave
replicates 3f6be14408c85b389c141cb65c588bc398a3ee27
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
备注:redis Desktop Manager 这个桌面工具不支持集群
上一篇: redis-cluster集群搭建
下一篇: redis cluster集群搭建