|
|
楼主 |
发表于 2018-11-16 12:43:33
|
显示全部楼层
http://www.discuz.net/forum.php? ... 648&highlight=REDIS
. M8 Z& a" r! j" w" l. l. ~7 ~9 l4 f无意间测试 单机状态 redis相当给力 测试1000请求/s 单纯的 get 和set 居然只用了 0.01秒 当时我惊呆了
5 b0 i( c1 b D
. T% l2 f+ M: E* D4 J- |http://www.discuz.net/forum.php? ... 731&highlight=REDIS
; v8 A k9 |' z* H+ f4 N! Y: f8 L6 ?% Y( `% G; q: o/ B- ]
https://wenku.baidu.com/view/265a5ce176a20029bc642d0b.html
, | o/ g5 q- z4 d5 r
) i: m- A6 n' g0 v+ H! U+ j7 {=======================================; p O% O4 e' c$ |1 o7 i& Z
- 连接上 ssh& h- U+ `& D7 ]
- 9 z2 w, O( U9 [8 y$ s* s
- ( X/ V C& j4 c( x
- 第一步:下载redis% U' i# A) h6 K( n, x+ d- k
- # wget http://redis.googlecode.com/files/redis-2.6.10.tar.gz# I; R, G# S' V7 F# m* ^% m
- # tar zxvf redis-2.6.10.tar.gz
3 M! F# B4 J! g4 |4 a) i/ B: j/ A - # cd redis-2.6.10
/ f; x; \+ p; p6 J. b - # make
1 f& [- `" p& O, d/ M8 B - # make install
, V5 D x2 Z" Q4 R1 k$ O$ J' e - #cp redis.conf /etc/ #复制配置文件到etc目录下面' @2 B1 o; r( O S2 |" N; e- t
- 第二步:修改配置- J5 i5 I& D: j! L% q7 w( u% T
- #vi /etc/redis.conf/ W4 _' x" j2 S# n8 j4 c1 ~
- ######################下面是无措的配置文件 复制过去就成#########
; K7 Y+ `% D2 R" p% O# Y, p - # Redis configuration file example
; x4 J) i2 i0 J" S$ G! J3 f
2 ?$ l5 ^1 Z+ ]" S- # Note on units: when memory size is needed, it is possible to specify
2 j; ^* i9 D; T$ a; L9 E - # it in the usual form of 1k 5GB 4M and so forth:+ ?: }/ C( N5 t1 e0 P
- ## o$ d- Y& R: @; \( A+ t
- # 1k => 1000 bytes
7 m9 t6 z8 w @ B' y) G - # 1kb => 1024 bytes
. N) f+ b' c% u7 m( T - # 1m => 1000000 bytes& S( g* W% L1 E$ |" p! u
- # 1mb => 1024*1024 bytes2 \7 g; S- H6 q1 ~* h+ t: j1 V& ?' J6 ]
- # 1g => 1000000000 bytes# x9 J2 s5 \+ w
- # 1gb => 1024*1024*1024 bytes9 X2 Z, |% b5 f& |
- # t' k; E) q! v4 a! W- t
- # units are case insensitive so 1GB 1Gb 1gB are all the same.7 `- ~) e9 Z( V) l6 F
- ! D" k. W" P/ b0 P7 `2 W2 [
- # By default Redis does not run as a daemon. Use 'yes' if you need it.
; t( N5 G3 U: U" \6 d2 P - # Note that Redis will write a pid file in /var/run/redis.pid when daemonized.
6 _3 o& e: g' O3 W! E! K& S5 A4 M - daemonize yes
& i3 G0 k' P; M" i( l/ q# V/ T
. h% a+ L7 B2 p* V q2 P' O: p- # When running daemonized, Redis writes a pid file in /var/run/redis.pid by
# d5 U- _& i! S: p, e. J - # default. You can specify a custom pid file location here.
7 R8 }, L% U1 q - pidfile /var/run/redis.pid0 @! G9 v: b7 t1 A. Y
- 1 Y9 [& J' l. c" T* i. j
- # Accept connections on the specified port, default is 6379.
% ^5 P' ^ M& m8 S! z - # If port 0 is specified Redis will not listen on a TCP socket.
H: x$ n" p- Z# a5 J, { - port 6379
6 i, f6 d/ _- W
/ m' A$ v7 h6 R! k7 Z, K! l- # If you want you can bind a single interface, if the bind option is not9 U, G, X/ h% A2 M! I" y1 Y/ \' V
- # specified all the interfaces will listen for incoming connections.
3 r! W) W! g+ }7 F- C - #7 `8 {2 k. U# L" _, G h! F4 H
- # bind 127.0.0.1/ z, o e- f" m" a# p3 s5 _- K
3 h9 |; C2 B+ @" T) h' k- # Specify the path for the unix socket that will be used to listen for+ t8 Y0 ~- j( i: c9 U( {
- # incoming connections. There is no default, so Redis will not listen
; I8 E# s8 [7 f" E - # on a unix socket when not specified.
- \! j/ D2 c2 s( ^ - #$ M0 o1 A& }/ w/ o
- # unixsocket /tmp/redis.sock
. o1 H: l C# I [. r9 F) Z - # unixsocketperm 7553 Q' Y$ ]. i1 L7 w
: A+ \/ S" d: C1 M- # Close the connection after a client is idle for N seconds (0 to disable)
% c- D% f) E" K; `( T0 `5 Q - timeout 300
3 B4 A5 r: C1 ^4 A: L' X) q T - % z9 d: O) |' V. \
- # TCP keepalive.
* i( q+ t# \, V- c4 E4 ~ - #1 S4 K- X* `$ F2 }$ u. z
- # If non-zero, use SO_KEEPALIVE to send TCP ACKs to clients in absence+ g1 f6 W: K9 g5 K1 |# V: R1 }
- # of communication. This is useful for two reasons:4 S9 G0 ]/ `5 e' y
- #5 F' S4 T' v& p) @
- # 1) Detect dead peers.
1 P% r, X8 w/ e - # 2) Take the connection alive from the point of view of network
6 e( P( L# u$ I - # equipment in the middle.9 |+ s+ O2 y) X X
- #* o8 \% e; N; ?1 Z: |$ b
- # On Linux, the specified value (in seconds) is the period used to send ACKs.8 @; m2 G5 E0 S& v/ Y9 o6 V6 v: i& L
- # Note that to close the connection the double of the time is needed.5 Z4 s4 t. Q. W1 H) N# |, M$ P, L
- # On other kernels the period depends on the kernel configuration.
: y5 J5 ?3 V% }/ w - #
8 O) o* n5 q* a - # A reasonable value for this option is 60 seconds.
* x& N& g! C& l' i* n/ ? - tcp-keepalive 0; |8 n/ q: c, d1 ^0 P+ k
- + C: m; u G- H! h
- # Specify the server verbosity level.
0 C5 ]3 N; }* ^8 w' g" j - # This can be one of:' n, p- F9 m! J( Y- n# C2 L
- # debug (a lot of information, useful for development/testing)! j) r$ M% ^; e/ H! w
- # verbose (many rarely useful info, but not a mess like the debug level)
E; {. ^7 E H8 p; |4 F - # notice (moderately verbose, what you want in production probably)
9 D- ^+ ~' r$ _5 c8 [ - # warning (only very important / critical messages are logged)
+ P9 L& j5 S; ]; J. b - loglevel warning
( m: V; v1 l7 [1 H$ i; T - , l0 |" x5 u1 h6 q, ?5 |
- # Specify the log file name. Also 'stdout' can be used to force8 [0 e* i" G7 Y3 k
- # Redis to log on the standard output. Note that if you use standard
- F3 L7 [* e' \2 @5 d# N2 V9 }) y - # output for logging but daemonize, logs will be sent to /dev/null
; Z/ X7 I) Q) P# ~4 F1 m9 e4 K' { - logfile /var/log/redis.log' N( V; \2 c1 ?# V( T
- & ]& _! V! p2 E7 x
- # To enable logging to the system logger, just set 'syslog-enabled' to yes,
' C L$ z/ Q, g7 V; f - # and optionally update the other syslog parameters to suit your needs.7 D8 g* |/ s+ J" e/ N$ M, Z4 r
- syslog-enabled yes% W' o- W: k% y9 W. {' V
- 8 Y# O0 w R; S' {: V' v
- # Specify the syslog identity.0 o+ w/ C; m* ?- \$ w
- # syslog-ident redis$ p8 _! K1 X- L8 T5 t
- ; q( W" f2 o) }4 h2 w$ a
- # Specify the syslog facility. Must be USER or between LOCAL0-LOCAL7.8 Y) _# g- |, V: @( O& N& \! {% d
- syslog-facility local0( H( h P: i7 t. O4 [1 A u
; e6 L, L# M _) q) S# s8 s9 Q/ q- # Set the number of databases. The default database is DB 0, you can select
- T* B1 y7 j$ g3 U# M8 k _0 l4 { - # a different one on a per-connection basis using SELECT <dbid> where
6 C- |, M4 F6 X' s- ^( H, A5 g - # dbid is a number between 0 and 'databases'-1
- |: i6 Q/ N' y - databases 16
! R; H3 F1 A: A, N0 m - 5 O: M+ W2 A- y
- ################################ SNAPSHOTTING #################################8 R- W0 H1 H7 W" f& }& \0 R* I4 X
- #
+ m, r8 Z7 X( I* E. Z - # Save the DB on disk:' L) e$ n) s0 m9 H
- #
9 q3 C1 C* M ]# r. n - # save <seconds> <changes>! A7 c! X$ \$ s( J3 @2 i Z& P
- #. f. _* n$ ~- |% k
- # Will save the DB if both the given number of seconds and the given
/ O2 j6 i" X" t3 g) H! U - # number of write operations against the DB occurred.
7 V5 b. y; ^3 B4 `% T - #' W: U D$ A3 G7 l0 K, R
- # In the example below the behaviour will be to save:
* q- e; N# x* n, V. y3 M& h& O - # after 900 sec (15 min) if at least 1 key changed3 K6 M6 ]3 c" b
- # after 300 sec (5 min) if at least 10 keys changed
6 _2 Z/ K, X, S( |* A. c+ J9 v- J - # after 60 sec if at least 10000 keys changed9 R3 P/ {' g3 d5 Q( q' a- v
- #
, e- v$ E, v3 J% `# W+ i: n - # Note: you can disable saving at all commenting all the "save" lines.1 b G) r" U/ A3 [% v5 c( l
- #- s1 E$ N( i2 }/ V
- # It is also possible to remove all the previously configured save
+ R! s# P3 T8 g# n" S - # points by adding a save directive with a single empty string argument
+ U3 D. P* I' W7 T - # like in the following example:$ R A- Q% y/ r4 Y" D, S( B
- #- b+ ~2 I+ A" z+ y @1 v
- # save "", [, c9 O: [9 T9 C9 ^8 ]8 J
- 6 C: `8 g8 r7 x i
- save 900 1/ [% C5 j, l* u+ W
- save 300 10
M+ f6 }6 `' g - save 60 10000
+ b5 s/ P( G ]8 T/ v
& z3 _# R# V# S6 |* K" e, B- # By default Redis will stop accepting writes if RDB snapshots are enabled; F2 {9 q) R$ W" G
- # (at least one save point) and the latest background save failed.
c) k! {# l) @, P% C8 { - # This will make the user aware (in an hard way) that data is not persisting0 k) @% O1 H# A: l8 x" \
- # on disk properly, otherwise chances are that no one will notice and some
7 r0 T+ B8 [$ w. M - # distater will happen.: b- w3 t, q6 A6 ^( {* O
- #7 i* j5 k3 O+ U) K( e, U
- # If the background saving process will start working again Redis will
8 V2 r% \/ }( B( E - # automatically allow writes again./ W$ ?. A1 \, h
- #3 k3 F: _8 E$ A
- # However if you have setup your proper monitoring of the Redis server8 z; T: I5 X) F8 A
- # and persistence, you may want to disable this feature so that Redis will
. i" N+ x; M7 V* q m - # continue to work as usually even if there are problems with disk,# x6 H, J3 a( B& w, }3 ^4 g
- # permissions, and so forth.
8 v. R/ g& m3 d7 Z - stop-writes-on-bgsave-error yes
) V2 K% d& ^1 a5 l' n- s - % t0 ~9 z/ g( }+ h: `. f: v
- # Compress string objects using LZF when dump .rdb databases?) k7 I, U5 D& U9 i6 z( k
- # For default that's set to 'yes' as it's almost always a win.6 V* s1 ~# m: L' j- b
- # If you want to save some CPU in the saving child set it to 'no' but: G* j5 y2 k( }% U
- # the dataset will likely be bigger if you have compressible values or keys." B) E2 w- L% C- s2 h7 j7 }
- rdbcompression yes8 i6 d. A; M2 e3 t2 `2 C
7 C4 ~0 ~9 ]' f4 m2 f8 H$ V- # Since version 5 of RDB a CRC64 checksum is placed at the end of the file.
0 o2 Z2 ]' k0 {; @3 D - # This makes the format more resistant to corruption but there is a performance+ m" O1 y8 m% ^3 o+ Q2 B+ B6 z
- # hit to pay (around 10%) when saving and loading RDB files, so you can disable it! A8 W8 T2 ^: b r4 }% m
- # for maximum performances.* S, Z! a. f$ a$ }- K/ h2 Q
- #$ l6 y! b" p: N- V: B- C
- # RDB files created with checksum disabled have a checksum of zero that will
# i1 \% D( w- s; [ - # tell the loading code to skip the check.
% G1 R' S2 c! E3 r0 R; ~( @ - rdbchecksum yes4 T; W0 c$ U/ C: ^
- ' \6 X4 o) |* u/ ` ?
- # The filename where to dump the DB
5 G% L. P) b1 b. G- a, K( ?4 U - dbfilename dump.rdb- H) d' ]6 e! ]# M6 \5 V
- . D3 O5 }# u9 o# {" Y
- # The working directory.
3 K8 B: ~% {& R* n) R. S. W0 T - #0 S" I) {/ b8 B! l% l. S2 ~: N
- # The DB will be written inside this directory, with the filename specified- g$ X1 `5 t7 H* Z
- # above using the 'dbfilename' configuration directive.
0 @5 \8 a4 U& Z* Z - # 0 Q6 L0 R. u/ o. ]' g2 N; [( l$ b
- # The Append Only File will also be created inside this directory.
1 A7 \, c7 b2 ^ - # / A2 `, c8 [1 }1 D7 l, g& b+ [# c0 B% |
- # Note that you must specify a directory here, not a file name.
, h( j- Q5 Y0 m3 o8 b - dir /var/db/redis2 |5 J' z+ k& X% c3 x9 Z1 h
, K9 |9 t! I3 j' E0 |3 y- ################################# REPLICATION #################################
2 z- j7 C |5 ]3 Z) s, l# c' z - 2 X2 U" V* [6 b* g8 n5 ]
- # Master-Slave replication. Use slaveof to make a Redis instance a copy of
: u& y7 c( X$ X4 L @ - # another Redis server. Note that the configuration is local to the slave% u) `8 l- o; s
- # so for example it is possible to configure the slave to save the DB with a
% P7 _) C. I, e, R7 Z4 } - # different interval, or to listen to another port, and so on.
# R3 i9 r/ `0 {% p: A0 x1 M - #9 Y7 p2 t8 X% V/ A' {; t7 x4 C( I% q
- # slaveof <masterip> <masterport>
+ {" g- G* H1 k c* z - $ G" ~0 B1 H2 w) X, ~6 E- k" f
- # If the master is password protected (using the "requirepass" configuration3 e7 P( _ O# G8 n- @% x
- # directive below) it is possible to tell the slave to authenticate before
* v( @, ]: \3 H( a/ R - # starting the replication synchronization process, otherwise the master will
! S* C" r" P& c8 e! x - # refuse the slave request." C# ~( H' g0 ^; O
- #
7 {: A/ f5 Z# N2 C! O/ E& B9 H - # masterauth <master-password>
) D! g4 s% ^5 n' @5 K; v5 o. G. g5 _# e
. x: R: w3 T! I) u- # When a slave loses its connection with the master, or when the replication9 ^0 Z( N2 h1 S2 L+ l
- # is still in progress, the slave can act in two different ways:5 c! i3 O/ b6 i* g) K7 |
- #
: @2 z# K1 m7 w7 P - # 1) if slave-serve-stale-data is set to 'yes' (the default) the slave will8 r3 U ~* _2 q
- # still reply to client requests, possibly with out of date data, or the
( V8 F9 j- P0 Y' T: Q - # data set may just be empty if this is the first synchronization./ J' O @7 Y9 i9 F% \6 Y# I
- #1 z5 E; ~5 }" I5 m% B
- # 2) if slave-serve-stale data is set to 'no' the slave will reply with
' K1 L) r$ Z9 X9 W6 K( n - # an error "SYNC with master in progress" to all the kind of commands
( e4 T2 M1 L. [3 J - # but to INFO and SLAVEOF./ k: {* `( @8 G8 L
- #
1 }- Y" V7 f" _/ e' N - slave-serve-stale-data yes5 a3 z; \0 H% l( Z' k9 ^2 z3 t
- W8 f4 t" g# m( }3 R4 @% _
- # You can configure a slave instance to accept writes or not. Writing against& ^# j# g* M3 [; V7 p* L
- # a slave instance may be useful to store some ephemeral data (because data
0 k1 Y, r2 _9 `* [1 ~ - # written on a slave will be easily deleted after resync with the master) but
! F( e9 F* [) H1 Q9 I8 p - # may also cause problems if clients are writing to it because of a
# G# k% s8 q8 |0 R$ k7 A2 h. R& Q - # misconfiguration.. p- Y4 D" U& W9 X2 D U. x3 X) r: ]1 v
- #
) b* J. C1 Q, `/ R9 s$ R+ ]7 B - # Since Redis 2.6 by default slaves are read-only.
# x: e7 R/ E, N9 c - #; N+ \9 l9 ~( k2 u
- # Note: read only slaves are not designed to be exposed to untrusted clients+ I/ i. W8 q( n P
- # on the internet. It's just a protection layer against misuse of the instance.
, B0 w! U: W/ g( B B5 n( O- ~ - # Still a read only slave exports by default all the administrative commands
- y e5 ]" [9 A& h - # such as CONFIG, DEBUG, and so forth. To a limited extend you can improve ]( y. X, i3 Y: R
- # security of read only slaves using 'rename-command' to shadow all the
! ^# x4 q& t0 ~ - # administrative / dangerous commands.
. \2 } @2 B( x - slave-read-only yes' x* Q9 r5 N$ W$ O: s* ~
, s8 _; x: G, ?7 k8 Y/ u- Z& P- # Slaves send PINGs to server in a predefined interval. It's possible to change! j S# l9 X [
- # this interval with the repl_ping_slave_period option. The default value is 109 n2 F* t* W" ~( D: E
- # seconds.6 e% z" i1 c& b! N- s6 S
- #
2 }! I' h% E# A - # repl-ping-slave-period 10
! O. }, ~# I# s% O6 O, [
0 f C" _3 j- y9 _+ g/ x- # The following option sets a timeout for both Bulk transfer I/O timeout and- q2 y! Q1 m' h, a
- # master data or ping response timeout. The default value is 60 seconds.$ r3 }$ \0 G8 E9 o- n, ^ I/ g* j3 L
- #
( A& T S1 i; S& N. W4 N - # It is important to make sure that this value is greater than the value' Y. E0 V. U( l, o" c
- # specified for repl-ping-slave-period otherwise a timeout will be detected' z8 ^. e: t+ e* ~- B# c5 c
- # every time there is low traffic between the master and the slave.
6 R4 \& s- R+ R% Z - #
( Y3 O$ E8 h' a+ e* j - # repl-timeout 60. _4 F! @- X# L) j
Q7 e6 j* D1 F# H7 O- f8 g- # Disable TCP_NODELAY on the slave socket after SYNC?
7 `' s8 @. |( Z" \ - #6 d$ ^ Z% v0 ], v' v/ n. o
- # If you select "yes" Redis will use a smaller number of TCP packets and
/ }3 j# k1 f! D# ^( d% B* u% G - # less bandwidth to send data to slaves. But this can add a delay for
. c* T" x: }" ` - # the data to appear on the slave side, up to 40 milliseconds with+ R1 d# f. W) n( b/ _+ b. R
- # Linux kernels using a default configuration.; v4 v0 Q, }; ?) V
- ## ^ ]. A1 j- t! r9 o& ~
- # If you select "no" the delay for data to appear on the slave side will
1 C& m3 I, K. I6 c( K - # be reduced but more bandwidth will be used for replication., i+ ?% |$ D& U: ?
- #4 W# z& q# J0 p# w
- # By default we optimize for low latency, but in very high traffic conditions2 [! e! c, }) A9 r
- # or when the master and slaves are many hops away, turning this to "yes" may
4 r# I/ K* S/ G( N - # be a good idea.
5 w% j4 y4 w" [/ X3 p) j - repl-disable-tcp-nodelay no
; \" E& ^ h% B. g. y3 ^* r6 e! H+ f
7 C7 l; }( M* {# g1 h4 O- # The slave priority is an integer number published by Redis in the INFO output.2 k! l; w8 V$ ]" p' w( B0 w
- # It is used by Redis Sentinel in order to select a slave to promote into a
( ~# j7 A# @% ~7 B - # master if the master is no longer working correctly.
; y) U9 O- z' u5 t7 Z - #7 J" ~$ l# g) ]$ @/ ~6 ~+ W
- # A slave with a low priority number is considered better for promotion, so
* J4 |9 X- X/ o2 v3 ~! O - # for instance if there are three slaves with priority 10, 100, 25 Sentinel will
( \/ |; T8 p; m \ h$ I- ^ - # pick the one wtih priority 10, that is the lowest.6 X Q1 n- r# L7 J
- #
2 l5 f2 o2 a9 r$ b - # However a special priority of 0 marks the slave as not able to perform the! _0 _! u3 x' I4 \2 ^* j s
- # role of master, so a slave with priority of 0 will never be selected by& ^0 F |8 s, |# t; f! P
- # Redis Sentinel for promotion.
. v/ X3 f; w: T% F" f - #
8 E" {; z! {: |0 q/ ^( f" ~1 ` - # By default the priority is 100.# C. f! X8 h( W i& Q* ?
- slave-priority 100
; ^# z$ k" t, C' @ - J' H! X8 J) Y
- ################################## SECURITY ###################################5 h+ k- B8 ]8 u
. T) J* p' c. N- Z( ^9 l- # Require clients to issue AUTH <ASSWORD> before processing any other
5 o& ]& h0 X+ W+ k' ?; ~ - # commands. This might be useful in environments in which you do not trust
4 q( V0 U: C/ A- ]9 I; ? - # others with access to the host running redis-server./ y$ K$ v8 |- @5 B0 S
- #8 o1 `: i' Q& ]
- # This should stay commented out for backward compatibility and because most
7 i0 x6 {. F. v9 }* y$ ^ - # people do not need auth (e.g. they run their own servers).
G( `. z0 G8 A3 g' d - #
6 O# T3 x9 ~& Y* @( z. T7 E - # Warning: since Redis is pretty fast an outside user can try up to
( w' B6 _: v8 p, _) ]$ Y# ]" y - # 150k passwords per second against a good box. This means that you should
1 q% F4 Y7 F, [ - # use a very strong password otherwise it will be very easy to break.- ?. d4 Q! X% z
- #
F4 K4 K7 C9 @" G( T ~ - # requirepass foobared* K5 _- `4 u) T* w
2 }# H- I7 Z0 a5 p& m; ^" ?- # Command renaming.% ?% G+ o; N. a8 s: ]
- #
( |8 a& B% V/ q/ ] E& j9 D' d# j( ^ - # It is possible to change the name of dangerous commands in a shared
6 W+ ^& G, |$ e$ Y$ e - # environment. For instance the CONFIG command may be renamed into something
7 e5 q4 Q4 V. o1 ^ - # hard to guess so that it will still be available for internal-use tools
6 b4 n' D' N5 n9 B - # but not available for general clients.
6 i, e, f- r( I" {1 } - #! E& f; `% G2 B3 Z+ d
- # Example:$ ?1 t3 |4 w) A' N
- #
! X5 H9 T3 m! |! w* X" F - # rename-command CONFIG b840fc02d524045429941cc15f59e41cb7be6c52
5 @! o2 X- D( M - #4 f. m! i/ J1 {7 X1 f4 m1 k
- # It is also possible to completely kill a command by renaming it into" v3 n/ x. D N! H
- # an empty string:
$ \3 n( W& `* z7 ^ - #" i2 p p* {0 y# |# W
- # rename-command CONFIG ""& j6 w' b1 w; W: V
- " x: X, H5 |) E1 N* m
- ################################### LIMITS ####################################7 |' |( c* \& S: E2 H
$ J8 ^5 w0 ?& ^7 U# I- # Set the max number of connected clients at the same time. By default
3 F) Z6 w! z( q. d [ - # this limit is set to 10000 clients, however if the Redis server is not
; r( C; b+ A4 s1 ^& m! G9 } - # able to configure the process file limit to allow for the specified limit
( Z# m# t' ^# U2 h/ q* ^( w - # the max number of allowed clients is set to the current file limit
/ `+ g' [) x. Y M9 |: g - # minus 32 (as Redis reserves a few file descriptors for internal uses).0 Y" F; s4 r3 P! f
- #
, H! Z' e8 n. T- Q - # Once the limit is reached Redis will close all the new connections sending
' k" |& g* a" q - # an error 'max number of clients reached'., o/ w- d- |7 ?' z' o( f8 g
- #
; b/ h, |$ F- [7 A9 t3 ?1 @8 x - maxclients 500
( y! `& V a" N
R; L- P6 i; C6 n" U3 w- # Don't use more memory than the specified amount of bytes.
# H% ]* y+ U2 z) [* o& b% C5 y% h% B - # When the memory limit is reached Redis will try to remove keys
2 ?' C2 W0 J5 K0 W. A, M/ O - # accordingly to the eviction policy selected (see maxmemmory-policy).
' ~3 g7 e. o# T; W( j - #
: R" z; B0 `, ?4 Y - # If Redis can't remove keys according to the policy, or if the policy is
& ^7 O! M; t8 M E - # set to 'noeviction', Redis will start to reply with errors to commands+ q* j0 y, n: ^5 \+ V$ C( @ s
- # that would use more memory, like SET, LPUSH, and so on, and will continue, ?- L0 ]/ m9 j" K/ n
- # to reply to read-only commands like GET.# m6 `* w9 c0 T& j
- #( [0 J2 w0 C: e) L, K8 j$ S/ E
- # This option is usually useful when using Redis as an LRU cache, or to set. E! m! X4 _# |* e# `5 Q7 ^" h
- # an hard memory limit for an instance (using the 'noeviction' policy).
! w4 {/ ]! r! @5 l& ^7 i - #9 V+ O8 q7 \8 b7 `4 b6 w8 H4 L
- # WARNING: If you have slaves attached to an instance with maxmemory on,# A/ D7 C. g; U# o7 H5 j
- # the size of the output buffers needed to feed the slaves are subtracted
$ L2 I' T! F9 q9 t5 _$ C& p: ] - # from the used memory count, so that network problems / resyncs will5 H& C# ~& u' @3 C, n; P1 d6 j4 C4 D
- # not trigger a loop where keys are evicted, and in turn the output
R- t: U& I+ Y9 x - # buffer of slaves is full with DELs of keys evicted triggering the deletion
0 h3 y! P2 E7 r - # of more keys, and so forth until the database is completely emptied.
- G2 X. i9 z. v8 x0 { - #
, r8 x; z9 U% m - # In short... if you have slaves attached it is suggested that you set a lower
. L9 l5 R0 a2 t4 ~5 U, S/ m - # limit for maxmemory so that there is some free RAM on the system for slave
& F2 S5 b. B; b - # output buffers (but this is not needed if the policy is 'noeviction').5 c* d! c9 K! n1 y& k
- #
) }; y( g, n% x: w+ b; r- c - maxmemory 128000000. e9 ^/ Z! i7 }2 o0 ^
- 5 B& Y3 r% E3 W, h3 }9 \ o
- # MAXMEMORY POLICY: how Redis will select what to remove when maxmemory
1 L/ n: I0 T7 u1 C* w1 D - # is reached. You can select among five behaviors:
9 b* F1 o# J8 `6 @0 ^& ^0 P - # 8 D. {) e) X! f7 K4 e" r# x7 N
- # volatile-lru -> remove the key with an expire set using an LRU algorithm( V8 I7 l2 ]4 W7 ]
- # allkeys-lru -> remove any key accordingly to the LRU algorithm$ v% h" U6 y; F
- # volatile-random -> remove a random key with an expire set
( V. P0 k, m1 n) u - # allkeys-random -> remove a random key, any key
" s8 d& k0 y2 l) B. H9 \3 n4 S - # volatile-ttl -> remove the key with the nearest expire time (minor TTL)
7 \1 T$ a9 a, d7 }! T v b - # noeviction -> don't expire at all, just return an error on write operations
w( G. h# _5 w, S7 M - # / `, a$ x/ N: r# j0 q6 r9 q
- # Note: with any of the above policies, Redis will return an error on write
: U7 T# `! a. `/ Y - # operations, when there are not suitable keys for eviction.
) `3 |$ S x! ~# l Q - #% U. c' b$ p! f" c2 p! W7 u
- # At the date of writing this commands are: set setnx setex append- ?7 q7 ^ w9 w) P8 M
- # incr decr rpush lpush rpushx lpushx linsert lset rpoplpush sadd8 s# I* ~& Q- K2 d7 I
- # sinter sinterstore sunion sunionstore sdiff sdiffstore zadd zincrby
$ {" [2 T, F+ H6 H+ C - # zunionstore zinterstore hset hsetnx hmset hincrby incrby decrby. u6 S: F, ~4 R
- # getset mset msetnx exec sort4 H8 h* H8 Y+ c
- #1 G+ ~9 h( Y* y5 i5 Y
- # The default is:
; ]. I6 a: p1 _3 g9 { - # P# O4 ]$ G5 g3 F! D; g" u- q
- # maxmemory-policy volatile-lru
5 F& K+ B: v) A- V. O, N - ; O- H3 J- R" W ?0 z
- # LRU and minimal TTL algorithms are not precise algorithms but approximated1 R3 D* S: Y" S
- # algorithms (in order to save memory), so you can select as well the sample) L1 K9 `( U, @9 p( r
- # size to check. For instance for default Redis will check three keys and
: M4 C C9 r' {( \$ |2 P - # pick the one that was used less recently, you can change the sample size* E; c7 o9 {1 S. g$ W2 ?) L/ P
- # using the following configuration directive.0 B$ V& o! c/ Z' g& {) |% h5 [
- #) D4 z! Z4 {( ?5 f
- # maxmemory-samples 3" u4 r$ r( o, n: K& O0 C7 q. j
2 ]1 `- z. l$ N- ############################## APPEND ONLY MODE ###############################* |- d2 o! U; M
1 [' J" ?% L; Z. K- # By default Redis asynchronously dumps the dataset on disk. This mode is- u- o) y5 Z1 H
- # good enough in many applications, but an issue with the Redis process or# }; M- W9 x* Y' f+ h
- # a power outage may result into a few minutes of writes lost (depending on
0 o5 V1 g, p6 P r& B - # the configured save points).
+ J+ \6 O" V! ?+ e# r - #
/ P& L5 \3 j+ ~. ]8 w" g' a - # The Append Only File is an alternative persistence mode that provides8 M& y$ a0 P/ _6 E* _
- # much better durability. For instance using the default data fsync policy
0 i8 ~/ V0 R1 X& W - # (see later in the config file) Redis can lose just one second of writes in a
" Z6 G# e4 B H6 q. E - # dramatic event like a server power outage, or a single write if something
+ r9 `4 R) ~' P8 B9 b - # wrong with the Redis process itself happens, but the operating system is
# p* K W# m3 _/ {4 c" I( Y - # still running correctly.
1 O; ]% l2 G6 m/ G - #8 S$ l" M- l/ F9 W5 D" G
- # AOF and RDB persistence can be enabled at the same time without problems.$ _/ s1 s" }# Q3 ]) {3 I
- # If the AOF is enabled on startup Redis will load the AOF, that is the file
- f3 F. ]! h3 r ~9 E" E - # with the better durability guarantees.
, [8 B: M$ t! A- @ - #) x: e( u- o+ ] Z6 N
- # Please check http://redis.io/topics/persistence for more information.. B' R/ [8 P2 o- r1 ^
: Q. m' u* T8 Q5 q Q7 g: a; K- appendonly no3 @7 [! t! {8 U/ C1 P
; ~& W# S/ @% d* g. p( N* a- # The name of the append only file (default: "appendonly.aof")9 J6 M7 S" Z' g
- # appendfilename appendonly.aof- S: K, ~5 r, S+ s
- , t( T4 q2 A& Z/ O
- # The fsync() call tells the Operating System to actually write data on disk
# y5 U; N5 v' S# Y - # instead to wait for more data in the output buffer. Some OS will really flush Y. D5 a$ d( c& R2 e# \. Q# Y: Q
- # data on disk, some other OS will just try to do it ASAP.
, m4 `9 p5 D* y i! E, y4 C% f - #
4 K% O" g% R2 T - # Redis supports three different modes:
/ B9 L3 j# X, a0 }' y - #+ l6 F N1 r' R& [
- # no: don't fsync, just let the OS flush the data when it wants. Faster.
3 w) ?/ }0 y2 C2 n2 s7 l - # always: fsync after every write to the append only log . Slow, Safest.
7 S. n9 ?" k4 I - # everysec: fsync only one time every second. Compromise.
, W4 ~6 Q6 Y/ Q8 a( \" x - #" f, P, S' G9 g M
- # The default is "everysec", as that's usually the right compromise between
2 g4 K) B8 t8 {' w) ~4 s7 w/ N: b - # speed and data safety. It's up to you to understand if you can relax this to! L# P% r4 P( ]
- # "no" that will let the operating system flush the output buffer when
0 ^1 P, ~" o( x3 C; J5 V( ] - # it wants, for better performances (but if you can live with the idea of
4 w: j3 s) e# q - # some data loss consider the default persistence mode that's snapshotting),
6 K4 d M6 l' O3 ` - # or on the contrary, use "always" that's very slow but a bit safer than V0 ?- }9 h% D
- # everysec.$ W4 g# I- g9 D/ c9 C
- #
' x/ P9 T( N0 q5 P5 G/ U- h - # More details please check the following article:0 ]) A9 W, ~" u" L: z. q5 t6 M4 t
- # http://antirez.com/post/redis-persistence-demystified.html/ h& U4 N* s0 X* m; Z. C4 H
- #+ Y* ~7 E [- m% q1 I S
- # If unsure, use "everysec".# E+ S t8 ?# e. b2 i
- : C7 j$ t! q& H7 D& |' \
- # appendfsync always4 A4 q1 n+ q2 ]' t0 I
- appendfsync everysec
& d0 M, x9 x! F9 v q - # appendfsync no' n# ], q [' R. Z
9 ? o$ |! y* X. G3 y. ]% c8 P7 Q, D! f- # When the AOF fsync policy is set to always or everysec, and a background
( n6 k& q2 [% M+ x( v - # saving process (a background save or AOF log background rewriting) is4 { j( t' U% x7 R) N
- # performing a lot of I/O against the disk, in some Linux configurations' R/ P+ ]+ }5 ~
- # Redis may block too long on the fsync() call. Note that there is no fix for- O" x+ a7 I. m! r
- # this currently, as even performing fsync in a different thread will block" M$ H1 K- y1 G6 M$ o8 g: l+ A
- # our synchronous write(2) call.
; @# p7 G, y5 c! g: \3 e4 @ - #, A/ n& N5 B& C& Y+ y- I3 Z
- # In order to mitigate this problem it's possible to use the following option
# ]9 d; N ~9 q" D% q1 c6 c7 C: R! V - # that will prevent fsync() from being called in the main process while a8 r" y2 [* z# j0 A2 }6 P
- # BGSAVE or BGREWRITEAOF is in progress.3 a0 A" q* P8 O4 v# D3 k9 `9 R
- #
4 D R" M' E/ S - # This means that while another child is saving, the durability of Redis is
( B1 x4 h2 e, \$ W4 P$ t% [ - # the same as "appendfsync none". In practical terms, this means that it is
4 b. A- F- @0 h - # possible to lose up to 30 seconds of log in the worst scenario (with the
. t% z8 t" N$ @. f' R( f - # default Linux settings).
a2 z, ]" B, G% j9 G, `3 j - #
( r1 R5 f7 Y! W+ A" g- l - # If you have latency problems turn this to "yes". Otherwise leave it as" ?" F. l/ g) S# A, t
- # "no" that is the safest pick from the point of view of durability.8 T, B# [3 d/ Z# @9 Y
- no-appendfsync-on-rewrite no* ]5 f6 d* W3 ]5 l5 [/ l
2 J; u; P3 } s! F3 N- # Automatic rewrite of the append only file.
2 |1 t2 J% a. f7 } - # Redis is able to automatically rewrite the log file implicitly calling! U+ L, D; I, e, c7 i. u
- # BGREWRITEAOF when the AOF log size grows by the specified percentage.! }, ~$ L1 N. r4 N# U% K z! L y
- # 4 I7 Q5 b) g4 A4 k
- # This is how it works: Redis remembers the size of the AOF file after the
# x, \2 O9 a* C t - # latest rewrite (if no rewrite has happened since the restart, the size of7 K1 D8 M$ L$ Q' V, d# }
- # the AOF at startup is used).' h9 B% k2 j9 A& l' y
- #; b5 b: Z3 M# i5 v* c
- # This base size is compared to the current size. If the current size is1 E6 i$ N: G2 R/ V2 O5 F& i* ?+ X+ G) Z
- # bigger than the specified percentage, the rewrite is triggered. Also% p8 P. r' p: ]3 @( e* `/ a5 _% p
- # you need to specify a minimal size for the AOF file to be rewritten, this* s& H% L% r7 F( P# W1 f X' K! ^! ^- r9 w
- # is useful to avoid rewriting the AOF file even if the percentage increase: s0 [, g) n& a" [
- # is reached but it is still pretty small.
" a0 R5 T+ O" P- j - #+ W3 g$ |$ p0 s- K" p4 n
- # Specify a percentage of zero in order to disable the automatic AOF
& P5 Q. a2 _7 O& H& a" |7 j; ~ - # rewrite feature.( m! _ D8 ~* _# |% b6 A
- 5 j$ e! n0 d' ^. z4 n4 l
- auto-aof-rewrite-percentage 100
/ E2 g" B) m) x* o9 s+ b* ]1 N- j - auto-aof-rewrite-min-size 64mb
0 G# T9 p5 n* E2 P% l8 |( P$ F8 \ - 7 u3 a! w) i5 k u2 a2 \+ @
- ################################ LUA SCRIPTING ###############################
: B3 I$ r2 l: |1 @ - - z: R8 o( d4 F4 z3 Q s8 c2 L7 k$ h
- # Max execution time of a Lua script in milliseconds.
0 f" n% R3 o$ P$ I - #) X5 E, f1 c/ G! w( r4 F! ?
- # If the maximum execution time is reached Redis will log that a script is1 x; Y% X7 h" }; |. H
- # still in execution after the maximum allowed time and will start to
+ ~. F& ^' ^1 } - # reply to queries with an error.
; e0 ]3 b+ \3 r) N" |9 v3 e - #1 M. {- H; q( e2 y
- # When a long running script exceed the maximum execution time only the
/ [) i0 P) y" o9 @ E: Z# G - # SCRIPT KILL and SHUTDOWN NOSAVE commands are available. The first can be
& e5 \ M" n }9 Z* G - # used to stop a script that did not yet called write commands. The second! k P) W( [: h: Z8 f9 P# ~
- # is the only way to shut down the server in the case a write commands was
( T$ B8 k+ Q) h9 N" `8 _ - # already issue by the script but the user don't want to wait for the natural/ r/ k9 g1 i/ r0 ]; b, |
- # termination of the script.
% M6 _) }) K- D3 N. N& k; ]' W) _4 G - #* H* x4 I7 u1 y* c* }4 e9 x
- # Set it to 0 or a negative value for unlimited execution without warnings.. M$ ^5 C# R, J7 t0 a* W
- lua-time-limit 5000# L0 r# Z# h3 D7 l5 x6 t* @
- - F- f- {' H' K2 y) A5 N- A- o
- ################################## SLOW LOG ###################################- V0 e' a9 f- `: T7 ?! q
) M( h& X9 [6 W" B9 v8 c- # The Redis Slow Log is a system to log queries that exceeded a specified
% t& f# A- q/ I5 `8 d1 Q+ e - # execution time. The execution time does not include the I/O operations
* q- r" Y0 a0 H9 n4 ]/ h - # like talking with the client, sending the reply and so forth,9 e, u5 [9 ?, L7 _% s" c
- # but just the time needed to actually execute the command (this is the only/ E. }4 @1 s8 N- t- F9 U
- # stage of command execution where the thread is blocked and can not serve/ C, K7 O0 W* Z9 T7 W8 `
- # other requests in the meantime).- ]# o3 @ \: N
- # + j1 J9 ^ V' m7 f
- # You can configure the slow log with two parameters: one tells Redis
# c" [. j/ ~6 W: i: B/ h - # what is the execution time, in microseconds, to exceed in order for the
4 z) l* {% {) f! V2 f) R - # command to get logged, and the other parameter is the length of the
" p% y' ?( u+ ]( h2 ^& D - # slow log. When a new command is logged the oldest one is removed from the4 [# b5 r" u+ _1 S, A; W6 i7 K* \
- # queue of logged commands.: t9 l/ h" m9 e3 v
# t+ s# w' s4 _# R# s- # The following time is expressed in microseconds, so 1000000 is equivalent5 a+ x: i; l# V, F, U* i/ Z, o* y$ h
- # to one second. Note that a negative number disables the slow log, while- n% {" j' ]5 G
- # a value of zero forces the logging of every command.) `. E* n/ L6 a' Q3 J2 @; x' e
- slowlog-log-slower-than 100009 s: P& g, d3 g+ n, r% x4 h' S
0 m$ m- `. C% w- # There is no limit to this length. Just be aware that it will consume memory.8 D: I8 c z. [: q
- # You can reclaim memory used by the slow log with SLOWLOG RESET.
! N* j, [: Y- u" g+ E0 L1 h6 u# c - slowlog-max-len 128
/ `2 e. Z4 \, s4 X* I
" f. e0 [) V- L! e* g; G) \- ############################### ADVANCED CONFIG ###############################
- d2 z' M6 g8 {/ K2 X7 q4 U+ Z
5 Y- `( Q) `; w t) X# L, M @- # Hashes are encoded using a memory efficient data structure when they have a
, W0 ] h# w) |* u - # small number of entries, and the biggest entry does not exceed a given& l' L. P/ ~: X) {5 J5 W
- # threshold. These thresholds can be configured using the following directives.. i* l3 Z7 u, B5 ~1 s! S
- hash-max-ziplist-entries 512, t, S- h, ^" x) F& o0 o$ j$ \2 `
- hash-max-ziplist-value 64% H. R; ?7 b; N; X( l; X
/ W* Z' w/ }8 V- Z q- # Similarly to hashes, small lists are also encoded in a special way in order3 _7 U. ?" b2 [% X
- # to save a lot of space. The special representation is only used when) l7 ?. n B' O
- # you are under the following limits:/ b. I. g' ?2 y* a
- list-max-ziplist-entries 512# `0 n: j- _" E% Z S
- list-max-ziplist-value 64
b5 R0 I% g5 h( T
z5 `4 D. `, [3 L9 l4 B- # Sets have a special encoding in just one case: when a set is composed; \5 p- f7 i% Q
- # of just strings that happens to be integers in radix 10 in the range
! ? U; a+ P% _ a8 ]' K - # of 64 bit signed integers.
# o9 g0 @# l6 Z - # The following configuration setting sets the limit in the size of the" Z7 _5 F4 l0 T: W% p2 D% ?0 ^
- # set in order to use this special memory saving encoding.
1 V$ }; V5 h, P. ^! ~( E - set-max-intset-entries 512
, Z; P2 c+ k% s" o, K' a6 h4 [& ^" g - + P: h+ n1 S9 e& r( x
- # Similarly to hashes and lists, sorted sets are also specially encoded in5 ~: p4 p! k1 B, S4 J% ?- `
- # order to save a lot of space. This encoding is only used when the length and
# f, P ?' o8 D% T - # elements of a sorted set are below the following limits:
% f" g6 J% m5 O% n: o n - zset-max-ziplist-entries 128( w G. q# n. {8 r @6 F7 I
- zset-max-ziplist-value 64$ k, x8 ? M3 l' C
- [! h5 |3 c1 J! z( L8 h! N& t- # Active rehashing uses 1 millisecond every 100 milliseconds of CPU time in0 ]" \% P2 {* e( M
- # order to help rehashing the main Redis hash table (the one mapping top-level
- P3 C7 {7 q P3 } - # keys to values). The hash table implementation Redis uses (see dict.c), \6 k* f& L; R
- # performs a lazy rehashing: the more operation you run into an hash table! M, Q$ {4 s2 U' p) g3 t
- # that is rehashing, the more rehashing "steps" are performed, so if the
C% C7 B- \% [+ v - # server is idle the rehashing is never complete and some more memory is used
9 T3 g5 k9 D6 N1 t6 a - # by the hash table.
* i8 }$ N+ F7 R |5 n9 f) R% A! J - #
+ [9 g- \/ P- V- J - # The default is to use this millisecond 10 times every second in order to i |. |! V( y3 ?9 n$ m2 n; J
- # active rehashing the main dictionaries, freeing memory when possible.
4 Z$ e( q( O: I3 `6 v - #0 i9 j7 E0 r2 \: k) J8 J- y
- # If unsure:9 d& o; p6 s5 Y9 n' D
- # use "activerehashing no" if you have hard latency requirements and it is* v2 Q9 _& C @
- # not a good thing in your environment that Redis can reply form time to time
) w: b! @1 ], s& a4 l1 l' a+ d* D - # to queries with 2 milliseconds delay.
1 c5 Z. m+ [! f% j4 r0 W N9 D& y' F - #' R+ I( P4 K0 |
- # use "activerehashing yes" if you don't have such hard requirements but7 i& v, C% ~6 Q" X5 Y
- # want to free memory asap when possible.8 `7 ~7 m! Q% x+ a
- activerehashing yes5 C. W' F& X4 S- a3 C1 P% x
3 ^; e" @1 E/ S2 ]6 {, U- # The client output buffer limits can be used to force disconnection of clients
; w/ \0 j" r1 r* N4 l4 J) {4 m/ ` - # that are not reading data from the server fast enough for some reason (a. x4 i/ M! \0 d! Y1 q9 O/ g+ d
- # common reason is that a Pub/Sub client can't consume messages as fast as the
& a' x* l9 K9 t+ Y1 O' q - # publisher can produce them).& a& f) H$ G* h4 d& I, P
- #
/ g4 f0 J& S& M: O6 w* G - # The limit can be set differently for the three different classes of clients:
5 z3 Z/ R5 [+ ^( b r7 e - #% V( X; c3 X7 G! m1 F
- # normal -> normal clients
4 H" @, ?3 q* h/ ? - # slave -> slave clients and MONITOR clients" k6 r0 z/ A7 ?2 r6 Y
- # pubsub -> clients subcribed to at least one pubsub channel or pattern
) A. [& N) Y! I2 `* | - #0 X( i a3 |5 U4 y: X) a
- # The syntax of every client-output-buffer-limit directive is the following:
4 |% H2 m6 z; p0 z3 W% r+ l - #
( q0 q N% ~# }0 z; ^- C# b - # client-output-buffer-limit <class> <hard limit> <soft limit> <soft seconds>
) @9 R( P. ?+ U# e+ a6 l, }+ p - #
" @2 e" g2 L5 D {# i0 |( g4 a - # A client is immediately disconnected once the hard limit is reached, or if
8 k8 @: t/ s4 w A. l9 N7 x - # the soft limit is reached and remains reached for the specified number of) X- p1 U9 @6 y Q
- # seconds (continuously).
* b8 B; [" ?1 m8 S V) O- N - # So for instance if the hard limit is 32 megabytes and the soft limit is
' S# R$ q5 ?" o8 v2 J5 K) M* z - # 16 megabytes / 10 seconds, the client will get disconnected immediately1 a6 e' {5 e" ~
- # if the size of the output buffers reach 32 megabytes, but will also get
$ R0 B& J3 _/ E2 V e- q$ i u: h - # disconnected if the client reaches 16 megabytes and continuously overcomes1 Q0 P7 z5 P8 `- D( H* ~
- # the limit for 10 seconds.
+ y# H8 D* ~/ y( a6 d - # G+ r' b* F. ^; t
- # By default normal clients are not limited because they don't receive data
" A$ d- I. e+ x: K - # without asking (in a push way), but just after a request, so only
1 X9 ^& r/ C3 X& o( ?, D0 n% y - # asynchronous clients may create a scenario where data is requested faster
7 r- J4 [4 c9 T; O. b4 n - # than it can read.
1 s3 U& u0 V1 ?' E$ ? - #( H/ J: y+ n1 i& H! d# k
- # Instead there is a default limit for pubsub and slave clients, since
% v% A4 n2 B8 _% M - # subscribers and slaves receive data in a push fashion.
% V& ]* {) z- h6 N - #: ?' I3 J" T; b0 M5 R) w4 f- j# h: ?) u
- # Both the hard or the soft limit can be disabled by setting them to zero.1 v" P2 Z. ~0 k2 S+ Y+ P# v
- client-output-buffer-limit normal 0 0 0
" E/ x; [4 A) T. d' X$ ?% ^ - client-output-buffer-limit slave 256mb 64mb 60
' {3 V. W1 |+ V, y - client-output-buffer-limit pubsub 32mb 8mb 60
5 [4 B" ?7 S: {1 H6 q1 V - % m# T, E! |6 Y0 q# O
- ################################## INCLUDES ###################################& M& Z* k/ `, [* f
7 y7 m( ^1 s( E* a7 a3 m- # Include one or more other config files here. This is useful if you" ], \" W8 L" O4 F6 ^% e" E
- # have a standard template that goes to all Redis server but also need
: b/ i& p; Z: q4 t% Q2 K - # to customize a few per-server settings. Include files can include
" a! c2 E5 p) ~ - # other files, so use this wisely.2 @! v) M9 ?3 t% ^1 X
- #
, ^, d. b: ^. P. l1 { - # include /path/to/local.conf% w$ m9 X. R4 K6 F H' }2 \% t0 V
- # include /path/to/other.conf
. W) U \& F! V/ l6 a. R; D2 P9 a - ##########################配置文件结束################################
; w( u1 x! c( X* F - 第三步:启动进程3 |8 T0 s2 m8 D* t1 v! U9 |
- #redis-server /etc/redis.conf
5 F2 V7 J, c& `" h$ x - 查看进程有没有成功启动+ F1 {2 |! [% s8 z. |$ c+ z5 \+ V# d
- #ps -ef | grep redis 8 ]9 X: T7 t% T: c4 O
- 测试输入一个键值0 N& J8 N1 d! `
- #redis-cli set test "testredis"4 C. u! F. N2 f( X0 ^
- 获取键值0 C# w0 X) W' K; o2 v3 V" s2 c
- #redis-cli get test, `: [8 c0 z$ {/ m
) T( w) S' z- Z) `( g
3 E7 T9 ^. ~2 \& E F- 第四步:关闭redis (这个是更改配置文件后 正常的重启方式 不重新加载redis配置跳过)( W$ E) g% h* F. a% k) `' _
- # redis-cli shutdown //关闭所有
8 x& S7 X4 ~9 H/ K f - 关闭某个端口上的redis
: M1 q9 Q {2 b9 n2 k2 I4 V - # redis-cli -p 6397 shutdown //关闭6397端口的redis 5 \. d/ p( J! x6 V
- 说明:关闭以后缓存数据会自动dump到硬盘上,硬盘地址见redis.conf中的dbfilename dump.rdb
1 A! b% { w) {6 o9 d" `! o+ b - . L2 N; `: p8 V" d/ s" x3 N
6 S2 a( U! y1 h& Q0 Q- 第5步:php扩展安装
# |# ?) t3 U9 s4 \ - phpredis PHP扩展下载地址 ; H& d) ?: }$ _3 O- N+ @
- https://github.com/nicolasff/phpredis/tree/2.2.2 5 z" |# O: Z# ^8 n" e1 a2 r5 g
- 选择最新版本下载zip
% h- P3 [. o: o+ i/ v
; \7 _+ P0 Z- ^( X' H- 然后自己上传zip 用unzip解压到当前目录 unzip 文件名
: H& d4 c9 \8 u7 @+ Q- ?( c - ! \' ^2 _- l! T8 U; A0 ^* _$ e
- # cd owlient-phpredis-90ecd17/ #打开解压后的文件夹里面 这个解压后的目录 要是不知道 可以输入 "dir" 查看4 J t2 L9 R& C) L. y' R
- # /www/nginx_php-5.2.17/bin # h* d" G [1 u$ ~7 l
- # ./configure --with-php-config=/www/nginx_php-5.2.17/bin/php-config8 W9 }& @3 _; F: j. y. J8 q
- #make
) g- ~4 m8 v4 @# b5 E" C p - #make install #记录产生的redis.so路径
0 t" C2 j0 C5 _; y
, j4 N: T0 N0 \' d4 g, l( |- 修改php.ini文件4 s+ k5 a6 Z* q/ r$ x+ G, P
- 在php.ini中添加如下一行:! J9 v# K) W6 j
- extension=/?/redis.so #是刚刚记录的产生redis.so的路 写在 ?那
: i% M9 k1 R) I- k. r - 重启 使之生效:! a- f; F4 ?6 y: o" _# \5 F
- /usr/local/php/sbin/php-fpm reload. K, E. F, e" K7 J2 _
- /usr/local/nginx/sbin/nginx -s reload
- P9 g+ n# t ~, Q/ f - 5 d0 e: m- j: H$ i; N9 |) h
- 将 Redis 作为 Linux 服务随机启动
: r/ \' ]# p6 s0 L1 | - vi /etc/rc.local, 加入代码:- H% _6 L- l$ _4 x7 A, |* s
- /root/redis-2.6.10/src/redis-serve #路径看情况修改
, z: z% l0 ^; A |- T - / P6 i, I4 Q, `
- redis-cli -h localhost -p 6379 info #命令要在redis目录下面执行1 g, s5 E6 f% B J3 d
- 提供host为localhost,端口为6379,redis服务的统计信息
. N+ K: ^( s+ {# U/ i
( V M8 X- N( F
9 E _; J. W& B# |, W, X* u- 就这样你的web服务器就支持redis了 记得要在 给dz 的配置文件 加上12.0.0.1哦9 b1 x- _! w& ~% |& b" d
- dz配置文件在 config目录下面的 config_global.php- M: s7 `- h% j
- $_config['memory']['redis']['server'] = '127.0.0.1';# t* \3 o. a% h: v: P+ t
- $_config['memory']['redis']['port'] = 6379;
( v, p/ A3 H b1 z4 o - $_config['memory']['redis']['pconnect'] = 1;/ m b3 z8 ?7 e& T. G. z
- $_config['memory']['redis']['timeout'] = '0';$ J5 l9 `5 ?2 F% @# A' N( k& _. Z
- $_config['memory']['redis']['serializer'] = 1;/ h0 A! a' |5 S" _) V) [
复制代码 |
|