生产环境-SpringBoot-Redis集群方案

作者邮箱时间
潘顾昌guchang.pan@hand-china.com2020/05/03

一、架构分析

1.涉及技术

Redis-5.0.3、Redis-Cli

2.机器资源描述

资源机器
Redis-5.0.3172.28.8.65
Redis-5.0.3172.28.8.65
Redis-5.0.3172.28.8.65
Redis-5.0.3172.28.8.61
Redis-5.0.3172.28.8.61
Redis-5.0.3172.28.8.61

3.架构图

在这里插入图片描述

二、Redis安装

1. 两台机器均下载redis

yum -y install wget
wget http://download.redis.io/releases/redis-5.0.3.tar.gz

2. 两台机器均安装redis

tar -zxvf redis-5.0.3.tar.gz
cd redis-5.0.3/
yum -y install gcc zlib-devel tcl
make MALLOC=libc && make install
make test
redis-server  -v  # 查看是否安装成功
redis-cli -v # 查看是否安装成功

3.配置每个节点

mkdir -p /data/redis-cluster/{7000,7001,7002}

在7000文件夹创建文件redis.conf


bind 172.28.8.65 127.0.0.1
protected-mode yes

port 7000

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes
supervised no

pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""

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 ./

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

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.conf

cluster-node-timeout 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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

在7001文件夹创建文件redis.conf


bind 172.28.8.65 127.0.0.1
protected-mode yes

port 7001

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes
supervised no

pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""

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 ./

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

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.conf

cluster-node-timeout 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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

在7002文件夹创建文件redis.conf


bind 172.28.8.65 127.0.0.1
protected-mode yes

port 7002

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize yes
supervised no

pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""

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 ./

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

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.conf

cluster-node-timeout 5000

slowlog-log-slower-than 10000

slowlog-max-len 128

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

4.启动每个节点

redis-server /data/redis-cluster/7000/redis.config
redis-server /data/redis-cluster/7001/redis.config
redis-server /data/redis-cluster/7002/redis.config

另一台机器同理

三、配置集群

1.准备ruby集群环境

[root@server1 ~]# wget http://cache.ruby-lang.org/pub/ruby/2.6/ruby-2.6.1.tar.gz
[root@server1 ~]# tar -zxvf ruby-2.6.1.tar.gz
[root@server1 ~]# cd ruby-2.6.1/
[root@server1 ruby-2.6.1]# ./configure --prefix=/opt/ruby
[root@server1 ruby-2.6.1]# make && make install

2.通过redis-cli实现集群

[root@server1 ~]# redis-cli --cluster create 172.28.8.65:7000 172.28.8.65:7001 172.28.8.65:7002 172.28.8.61:7000 172.28.8.61:7001 172.28.8.61:7002 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383

3.验证集群

[root@register test]# redis-cli -h 172.28.8.65 -c -p 7000
172.28.8.65:7000> set pgc 1234565
-> Redirected to slot [5744] located at 172.28.8.61:7000
OK
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

潘顾昌

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值