Detailed Redis configuration parameters

Source: Internet
Author: User
Tags failover syslog password protection redis cluster

Redis is a high-performance Key-value database with a wide range of applications, similar to memcached, but more powerful!
In this paper, according to different functional modules, the configuration parameters of each function module are described in detail.

General

./redis-server/path/to/redis.confStart with the specified configuration file
include/path/to/other.confInclude other Redis profiles
daemonize YesEnable background daemon run mode
Pidfile/var/run/redis.pidProcess ID after redis boot save file
Port 6379Specify the port number to use
bind IPListens on the specified network interface
Unixsocket/tmp/redis.sockSpecifies the listening socket for the UNIX environment
Timeout NThe client disconnects after n seconds of inactivity, and parameter 0 indicates that it is not enabled
loglevel NoticeSpecifies the level at which the server information is displayed, with 4 parameters debug\verbose\notice\warning
logfile ""Specifies the log file, which defaults to using the system's standard output
syslog-enabled NoWhether logging to the System log feature is enabled, default is not enabled
syslog-ident RedisIf logging is enabled, you need to set the identity of the log record
syslog-facility local0If logging is enabled, you need to set the log facility with a value range of LOCAL0~LOCAL7 to indicate different log levels
databasesSet the number of databases, use DB0 by default when starting, use "select <dbid>"Database can be replaced
Tcp-backlog 511This parameter determines the length of the completed queue (after 3 handshake) in a TCP connection and should be less than the/proc/sys/net/core/somaxconn value of the Linux system, which defaults to 511, while the Somaxconn default value for Linux is 128. These two parameters can be improved at the same time when the concurrency is large and the client is slow to respond.
tcp-keepalive 0Specifies a time period of acks, in seconds, and a value other than 0 that indicates whether the periodic detection client is available and the default value is 60 seconds.

Snapshotting

Data Save frequency:
Save 1 is saved after 900 seconds, and at least 1 keys are changed before triggering
save after 300 seconds, at least 10 keys are changed to trigger
Save 10000 after 60 seconds, at least 10,000 keys are changed to trigger

Stop-writes-on-bgsave-error Yes the last save operation failed to stop the write operation
rdbcompression Yes to enable compression
rdbchecksum Yes enables the CRC64 checksum, which, of course, affects a part of the performance
dbfilename Dump.rdb Specifies the file name where the data is stored
dir./ Specify working directory, RDB file and aof file will be stored in this directory, the default is that the current directory

SECURITY

Requirepass foobared If a password verification is required for a slave-side connection

LIMITS

maxclients 10000 maximum number of clients connections at the same time, more than a number of connections will return an error message
maxmemory <bytes>Set Maximum memory
If memory usage reaches the maximum memory setting, there are 6 ways to handle it:

Remove Volatile-lru theKey with  anExpireSet using  anLRU Algorithmallkeys-lru, remove anyKey according to  theLRU algorithmvolatile-RandomRemovea RandomKey with  anExpireSetallkeys-RandomRemovea RandomKey anyRemove Keyvolatile-ttl theKey with  theNearest expire Time(minor TTL) noeviction, Don' t expire at all, just return a error on write operations

The default setting is maxmemory-policy noeviction
Maxmemory-samples 5 Number of keys checked by LRU algorithm

APPEND only MODE

appendonly Yes enable AOF mode
appendfilename "Appendonly.aof" sets the file name of the AOF record

There are 3 options for how often you write data to a disk:
always have new data to write immediately, slow but high reliability
everysec Write once per second, compromise method, so-called Redis can only lose 1 seconds of data is from here
no According to the OS's own brush write policy, the fastest
Use the options to set appendfsync everysec

No-appendfsync-on-rewrite No when the main process is writing to disk, other Fsync calls will be blocked
auto-aof-rewrite-percentage The percentage of automatic rewrite triggered by the aof file, and a value of 0 means that automatic rewrite is disabled
auto-aof-rewrite-min-size 64mb aof file triggers the smallest file size for automatic rewrite
aof-load-truncated Yes whether to load an incomplete aof file to start

LUA SCRIPTING

Lua-time-limit The maximum run time of the Lua script is set in milliseconds

EVENT NOTIFICATION

notify-keyspace-events "" event notification, default is not enabled, specific parameters to view the configuration file

REPLICATION

