下载redis镜像
docker pull redis6.2
准备redis 配置文件 redis-7001~7006.conf
点击查看代码- protected-mode yes
- port 7001
- tcp-backlog 511
- timeout 0
- tcp-keepalive 300
- daemonize no
- supervised no
- pidfile /var/run/redis_7001.pid
- loglevel notice
- logfile "/data/redis7001.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 dump7001.rdb
- rdb-del-sync-files no
- dir "/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
- requirepass "123456"
- lazyfree-lazy-eviction no
- lazyfree-lazy-expire no
- lazyfree-lazy-server-del no
- replica-lazy-flush no
- lazyfree-lazy-user-del no
- appendonly yes
- appendfilename "appendonly7001.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 /data/nodes-7001.conf
- cluster-node-timeout 15000
- cluster-announce-ip 121.5.xxx.xx
- 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
复制代码 启动redis
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7001 redis:6.2 redis-server /usr/local/etc/redis/redis-7001.conf
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7002 redis:6.2 redis-server /usr/local/etc/redis/redis-7002.conf
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7003 redis:6.2 redis-server /usr/local/etc/redis/redis-7003.conf
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7004 redis:6.2 redis-server /usr/local/etc/redis/redis-7004.conf
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7005 redis:6.2 redis-server /usr/local/etc/redis/redis-7005.conf
docker run -it -d -v /home/zyw/zpowner/dockerdata/redis-cluster/conf:/usr/local/etc/redis -v /home/zyw/zpowner/dockerdata/redis-cluster/data:/data --network=host --name redis-7006 redis:6.2 redis-server /usr/local/etc/redis/redis-7006.conf
加载集群(需同步开放17001-17006端口)
/usr/local/bin/redis-cli --cluster create ip地址:7001 ip地址:7002 ip地址:7003 ip地址:7004 ip地址:7005 ip地址:7006 --cluster-replicas 1 -a 123456
登录redis
redis-cli -h 127.0.0.1 -p 7001
检查集群配置
CLUSTER NODES
docker容器里安装vim命令
apt-get update
apt-get install vim
docker部署、云服务可能碰到(客户端连接后IP变成内网地址、需指定conf文件中得地址为外网)
cluster-announce-ip 10.1.1.5
这是redis.conf 中的原文 大致意思是在docker或者某些部署中 因为端口被转发等其他原因 会导致地址发送变化,所以在配置中写死地址就可以解决
非docker部署时解决方案 执行命令
1.config set cluster-announce-ip 阿里云redis的ip地址
2. config rewrite
3. exit
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作! |