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