Explanation of the redis configuration file

Source: Internet
Author: User
Tags lzf password protection redis server

Reprinted from: http://www.cnblogs.com/daizhj/articles/1956681.html to some configuration options made some instructions

I have read the configuration item from top to bottom. I have a general understanding of it. For now, I still cannot use some advanced configuration options. I will put them here first, and I will try again later.

Configuration File Parameters:

 

1. redis does not run as a daemon by default. You can modify this configuration item and use yes to enable the daemon.

Daemonize No

2. When redis runs as a daemon, redis writes the PID to the/var/run/redis. PID file by default, which can be specified through pidfile

Pidfile/var/run/redis. PID

3. specify the redis listening port. The default port is 6379. The author explains in his blog why 6379 is used as the default port, because 6379 corresponds to the Merz number on the mobile phone key, merz is taken from the name of Alessia Merz, an Italian singer.

Port 6379

4. Bound host address

Bind 127.0.0.1

5. When the client is idle for a long time, the connection is closed. If it is set to 0, the function is disabled.

Timeout 300

6. Specify the log record level. redis supports four levels in total: Debug, verbose, notice, and warning. The default value is verbose.

Loglevel verbose

7. log Record mode. The default value is standard output. If redis is configured to run in daemon mode and the log record mode is set to standard output, the log will be sent to/dev/null.

Logfile stdout

8. Set the number of databases. The default database is 0. You can use the select <dbid> command to specify the database ID for the connection.

Databases 16

9. specify how many update operations are performed within the specified time period to synchronize data to the data file. Multiple conditions can be used together.

Save <seconds> <changes>

The default configuration file of redis provides three conditions:

Save 900 1

Save 300 10

Save 60 10000

1 change in 900 seconds (15 minutes), 10 Changes in 300 seconds (5 minutes), and 10000 changes in 60 seconds.

 

10. Specify whether to compress data when stored in the local database. The default value is yes. redis uses lzf to compress data. To save CPU time, disable this option, but this will cause huge changes in database files.

Rdbcompression Yes

11. Specify the local database file name. The default value is dump. RDB.

Dbfilename dump. RDB

12. Specify the local database storage directory

Dir ./

13. Set the IP address and port of the master service when the local machine is Slav service. When redis is started, it will automatically synchronize data from the master.

Slaveof <masterip> <masterport>

14. When password protection is set for the master service, the Slav service connects to the master password

Masterauth <master-Password>

15. Set the redis connection password. If the connection password is configured, the client must use the auth <password> command to provide the password when connecting to redis. The password is disabled by default.

Requirepass foobared

16. Set the maximum number of client connections at the same time. By default, there is no limit. The number of client connections that redis can open at the same time is the maximum number of file descriptors that redis processes can open. If you set maxclients 0, no limit is imposed. When the number of client connections reaches the limit, redis closes the new connection and returns the Max number of clients reached error message to the client.

Maxclients 128

17. specify the maximum memory limit of apsaradb for redis. redis loads data into the memory at startup. After the maximum memory is reached, redis first tries to clear the expired or expiring key, after this method is processed, it still reaches the maximum memory setting, and no write operation can be performed, but the read operation can still be performed. Redis's new VM mechanism stores keys in memory, and values in the SWAp Area

Maxmemory <bytes>

18. specify whether to record logs after each update operation. redis asynchronously writes data to the disk by default. If this parameter is not enabled, data may be lost for a period of time during power failure. Because redis synchronizes data files according to the Save conditions above, some data will only exist in the memory for a period of time. The default value is no.

Appendonly No

19. Specify the Update log file name. The default value is appendonly. Aof.

Appendfilename appendonly. aof

20. Specify the log update conditions. There are three optional values:
No: Indicates that the data cache is synchronized to the disk (FAST) by the operating system)
Always: Indicates that fsync () is manually called after each update operation to write data to the disk (slow and secure)
Everysec: Indicates synchronization once per second (compromise, default value)

Appendfsync everysec

 

21. specifies whether to enable the virtual memory mechanism. The default value is no. For a brief introduction, the VM mechanism stores data on pages, and redis stores cold data on the disk, that is, pages with less traffic, multiple accessed pages are automatically swapped out from the disk to the memory (I will carefully analyze the VM mechanism of redis in the following article)

VM-enabled No

