docker-redis


在docker中搭建redis

配置文件

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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
修改端口号: port
修改默认密码: requirepass
修改支持远程登陆: protected-mode no
修改监听端口号: bind 0.0.0.0
添加用户(用户名XX 密码******** 状态是on 权限是all): user XX ~* &* +@all on >********

bind 0.0.0.0

protected-mode no

port 12359

tcp-backlog 511

timeout 0

tcp-keepalive 300

daemonize no

supervised no

pidfile /var/run/redis_6379.pid

loglevel notice

logfile ""

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 dump.rdb

rdb-del-sync-files no

dir ./

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

user XX ~* &* +@all on >********

acllog-max-len 128

requirepass *********

lazyfree-lazy-eviction no
lazyfree-lazy-expire no
lazyfree-lazy-server-del no
replica-lazy-flush no

lazyfree-lazy-user-del no

appendonly no

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 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-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

Dockerfile

1
2
3
4
5
6
7
FROM redis

COPY redis.conf /usr/local/etc/redis/redis.conf

EXPOSE 12359

CMD [ "redis-server", "/usr/local/etc/redis/redis.conf" ]

build

1
docker build -t redis-server .

run

1
2
3
4
5
将配置中的port暴露出来
docker run -p 12359:12359 --restart=always \
-v /*****/data:/data \
--name="redis-server" \
-d redis

新建用户

1
2
3
4
5
6
7
8
9
10
11
12
没有在redis.conf里添加用户时,可以使用以下指令添加添加

登陆默认帐号
AUTH *******
新建用户XX 密码*******
ACL SETUSER XX >*******
启用用户XX
ACL SETUSER XX on
为用户XX添加string权限
ACL SETUSER XX resetkeys ~* +@string
为用户XX添加所有权限
ACL SETUSER XX resetkeys ~* &* +@all