Redis's master-slave replication takes place asynchronously.
If the slave terminal is temporarily disconnected from the master end while synchronizing the connection, the connection is resumed allowing the slave to be partially resynchronized with the master side.
Master-slave replication is automated and does not require user intervention, and the slave will automatically attempt to re-connect the master and synchronize the data.
slaveof <master ip> <master port>Set the IP and port information on the master side
masterauth <master-password>If password protection is enabled on the master side (Requirepass), the slave side needs to configure this option
Slave-serve-stale-data Yes when the slave end is disconnected from master during master-slave replication, there are 2 ways to do this: one is to continue to service even though the data may not be up to date and the other is to return an error message to the request , the default configuration is to continue to provide services
slave-read-only Yes since Redis 2.6, the slave side defaults to ReadOnly

Master-Slave synchronization supports two strategies, disk and socket (socket is not perfect, still in the experimental phase).
The new slave end and the salve end of the re-connection are not allowed to continue the synchronization process, which is called "Full Synchronization".
An Rdb file is uploaded from the master to the slave end, in two cases:
1, support Disk:master end will be the Rdb file written to disk, and later transferred to the slave end;
2, no disk diskless:master side directly to the Rdb file to the slave socket, do not need to interact with disk.
The diskless disk-less approach is suitable for environments where disk reads and writes are slow but network bandwidth is high.
Repl-diskless-sync NoDiskless synchronization is not used by default
Repl-diskless-sync-delay 5A disk-less diskless method has a time delay before the data is passed so that the slave can proceed to the destination queue to be delivered, which is 5 seconds by default
Repl-ping-slave-period TenSlave sends the pings time interval setting to the server side, which defaults to 10 seconds
Repl-timeoutSetting the time-out period
Repl-disable-tcp-nodelay NoWhether to enable Tcp_nodelay, if enabled, uses a small amount of TCP packets and bandwidth to transfer data to the slave side, which of course is slower and, if not enabled, is faster, but consumes more bandwidth.
repl-backlog-size 1MBTo set the backlog size, the backlog is a buffer that holds the data to be synchronized to the slave at the slave end, so when a slave is to be re-connected, it is often not necessary to fully synchronize, and performing local synchronization is sufficient. The larger the backlog is set, the longer the slave can lose the connection.
Repl-backlog-ttl 3600If no slave is connected to master after a period of time, the memory of the backlog size will be freed. A value of 0 means that the partial memory is never freed.
slave-prioritySlave the priority setting of the end, the value is an integer, the smaller the number, the higher the priority. When Master fails, it will select the slave side for recovery by priority, and if the value is set to 0, the slave will never be selected.
Min-slaves-to-write 3
Min-slaves-max-lag TenSet when the available slave on a master side are less than N and the delay time is greater than m seconds, the write operation is not received.

REDIS CLUSTER

A normal Redis instance cannot be a node of a redis cluster unless it is started as a cluster node.
cluster-enabled Yes to configure Redis as a cluster node to boot
cluster-config-file node-6379.conf Each cluster node has a cluster configuration file that does not need to be edited and is created and updated by the Redis node. The cluster configuration file for each Redis node cannot be the same.
Cluster-node-timeout 15000 Sets the cluster node timeout, and if it exceeds the specified time-out period, the node is considered to be a failed state in milliseconds.

A slave that belongs to the master end of the failure and will not start failover if its data is older.
Now there is no easy way to solve the problem of how to determine the timeliness of a slave-side data, so you can do the following two choices:
1, if there are multiple slave available for failover, They exchange information in order to select an optimal master-slave copy of the Offset,slave end will try to get the rank of each slave based on offset, so that the use of each slave when starting failover is proportional to the slave side of rank.
2, each slave end and its master end of the last interaction time, which may be the most recent ping or instruction received time, or from the master end of the out-of-date time. If the recent interaction time is too long, slave will not attempt to failover. The
2nd can be adjusted by the user to make clear that a slave will not be failover. Since the most recent interaction with the master side, the obsolescence time has a calculation formula:
(node-timeout * slave-validity-factor) +repl-ping-slave-period
A larger slave-validity-factor parameter allows the slave side to use older data to failover its master side, while a smaller value may prevent the cluster from selecting the slave side.
to get maximum availability, you can set the value of Slave-validity-factor to 0, which means that the slave end will try to failover its master side regardless of the last interaction time it has with the master side.
cluster-slave-validity-factor default value is ten

