Redis集群部署

架构

请添加图片描述

网络规划

主机名IP服务端口主/从
redis1192.168.62.3163816381-Master
redis1192.168.62.3163846384-Slave
redis2192.168.62.3263836383-Master
redis2192.168.62.3263866386-Slave
redis3192.168.62.3363856385-Master
redis3192.168.62.3363826382-Slave

目录规划

主机名服务端口软件安装目录
redis16381/redis6381
redis16384/redis6384
redis26383/redis6383
redis26386/redis6386
redis36385/redis6385
redis36382/redis6382

创建用户

useradd redis
echo "redis"|passwd --stdin redis

创建目录

#192.168.62.31	
mkdir /redis6381
mkdir /redis6384
chown -R redis:redis /redis
chmod 775 /redis

#192.168.62.32	
mkdir /redis6383
mkdir /redis6386
chown -R redis:redis /redis
chmod 775 /redis

#192.168.62.32	
mkdir /redis6385
mkdir /redis6382
chown -R redis:redis /redis
chmod 775 /redis

安装tcl包

yum install tcl tcl-devel

解压

tar zxvf /home/cpcn/redis-6.2.10.tar.gz

编译测试

192.168.62.31/32/33编译测试

cd redis-6.2.10
make && make test
make PREFIX=/usr/local/redis install

编辑配置

根据服务器IP修改bind参数
根据端口号修改port、pidfile、logfile、cluster-config-file参数

bind 192.168.62.31
protected-mode yes
masterauth Redis
port 6381
tcp-backlog 511
timeout 3600
tcp-keepalive 300
daemonize yes
supervised no
pidfile /redis6381/redis_6381.pid
loglevel notice
logfile /redis6381/redis_6381.log
databases 1
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump6381.rdb
dir /usr/local/redis6381
slave-serve-stale-data yes
slave-read-only yes
repl-diskless-sync no
repl-diskless-sync-delay 5
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 50000
maxmemory 1g
maxmemory-policy noeviction
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
lua-time-limit 5000
cluster-enabled yes
cluster-config-file nodes-6381.conf
cluster-node-timeout 15000
cluster-slave-validity-factor 10
cluster-require-full-coverage yes
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
activerehashing yes
client-output-buffer-limit normal 0 0 0
client-output-buffer-limit slave 256mb 64mb 60
client-output-buffer-limit pubsub 32mb 8mb 60
hz 10
aof-rewrite-incremental-fsync yes
requirepass Redis

启动服务

合计6个redis服务

nohup /usr/local/redis/bin/redis-server  /redis6381/redis.conf

添加集群节点

cluster meet 192.168.56.{31,32,33} {6382,6383,6384,6385,6386}

指派槽位

#192.168.62.31	
./bin/redis-cli -c -h 192.168.62.31 -p 6381 cluster addslots {0..5460}
#192.168.62.32	
./bin/redis-cli -c -h 192.168.62.32 -p 6383 cluster addslots {5461..10922}
#192.168.62.33	
./bin/redis-cli -c -h 192.168.62.33 -p 6385 cluster addslots {10923..16383}

配置主从关系

192.168.62.31

192.168.62.33:6381> cluster replicate 6eca1d1d4a178ebd93162b3fe1eb46be39227eab
OK
192.168.62.33:6381> cluster nodes
9a5c5379c99242de67f8a325669c296935cbd5fe 192.168.62.33:6385 master - 0 1599826755103 5 connected 10923-16383
6eca1d1d4a178ebd93162b3fe1eb46be39227eab 192.168.62.32:6383 master - 0 1599826753084 3 connected 5461-10922
2cb5b8971d08b6e8ac800f2d1c718edd57856bb9 192.168.62.31:6381 master - 0 1599826758127 2 connected 0-5460
7a0fee134d6d63316a98c67abb3270f6558337d5 192.168.62.32:6386 myself,master - 0 0 4 connected
dc88fb3227e1b689b3c2582f87257755affd4049 192.168.62.33:6382 master - 0 1599826756617 0 connected
121bd383dc1e65511929e07afce4a98e1d33ff2d 192.168.62.31:6384 slave 6eca1d1d4a178ebd93162b3fe1eb46be39227eab 0 1599826757120 3 connected

192.168.62.32

192.168.62.32:6386> cluster replicate 9a5c5379c99242de67f8a325669c296935cbd5fe
OK
192.168.62.32:6386> cluster nodes
9a5c5379c99242de67f8a325669c296935cbd5fe 192.168.62.33:6385 master - 0 1599826755103 5 connected 10923-16383
6eca1d1d4a178ebd93162b3fe1eb46be39227eab 192.168.62.32:6383 master - 0 1599826753084 3 connected 5461-10922
2cb5b8971d08b6e8ac800f2d1c718edd57856bb9 192.168.62.31:6381 master - 0 1599826758127 2 connected 0-5460
7a0fee134d6d63316a98c67abb3270f6558337d5 192.168.62.32:6386 myself,slave - 0 0 4 connected
dc88fb3227e1b689b3c2582f87257755affd4049 192.168.62.33:6382 master - 0 1599826756617 0 connected
121bd383dc1e65511929e07afce4a98e1d33ff2d 192.168.62.31:6384 slave 6eca1d1d4a178ebd93162b3fe1eb46be39227eab 0 1599826757120 3 connected

192.168.62.33

192.168.62.33:6382> cluster replicate 9a5c5379c99242de67f8a325669c296935cbd5fe
OK
192.168.62.33:6382> cluster nodes
121bd383dc1e65511929e07afce4a98e1d33ff2d 192.168.62.31:6384 slave 6eca1d1d4a178ebd93162b3fe1eb46be39227eab 0 1599826795383 3 connected
2cb5b8971d08b6e8ac800f2d1c718edd57856bb9 192.168.62.31:6381 master - 0 1599826797399 2 connected 0-5460
dc88fb3227e1b689b3c2582f87257755affd4049 192.168.62.33:6382 myself,slave - 0 0 0 connected
6eca1d1d4a178ebd93162b3fe1eb46be39227eab 192.168.62.32:6383 master - 0 1599826796391 3 connected 5461-10922
7a0fee134d6d63316a98c67abb3270f6558337d5 192.168.62.32:6386 slave 9a5c5379c99242de67f8a325669c296935cbd5fe 0 1599826793366 5 connected
9a5c5379c99242de67f8a325669c296935cbd5fe 192.168.62.33:6385 master - 0 1599826794375 5 connected 10923-16383

主从切换

从库执行

CLUSTER FAILOVER
CLUSTER FAILOVER FORCE
CLUSTER FAILOVER TAKEOVER 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值