-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRedis_Notes.txt
More file actions
357 lines (327 loc) · 10.3 KB
/
Redis_Notes.txt
File metadata and controls
357 lines (327 loc) · 10.3 KB
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
-----
Redis
-----
Questions
---------
Q1. Setting 'tcp_backlog 511' in /etc/redis/*.conf files, but
/proc/sys/net/core/somaxconn: 128
/proc/sys/net/ipv4/tcp_max_syn_backlog: 256
nothing in: /etc/sysctl.conf
Q2. Logfile set to "" and daemonized, so logs -> /dev/null
A2. Messages are going to syslog with 'syslog-enabled yes' setting
Q3. How to check/verify DB snapshots
Q4. In /etc/redis/*.conf files, how does
'slaveof tcs-redis1 6371' -> 'slaveof 10.200.18.115 6371'
Q5. Where are the 'slow-log' commands logged? How to see?
SLOWLOG GET [N]
SLOWLOG LEN
Install
-------
http://download.redis.io/redis-stable.tar.gz
$ wget http://download.redis.io/redis-stable.tar.gz
$ tar xvzf redis-stable.tar.gz
$ cd redis-stable
$ make
$ make test # optional
--------------
# yum install wget tcl
# wget http://download.redis.io/releases/redis-3.2.5.tar.gz
# tar xzf redis-3.2.5.tar.gz
# cd redis-3.2.5
# make
# make test
--------------
$ sudo make install
OR
$ sudo cp src/redis-server /usr/local/bin/
$ sudo cp src/redis-cli /usr/local/bin/
$ sudo mkdir /etc/redis
$ sudo mkdir /var/redis
$ sudo cp utils/redis_init_script /etc/init.d/redis_6379
$ sudo cp redis.conf /etc/redis/6379.conf
$ sudo mkdir /var/redis/6379
$ sudo update-rc.d redis_6379 defaults # OR sudo chkconfig --add redis_6379
$ sudo /etc/init.d/redis_6379 start
--------------
TERMS
-----
RESP (REdis Serialization Protocol)
RESP, the type of some data depends on the first byte:
Simple Strings "+"
Errors "-"
Integers ":"
Bulk Strings "$"
Arrays "*"
Redis append-only file feature (AOF)
COMMANDS
--------
$ redis-server # start server
/etc/init.d/redis_PORT start
$ redis-cli [-p PORT] shutdown # stop server
/etc/init.d/redis_PORT stop
$ redis-cli ping # check if working
$ redis-cli --stat [-i interval] # continuous stats mode
$ redis-cli --bigkeys # scan for big keys
$ redis-cli [-p port ] --scan [--pattern REGEX] # get a list of keys
$ redis-cli [-p port ] monitor # monitor commands
$ redis-cli [-p port ] --latency # monitor latency of instances
$ redis-cli [-p port ] --latency-history [-i interval]
$ redis-cli [-p port ] --latency-dist # spectrum of latencies
$ redis-cli --intrinsic-latency [-p port ] [test-time] # latency of system
$ redis-cli --intrinsic-latency 5
$ redis-cli --rdb <dest-filename> # remote RDB backup ($?=0 success)
$ redis-cli --rdb /tmp/dump.rdb
$ redis-cli --slave # slave mode (monitor master -> slave writes)
$ redis-cli --lru-test 10000000 # Least Recently Used (LRU) simulation
# used to help configure 'maxmemory' for LRU
$ redis-cli save # save dump file (dump.rdb) to $dir
$ redis-cli select <DB_NUMBER> # select DB
$ redis-cli dbsize # show size of DB
$ redis-cli connect <SERVER> <PORT> # connect to different servers/ports
$ redis-cli debug restart
$ redis-cli --version
$ redis-cli pubsub channels [PATTERN]
$ redis-cli pubsub numsub [channel1 ... channelN]
$ redis-cli subscribe/psubscribe/publish
$ redis-cli slowlog get [N]|len
a. unique progressive identifier for every slow log entry.
b. timestamp at which the logged command was processed.
c. amount of time needed for its execution, in microseconds.
d. array composing the arguments of the command.
FILES
-----
config file: /etc/redis/6371.conf
dbfilename dump.rdb
dir /var/lib/redis/6371
pidfile /var/run/redis/6371.pid
DB saved to:
/var/lib/redis/6371/dump.rdb
OPTIONS
-------
--raw, --no-raw
Configuration
-------------
redis.conf # well documented
default ports: 6379 / 16379 (cluster mode) / 26379 (Sentinel)
daemonize no
pidfile /var/run/redis_6379.pid
port 6379
loglevel info
logfile /var/log/redis_6379.log
dir /var/redis/6379
keyword argument1 argument2 ... argumentN
slaveof 127.0.0.1 6380
requirepass "hello world"
maxmemory 2mb
maxmemory-policy allkeys-lru
masterauth <password>
daemonize no # when run under daemontools
Administration
--------------
/etc/sysctl.conf
--
vm.overcommit_memory = 1 # sysctl vm.overcommit_memory=1
echo never > /sys/kernel/mm/transparent_hugepage/enabled
# passing arguments via CLI
$ ./redis-server --port 6380 --slaveof 127.0.0.1 6379
redis> config get GLOB
redis> config set slaveof 127.0.0.1 6380
redis> config rewrite
--- ---
Actual config
---
daemonize yes
pidfile /var/run/redis/6371.pid
port 6371
tcp-backlog 511
bind 0.0.0.0
timeout 0
tcp-keepalive 0
loglevel notice
logfile ""
syslog-enabled yes
syslog-ident redis
syslog-facility USER
databases 16
save 900 1
save 300 10
save 60 10000
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dbfilename dump.rdb
dir /var/lib/redis/6371
slaveof 10.200.18.115 6371 # only on slave(s)
slave-serve-stale-data yes
slave-read-only yes
repl-disable-tcp-nodelay no
slave-priority 100
maxclients 10000
maxmemory-policy noeviction
appendonly no
appendfilename "appendonly.aof"
appendfsync everysec
no-appendfsync-on-rewrite no
auto-aof-rewrite-percentage 100
auto-aof-rewrite-min-size 64mb
lua-time-limit 5000
slowlog-log-slower-than 10000
slowlog-max-len 128
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
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
---
Replication
-----------
redis> config set masterauth <password>
persistence = enabled OR automatic-restarts = disabled
slaveof 192.168.1.1 6379
repl-diskless-sync
repl-diskless-sync-delay
slave-read-only
masterauth <password> # config set masterauth <password>
min-slaves-to-write <number of slaves>
min-slaves-max-lag <number of seconds>
slave-announce-ip 5.5.5.5
slave-announce-port 1234
Redis Sentinel (26379)
--------------
- Monitoring
- Notification
- Automatic failover
- Configuration provider
redis-sentinel /path/to/sentinel.conf
OR
redis-server /path/to/sentinel.conf --sentinel
# typical minimal config
---
# sentinel monitor <master-group-name> <ip> <port> <quorum>
# sentinel down-after-milliseconds <master-name> <milliseconds> # default 30 secs
# sentinel failover-timeout <master-name> <milliseconds> # default 3 minutes
# sentinel parallel-syncs <master-name> <numslaves>
---
# example typical minimal config:
---
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel down-after-milliseconds mymaster 60000
sentinel failover-timeout mymaster 180000
sentinel parallel-syncs mymaster 1
---
# additional configs
---
# bind 127.0.0.1 192.168.1.1
# protected-mode no
# sentinel announce-ip <ip>
# sentinel announce-port <port>
# dir <working-directory>
# syntax: sentinel <option_name> <master_name> <option_value>
# sentinel auth-pass <master-name> <password>
# sentinel down-after-milliseconds <master-name> <milliseconds> # default 30 secs
# sentinel parallel-syncs <master-name> <numslaves>
# sentinel failover-timeout <master-name> <milliseconds> # default 3 minutes
# sentinel notification-script <master-name> <script-path>
# passed: <event type> <event description>
# sentinel client-reconfig-script <master-name> <script-path>
# passed: <master-name> <role> <state> <from-ip> <from-port> <to-ip> <to-port>
# <state> is currently always "failover"
# <role> is either "leader" or "observer"
--- --- ---
# actual config
---
/etc/redis/sentinel_26371.conf
# redis-sentinel 2.8.9 configuration file
# sentinel_26371.conf
daemonize no
dir "/var/lib/redis/sentinel_26371"
pidfile "/var/run/redis/sentinel_26371.pid"
port 26371
bind 0.0.0.0
sentinel monitor iowa_master_staging 10.200.18.115 6375 2
sentinel config-epoch iowa_master_staging 0
sentinel leader-epoch iowa_master_staging 0
sentinel known-slave iowa_master_staging 10.200.20.234 6375
logfile ""
syslog-enabled yes
syslog-ident "sentinel_26371"
syslog-facility user
-------------
# sentinel messages/events
---
+monitor master <group-name> <ip> quorum <N>
# Testing
$ redis-cli -p PORT
127.0.0.1:PORT> SENTINEL master mymaster # info about master
127.0.0.1:PORT> SENTINEL slaves mymaster # info about slave(s)
127.0.0.1:PORT> SENTINEL sentinels mymaster # info about sentinel(s)
127.0.0.1:PORT> SENTINEL get-master-addr-by-name mymasterer # get address of master
$ redis-cli -p 6379 DEBUG sleep 30 # simulate master hanging
---
ping
SENTINEL masters # get list of monitored masters and their state
SENTINEL master <master name>
SENTINEL slaves <master name>
SENTINEL sentinels <master name>
SENTINEL get-master-addr-by-name <master name>
SENTINEL reset <pattern> # reset all masters matching pattern
SENTINEL failover <master name> # force a failover
SENTINEL ckquorum <master name> # check if current config is able to failover
SENTINEL flushconfig # rewrite config file
SENTINEL monitor <name> <ip> <port> <quorum> # start monitoring a new master
SENTINEL remove <name> # stop monitoring master
SENTINEL SET <name> <option> <value>
---
# Commands
$
Redis Cluster
-------------
port 7000
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes
=====================================
redis1:$ WTFI redis-cli => /nb/redis/bin/redis-cli
redis-cli -h <hostname> -p <port> -r <repeat (-1=forever)> -i <interval (secs)> -n <DB_NUM> <COMMAND>
redis-cli -p 6371|26371 info [server|clients|memory|persistence|stats|replication|cpu|keyspace|sentinel]
redis-cli -p 6371 ping
=====================================
Upgrading or restarting a Redis instance without downtime
Check out: https://redis.io/topics/admin (bottom)
=====================================
for p in $(grep ^port /etc/redis/*|awk '{print $NF}'); do echo "---- port: $p ----"; /nb/redis/bin/redis-cli -p $p info | grep stat; done
========== tool (redis_monit.sh) [begin] ==========
#!/bin/bash
# get status of redis servers
REDIS_CLI_CMD=/nb/redis/bin/redis-cli
# get the list of ports configured
ports=$(ls /etc/redis/*.conf | tr -d '[a-z/.]')
for port in $ports; do
echo "---- port: $port ----"
if [ -e /etc/redis/$port.conf ]; then
$REDIS_CLI_CMD -p $port info | grep stat
else
echo "no config (/etc/redis/$port.conf)"
fi
done
========== tool (redis_monit.sh) [end] ==========
# update the monitor hosts - "live"
sentinel monitor mymaster 127.0.0.1 6379 2
sentinel monitor redis2 10.204.21.219 6379 2
sentinel failover redis1
sentinel masters
sentinel slaves redis1
# manual failover
# CLUSTER FAILOVER [FORCE|TAKEOVER]
$ redis-cli -p 7002 debug segfault
tags: redis