赞
踩
目录
四、将原配置好的redis.conf文件内容复制到本地redis.conf
# 该处下载的是redis 5.0,如果想下载最新可以去掉“:5”,默认下载最新
# 也可以到redis官网上去查看自己想要的版本:
docker pull redis:5
# 查看下载情况
docker images
# 创建文件夹,我是在根目录下创建的mydata和redis文件夹
mkdir /mydata
mkdir /mydata/redis
# 创建本地redis.conf
touch /mydata/redis/redis.conf
# 打开redis.conf,将下面的内容拷贝进去,“:wq”保存退出
vim /mydata/redis/redis.conf
- protected-mode no
-
- port 6379
-
- tcp-backlog 511
- #redis密码 强烈建议设置复杂一些
- requirepass hat123
-
- timeout 0
-
- #防止出现远程主机强迫关闭了一个现有的连接的错误 默认是300
- tcp-keepalive 300
-
- #用守护线程的方式启动
- daemonize no
-
- supervised no
-
- pidfile /var/run/redis_6379.pid
-
- loglevel notice
-
- logfile ""
-
- databases 30
-
- 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-disable-tcp-nodelay no
-
- replica-priority 100
-
- lazyfree-lazy-eviction no
- lazyfree-lazy-expire no
- lazyfree-lazy-server-del no
- replica-lazy-flush no
-
- #redis持久化 默认是no
- appendonly yes
-
- appendfilename "appendonly.aof"
-
- 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
-
- 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
-
- hz 10
-
- dynamic-hz yes
-
- aof-rewrite-incremental-fsync yes
-
- rdb-save-incremental-fsync yes
# 直接复制,启动
docker run -p 6379:6379 --name redis -v /mydata/redis/redis.conf:/etc/redis/redis.conf -v /mydata/redis/data:/data -d redis:5 redis-server /etc/redis/redis.conf --appendonly yes
# 查看启动结果
docker ps
命令注释:
- -p 6379:6379 #把容器内的6379端口映射到宿主机6379端口
- -v /mydata/redis/redis.conf:/etc/redis/redis.conf #把宿主机配置好的redis.conf放到容器内的这个位置中
- -v /mydata/redis/data:/data #把redis持久化的数据在宿主机内显示,做数据备份
- redis-server /etc/redis/redis.conf #这个是关键配置,让redis不是无配置启动,而是按照这个redis.conf的配置启动
- -d redis:5 #启动redis版本
- -appendonly yes #redis启动后数据持久化
# 进入Redis容器使用 redis-cli 命令进行连接
docker exec -it redis redis-cli
# 查看当前redis版本,其中redis为你的容器名称哦,记得改
docker exec -it redis redis-server -v
# 查看当前正在运行的容器
docker ps
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。