redis
1、上传redis离线镜像文件到服务器上
链接:https://pan.baidu.com/s/1kjdsdCqXOa2QzPxIPIvaFw
提取码:6666
2、docker加载镜像文件到本地镜像仓库中
# 加载离线镜像文件到本地仓库
docker load -i redis7.0.4.tar
# 查询是否加载成功,确保无误
docker images | grep redis
3、配置docker-compose.yml文件(docker容器里面的目录请勿修改)
version: '3'
services:
redis:
network_mode: "host"
restart: always
container_name: docker_redis_7001
image: redis:latest
environment:
TZ: Asia/Shanghai
ports:
- "16379:16379"
volumes:
- /home/cttic/dockerConfig/redis:/data/redis
- /home/cttic/dockerConfig/redis/conf/redis7001.conf:/etc/redis/conf/redis.conf
- /home/cttic/dockerConfig/redis/logs:/data/redis/logs
privileged: true
command: ["redis-server","/etc/redis/conf/redis.conf"]
4、redis.conf文件
bind 0.0.0.0
requirepass 12gsd6..qww
protected-mode yes
port 6379
tcp-backlog 511
# 它可以决定一个空闲的客户端维持多少秒会关闭,0表示关闭该功能。即永不关闭。
timeout 0
# 对访问客户端的一种心跳检测,每个n秒检测一次。
tcp-keepalive 30
# 不限制大小
maxmemory 0
# 当内存不足以容纳新写入数据时,在键空间中,移除最近最少使用的 Key
#maxmemory-policy allkeys-lru
daemonize no
supervised no
supervised no
pidfile /data/redis/redis.pid
loglevel notice
logfile "/data/redis/logs/redis.log"
databases 16
always-show-logo yes
save ""
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir "/data/redis/"
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
lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
slave-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 no
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
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
5、通过docker-compose构建nginx
#来到docker-compose文件目录下,执行构建redis命令
docker-compose -f ./docker-compose.yml up redis --build -d
#查询docker进程运行命令,状态为 up 即是正常运行
docker ps | grep redis
6、访问服务器redis,测试效果
#进入容器内部
docker exec -it 5db2c7551714 /bin/bash
#连接redis客户端,配置文件中端口是16379,所以-p
redis-cli -p 16379
7、查看服务器映射目录