如何用docker快速搭建redis

如何用docker快速搭建redis

环境
CentOS Linux release 7.9.2009 (Core)
docker Version: 1.13.1

一、安装docker、docker-compose并启动
yum install  -y docker docker-compose
systemctl start docker
systemctl status docker
二、准备redis.conf文件

这里已经去除无用注释以及空行

pidfile /var/run/redis.pid
port 6379
tcp-backlog 511
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
#修改数据库的个数
databases 64
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error no
rdbcompression yes
rdbchecksum no
dbfilename dump.rdb
dir ./
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
#密码
requirepass 123456789   
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
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-entries 512
list-max-ziplist-value 64
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
三、编写一键部署redis-docker.sh脚本
#!/bin/bash

docker run -d -p 6379:6379 \
           --restart=always \
           -v /root/hhb/redis/redis.conf:/etc/redis.conf \
           -v /root/hhb/redis/data/:/root/hhb/redis/data \
           --name redis-server1 redis \
           redis-server /etc/redis.conf
           
# -v /root/hhb/redis/redis.conf:/etc/redis.conf 配置当前目录下的配置文件redis.conf同步到容器中的目录
# -v /root/hhb/redis/data/:/root/hhb/redis/data 配置本地目录到容器中的Data目录,用于Redis数据持久化
# redis-server $('pwd')/redis.conf 在容器启动时,使用redis-server命令行工具使用配置文件
# -p 6379:6379 表示本地端口和容器内部端口的映射,用于外网访问容器
# -d 让容器在后台运行,并输出运行成功时守护进程的编号
# --name redis-server1 给当前容器设置别名,便于查看
# redis-server /etc/redis.conf 这个是关键配置,让redis不是无配置启动,而是按照这个redis.conf的配置启动
四、执行脚本并验证结果
bash redis-docker.sh
docker ps
#另外找一台设备远程连接,首先得安装redis客户端
redis-cli -h *.*.*.*  -p 6379
redis:6379> auth 123456789
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值