美文网首页
docker 配置redis集群

docker 配置redis集群

作者: 卫泽洪_70a7 | 来源:发表于2021-05-07 09:15 被阅读0次

1、首先创建好挂载目录

mkdir -p /data/redis/node_6379/data
mkdir -p /data/redis/node_6380/data
mkdir -p /data/redis/node_6381/data
mkdir -p /data/redis/node_6382/data
mkdir -p /data/redis/node_6383/data
mkdir -p /data/redis/node_6384/data

mkdir -p /data/redis/node_6379/conf
mkdir -p /data/redis/node_6380/conf
mkdir -p /data/redis/node_6381/conf
mkdir -p /data/redis/node_6382/conf
mkdir -p /data/redis/node_6383/conf
mkdir -p /data/redis/node_6384/conf

2、编写配置文件

#bind 127.0.0.1 -::1
protected-mode no
requirepass myLoveJSYF11c.com
masterauth myLoveJSYF11c.com
port 6379
cluster-enabled yes
cluster-config-file node-6379.conf
cluster-node-timeout 15000
tcp-backlog 511
timeout 0
tcp-keepalive 300
daemonize no
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
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 ./
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 yes
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite yes
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
aof-load-truncated yes
aof-use-rdb-preamble yes
lua-time-limit 5000
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

对应不同的节点把6379改为对应的值就行

3、创建6个redis容器

docker create --name redis-6379 --net host -p 6379:6379 -v /data/redis/node_6379/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6379/data:/data redis redis-server /etc/redis/redis.conf
docker create --name redis-6380 --net host -p 6380:6380 -v /data/redis/node_6380/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6380/data:/data redis redis-server /etc/redis/redis.conf
docker create --name redis-6381 --net host -p 6381:6381 -v /data/redis/node_6381/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6381/data:/data redis redis-server /etc/redis/redis.conf
docker create --name redis-6382 --net host -p 6382:6382 -v /data/redis/node_6382/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6382/data:/data redis redis-server /etc/redis/redis.conf
docker create --name redis-6383 --net host -p 6383:6383 -v /data/redis/node_6383/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6383/data:/data redis redis-server /etc/redis/redis.conf
docker create --name redis-6384 --net host -p 6384:6384 -v /data/redis/node_6384/conf/redis.conf:/etc/redis/redis.conf -v /data/redis/node_6384/data:/data redis redis-server /etc/redis/redis.conf

4、启动redis容器

docker start redis-6379 redis-6380 redis-6381 redis-6382 redis-6383 redis-6384

5、组建 Redis 集群

进入任意一个 Redis 实例:

 docker exec -it redis-6379 /bin/bash

执行组件集群的命令:39.106.97.86 为本机的ip地址

redis-cli --cluster create 39.106.97.86:6379 39.106.97.86:6380 39.106.97.86:6381 39.106.97.86:6382 39.106.97.86:6383 39.106.97.86:6384 --cluster-replicas 1 -a yourpassword

6、然后就出现问题了

Waiting for the cluster to join 很久都没有反应............................................................................................................................
原因:
redis集群不仅需要开通redis客户端连接的端口,而且需要开通集群总线端口
集群总线端口为redis客户端连接的端口 + 10000
如redis端口为6379

则集群总线端口为16379

故,所有服务器的点需要开通redis的客户端连接端口和集群总线端口

7、如果还是一直等待,请检查创建容器的时候是否少了参数:--net host

因为使用docker搭建redis cluster必须要用docker的主机联网模式 也就是 --net host ,redis官网有讲
官网介绍如下:https://redis.io/topics/cluster-tutorial

image.png

完!!!

相关文章

网友评论

      本文标题:docker 配置redis集群

      本文链接:https://www.haomeiwen.com/subject/grskdltx.html