The slave in the cluster can be migrated to the master side of the slave that are not available, which increases the ability of the cluster to handle failures. After all, a master end without slave if there is a failure, there is no way to carry out the failover.
To migrate a slave to another master, you must have at least a given number of available slave on the original master side of this slave to migrate, given the number set by the migration barrier parameter, the default value is 1, The original master side of the slave that is to be migrated should have at least 1 available slave to allow it to be migrated, and to disable this feature you only need to set this parameter to a very large value.
Cluster-migration-barrier 1

By default, when a Redis cluster node discovers that at least one hashslot has not been covered, it stops receiving queries.
In this case, if one part of the cluster is down, the entire cluster will become unusable.
The cluster will be automatically recovered after all the slots have been re-covered.
Set the parameter to no if you want to set the cluster to continue to receive queries when some key space is not cover completed.
Cluster-require-full-coverage Yes

SLOW LOG

Redis's slow log is a record query made by the System OS, which exceeds the specified execution time. The execution time does not include I/O operations such as interacting with the client or sending a reply, it is just the time of the actual execution of the instruction.
There are 2 parameters that can be configured, one to tell the Redis execution time, this time is microsecond (1 seconds =1000000 microseconds), this is to not omit the command. Another parameter is to set the length of the Slowlog, and when a new command is recorded, the oldest command will be removed from the command record queue.
Slowlog-log-slower-than 10000
Slowlog-max-len
You can use theslowlog resetcommand to free the memory that Slowlog occupies.

LATENCY MONITOR

Latency-monitor-threshold 0 Latency Monitoring, which records actions equal to or exceeding a specified time, is turned off by default, which is a value of 0.

Advanced CONFIG

When the number of entries is small and the maximum does not exceed the given threshold, the hash encoding uses a very efficient memory data structure that is configured with the following parameters.
hash-max-ziplist-entries
Hash-max-ziplist-value 64

Similar to hashing, a small amount of lists is encoded in a specified way to save more space, and its thresholds are configured with the following parameters.
list-max-ziplist-entries
List-max-ziplist-value 64

The set sets in a particular case when there is a specified encoding, which is the case that the collection consists of a set of numbers in the range of 64-bit signed integers that are 10 binary. The following options set the size limit for the collection to use this special encoding.
Set-max-intset-entries 512

Like hashes and lists, ordered collections also use a special encoding to save space, and this particular encoding is used only when the length of the ordered set and the elements are below the values set by the following parameters.
zset-max-ziplist-entries
Zset-max-ziplist-value 64

hll-sparse-max-bytes Set Hyeperloglog byte limit, this value is usually between 0~15000, the default is 3000, basically no more than 16000
activerehashing Yes Redis will extract 10 milliseconds per second to re-hash the main dictionary, which helps to free up memory as much as possible

For some reason, the client cannot read the data from the server fast enough, and the client's output cache limit may cause the client to be lost, which can be used for 3 different types of clients: normal, slave, and pubsub.
The format of the settings is as follows:

client-output-buffer-limit <class><hard limit><soft limit><soft seconds>

If the hard limit is reached, the client will lose its connection immediately.
If the soft limit is reached, the client will lose its connection after soft seconds seconds.
Parameters Soft Limit < hard limit.
client-output-buffer-limit Normal 0 0 0
client-output-buffer-limit slave 256mb 64MB
Client-output-buffer-limit pubsub 32MB 8MB 60

Redis uses an internal program to handle background tasks, such as closing a timed-out client connection, clearing expired keys, and so on. It does not handle all tasks at the same time, and Redis checks and executes tasks by specifying the Hz parameters.
The Hz default is set to 10, increasing its value will take up more CPU, of course, the corresponding Redis will be faster processing of many key at the same time, and more accurate to handle timeouts.
The range of Hz values is 1~500, which is usually not recommended for more than 100, and can be raised to 100 only if the request delay is very low.
Hz 10

When a subprocess is to overwrite the aof file, if the following options are enabled, the file will be synchronized each time the 32MB data is generated, so that a larger delay can be avoided when committing the delta file to disk.
Aof-rewrite-incremental-fsync Yes

Detailed Redis configuration parameters

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.