Docker安装Redis

安装redis

1
docker pull redis
1
mkdir -p /usr/local/app/redis/conf /usr/local/app/redis/data /usr/local/app/redis/logs
1
vim /usr/local/app/redis/conf/myredis.conf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# bind 192.168.1.100 10.0.0.1
# bind 127.0.0.1 ::1
#bind 127.0.0.1

protected-mode no

port 6379

tcp-backlog 511

requirepass yangming666@redis

timeout 0

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

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
1
docker run --restart=always --log-opt max-size=100m --log-opt max-file=2 -p 6379:6379 --name redis -v /usr/local/app/redis/conf/myredis.conf:/etc/redis/redis.conf -v /usr/local/app/redis/data:/data -d redis redis-server /etc/redis/redis.conf  --appendonly yes  --requirepass yangming666@redis
  1. –appendonly yes 开启redis 持久化
  2. –requirepass yangming666@redis 设置密码 (如果你是通过docker 容器内部连接的话,就随意,可设可不设。但是如果想向外开放的话,一定要设置,

通过docker ps指令查看启动状态

1
docker ps -a |grep redis 

查看容器运行日志

此处 –since 30m 是查看此容器30分钟之内的日志情况。

1
docker logs --since 30m redis

进入容器

1
docker exec -it redis redis-cli

在这里插入图片描述

error是没有权限验证。(因为设置了密码的。)

验证密码:

1
auth 密码

查看当前redis有没有设置密码:(得验证通过了才能输入的)

1
config get requirepass
1
config set requirepass yangming666@redis     # 将redis的密码设置为123456

查看挂载目录

1
docker inspect redis| grep Mounts -A 20
image-20230208135929340

image-20230224192111589