22. virtual memory file path. The default value is/tmp/redis. Swap. It cannot be shared by multiple redis instances.

VM-Swap-file/tmp/redis. Swap

23. store all data greater than VM-max-memory into the virtual memory. No matter how small the VM-max-memory settings are, all index data is stored in the memory (redis's index data is keys ), that is to say, when VM-max-memory is set to 0, all values exist on the disk. The default value is 0.

VM-max-memory 0

24. redis swap files are divided into many pages. One object can be stored on multiple pages, but one page cannot be shared by multiple objects, VM-page-size is set based on the size of stored data. The author suggests that if many small objects are stored, the page size should be set to 32 or 64 bytes. If a large object is stored, you can use a larger page. If you are not sure, use the default value.

VM-page-size 32

25. set the number of pages in the swap file. Because the page table (a bitmap indicating that the page is idle or used) is in the memory, every 8 pages on the disk consumes 1 byte of memory.

VM-pages 134217728

26. set the number of threads used to access the swap file. It is best not to exceed the number of server cores. If it is set to 0, all operations on the swap file are serial, which may cause a long delay. The default value is 4.

VM-max-threads 4

27. Set whether to combine a small package into a package for sending when responding to the client. The function is enabled by default.

Glueoutputbuf Yes

28. When a specified number or maximum element exceeds a critical value, a special hash algorithm is used.

Hash-max-zipmap-entries 64

Hash-max-zipmap-value 512

29. Specify whether to enable or disable hash resetting. The default setting is enable (this will be detailed later when we introduce the hash algorithm of redis)

Activerehashing Yes

30. Specify other configuration files. You can use the same configuration file between multiple redis instances on the same host, and each instance has its own specific configuration file.

Include/path/to/local. conf

 

Bytes ------------------------------------------------------------------------------------------------------------------------------

Complete configuration file:

# Redis configuration file example

 

# By default redis does not run as a daemon. Use 'yes' if you need it.

# Note that redis will write a PID file in/var/run/redis. PID when daemonized.

Daemonize No

 

# When run as a daemon, redis write a PID file in/var/run/redis. PID by default.

# You can specify a custom PID file location here.

Pidfile/var/run/redis. PID

 

# Accept connections on the specified port, default is 6379

Port 6379

 

# If you want you can bind a single interface, if the BIND option is not

# Specified all the interfaces will listen for connections.

#

# Bind 127.0.0.1

 

# Close the connection after a client is idle for n seconds (0 to disable)

Timeout 300

 

# Set server verbosity to 'debug'

# It Can Be one:

# Debug (a lot of information, useful for development/Testing)

# Notice (moderately verbose, what you want in production probably)

# Warning (only very important/critical messages are logged)

Loglevel debug

 

# Specify the log file name. Also 'stdout' can be used to force

# The demon to log on the standard output. Note that if you use standard

# Output for logging but daemonize, logs will be sent to/dev/null

Logfile stdout

 

# Set the number of databases. The default database is db 0, you can select

# A different one on a per-connection basis using select <dbid> where

# Dbid is a number between 0 and 'databases'-1

Databases 16

 

################################ Snapshotting (snapshot) #################################

#

# Save the DB on disk:

#

# Save <seconds> <changes>

#

# Will Save the DB if both the given number of seconds and the given

# Number of write operations against the DB occurred.

#

# In the example below the behaviour will be to save:

# After 900 Sec (15 min) if at least 1 key changed

# After 300 Sec (5 min) if at least 10 keys changed

# After 60 sec if at least 10000 keys changed

Save 900 1

Save 300 10

Save 60 10000

 

# Compress string objects using lzf when dump. RDB databases?

# For default that's set to 'yes' as it's almost always a win.

# If you want to save some CPU in the saving child set it to 'no'

# The dataset will likely be bigger if you have compressible values or keys.

Rdbcompression Yes

 

# The filename where to dump the DB

Dbfilename dump. RDB

 

# For default save/load dB in/from the working directory

# Note that you must specify a directory not a file name.

Dir ./

 

################################# Replication ###### ###########################

 

# Master-slave replication. Use slaveof to make a redis instance a copy

# Another redis server. Note that the configuration is local to the slave

# So for example it is possible to configure the slave to save the DB with

# Different interval, or to listen to another port, and so on.

#

# Slaveof <masterip> <masterport>

 

# If the master is password protected (using the "requirepass" configuration

# Directive below) it is possible to tell the slave to authenticate before

# Starting the replication synchronization process, otherwise the master will

# Refuse the slave request.

#

# Masterauth <master-Password>

 

################################## Security ##### ##############################

 

# Require clients to issue auth <password> before processing any other

# Commands. This might be useful in environments in which you do not trust

# Others with access to the host running redis-server.

#

# This shoshould stay commented out for backward compatibility and because most

# People do not need auth (e.g. They run their own servers ).

#

# Requirepass foobared

 

################################### Limits #### ################################

 

# Set the Max number of connected clients at the same time. By default there

# Is no limit, and it's up to the number of file descriptors The redis Process

# Is able to open. The special value '0' means no limts.

# Once the limit is reached redis will close all the new connections sending

# An error 'max number of clients reached '.

#

# Maxclients 128

 

# Don't use more memory than the specified amount of bytes.

# When the memory limit is reached redis will try to remove keys with

# Expire set. It will try to start freeing keys that are going to expire

# In little time and preserve keys with a longer time to live.

# Redis will also try to remove objects from free lists if possible.

#

# If all this fails, redis will start to reply with errors to commands

# That will use more memory, like set, lpush, and so on, and will continue

# To reply to most read-only commands like get.

#

# Warning: maxmemory Can Be A Good Idea mainly if you want to use redis as

# 'State' server or cache, not as a real dB. When redis is used as a real

# Database the memory usage will grow over the weeks, it will be obvious if

# It is going to use too much memory in the long run, and you'll have the time

# To upgrade. With maxmemory after the limit is reached you'll start to get

# Errors for write operations, and this may even lead to DB inconsistency.

#

# Maxmemory <bytes>

 

############################# Append only mode ####### ########################

 

# By default redis asynchronously (asynchronous) dumps the dataset on disk. If you can live

# With the idea that the latest records will be lost if something like a crash

# Happens this is the preferred way to run redis. If instead you care a lot

# About your data and don't want to that a single record can get lost you shoshould

# Enable the append only mode: When this mode is enabled redis will append

# Every write operation completed ed in the file appendonly. log. This file will

# Be read on startup in order to rebuild the full dataset in memory.

#

# Note that you can have both the async dumps and the append only file if you

# Like (You have to comment the "save" statements above to disable the dumps ).

# Still if append only mode is enabled redis will load the data from

# Log file at startup ignoring the dump. RDB file.

#

# The Name Of The append only file is "appendonly. log"

#

# Important: Check the bgrewriteaof to check how to rewrite the append

# Log file in background when it gets too big.

 

Appendonly No

 

# The fsync () call tells the operating system to actually write data on disk

# Instead to wait for more data in the output buffer. Some OS will really flush

# Data on disk, some other OS will just try to do it ASAP.

#

# Redis supports three different modes:

#

# No: Don't fsync, just let the OS flush the data when it wants. Faster.

# Always: fsync after every write to the append only log. Slow, safest.

# Everysec: fsync only if one second passed since the last fsync. Compromise.

#

# The default is "always" that's the safer of the options. It's up to you

# Understand if you can relax this to "everysec" that will fsync every second

# Or to "no" that will let the operating system flush the output buffer when

# It want, for better performances (but if you can live with the idea

# Some data loss consider the default persistence mode that's snapshoence ).

 

Appendfsync always

# Appendfsync everysec

# Appendfsync No

 

############################## Advanced config ####### ########################

 

# Glue small output buffers together in order to send small replies in

# Single TCP packet. uses a bit more CPU but most of the times it is a win

# In terms of number of queries per second. Use 'yes' if unsure.

Glueoutputbuf Yes

 

# Use object sharing. can save a lot of memory if you have always common

# String in your dataset, but performs lookups against the shared objects

# Pool so it uses more CPU and can be a bit slower. Usually it's a good

# Idea.

#

# When object sharing is enabled (required objects yes) You can use

# Define objectspoolsize to control the size of the pool used in order to try

# Object sharing. A bigger pool size will lead to better sharing capabilities.

# In general you want this value to be at least the double of the number

# Very common strings you have in your dataset.

#

# Warning: Object sharing is experimental, don't enable this feature

# In production before of redis 1.0-stable. Still please try this feature in

# Your development environment so that we can test it better.

# Define objects no

# Define objectspoolsize 1024

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.