Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

Detailed introduction of Redis cache database configuration file

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)06/01 Report--

Today, the editor to share with you is a detailed introduction of the Redis cache database configuration file, I believe that most people do not understand, in order to make you better understand, the editor summed up the following content, do not say much, let's look down.

1. The beginning description

There is nothing to say here, but it is important to note that when you need to use memory size later, you can specify units, usually in the form of kjournal gbforce m, and the units are case-insensitive.

2 、 INCLUDES

We know that Redis has only one configuration file, and if multiple individuals are involved in development and maintenance, multiple such configuration files are required. At this time, multiple configuration files can be configured here through include / path/to/local.conf, while the original redis.conf configuration file acts as a master gate.

Ps: if you have used struts2 development, you will usually have multiple struts2.xml files in the case of multiple developers on the project team, which will also be introduced through the configuration of class time.

It is also important to note that if you write this configuration at the beginning of the redis.conf file, then the later configuration will overwrite the configuration of the incoming file, and if you want to focus on the configuration of the incoming file, you need to write the include configuration at the end of the redis.conf file.

3 、 MODULES

The explosion function of redis3.0 is the addition of clusters, and redis4.0 has added many new functions on the basis of 3.0. the custom module configuration here is one of them. Custom modules will be introduced through the loadmodule configuration here to add some features.

4 、 NETWORK

Ps: the configuration here is rather long. I only intercepted part of it, the same as below.

① and bind: bind the redis server ENI IP. The default is 127.0.0.1, which is the local loopback address. In this way, access to the redis service can only be through a local client connection, not through a remote connection. If the bind option is empty, all connections from available network interfaces are accepted.

②, port: specify the port on which redis is running. The default is 6379. Because Redis is a single-threaded model, the port will be modified when multiple Redis processes are opened on a single machine.

③, timeout: sets the timeout for client connection (in seconds). When the client does not issue any instructions during this period, then close the connection. The default value is 0, which means that it is not turned off.

④, tcp-keepalive: in seconds, it means that SO_KEEPALIVE will be used periodically to check whether the client is still in a healthy state to avoid server blocking. The official recommended value is 300s. If set to 0, periodic detection will not be performed.

5 、 GENERAL

Details of the configuration:

①, daemonize: set to yes means that the specified Redis starts as a daemon (started in the background). The default value is no

②, pidfile: configure the PID file path. When redis runs as a daemon, it writes pid to the / var/redis/run/redis_6379.pid file by default.

③, loglevel: define the log level. The default value is notice, and the following four values are available:

Debug (record a large amount of log information, suitable for development and testing phases)

Verbose (more log information)

Notice (appropriate amount of log information, used in production environment)

Warning (only some important and critical information will be recorded)

④, logfile: configure the log file address, which is printed on the window of the command line terminal by default

⑤, databases: sets the number of databases. The default database is DB 0, and you can use the select command to select a different database on each connection. Dbid is a value between 0 and databases-1. The default value is 16, which means that the default Redis has 16 databases.

6 、 SNAPSHOTTING

The configuration here is mainly used for persistence operations.

①, save: this is used to configure the persistence condition that triggers Redis, that is, when the data in memory is saved to the hard disk. The default configuration is as follows:

Save 9001: if there is a change in the value of at least one key in 900s, save save 30010: if there is a change in the value of at least 10 key in 300s, save save 60 10000: it means that if there is a change in the value of at least 10000 key in 60 seconds, save it

Of course, if you only use Redis caching without persistence, you can comment out all save lines to disable the save feature. Deactivation can be achieved by directly using an empty string: save ""

②, stop-writes-on-bgsave-error: the default value is yes. Whether Redis stops receiving data when RDB is enabled and the last time the data is saved in the background fails. This will make the user realize that the data is not correctly persisted to disk, otherwise no one will notice that a disaster has occurred. If Redis is restarted, you can start receiving data again.

③, rdbcompression; default is yes. For snapshots stored on disk, you can set whether to compress storage. If so, redis uses the LZF algorithm for compression. If you don't want to consume CPU for compression, you can set this feature to off, but the snapshots stored on disk will be larger.

④, rdbchecksum: the default value is yes. "after storing the snapshot, we can also have redis use the CRC64 algorithm for data validation, but doing so increases performance consumption by about 10%, which can be turned off if you want to get the maximum performance improvement."

⑤, dbfilename: sets the file name of the snapshot. Default is dump.rdb.

⑥, dir: set the path where snapshot files are stored. This configuration item must be a directory, not a file name. Use the above dbfilename as the saved file name.

7 、 REPLICATION

①, slave-serve-stale-data: default is yes. When a slave loses contact with master, or when replication is in progress, slave may behave in two ways:

1) if yes, slave will still answer the client request, but the data returned may be outdated, or the data may be empty at the time of the first synchronization

2) if no, slave will return a "SYNC with master in progress" error when you execute any command other than info he salveof

②, slave-read-only: configure whether the Slave instance of Redis accepts write operations, that is, whether Slave is read-only Redis. The default is yes.

③, repl-diskless-sync: whether master-slave data replication uses no hard disk replication function. The default is no.

④, repl-diskless-sync-delay: when no hard disk backup is enabled, the server waits for a period of time before sending RDB files to the slave through the socket. This wait time is configurable. This is important because once the transmission starts, it is no longer possible to serve a newly arrived slave station. The slave station is queued for the next RDB transmission. So the server waits for a period of time to expect more slave stations to arrive. The delay time is in seconds, and the default is 5 seconds. To turn off this feature, simply set it to 0 seconds and the transfer will start immediately. The default value is 5.

⑤, repl-disable-tcp-nodelay: whether to disable TCP_NODELAY on the slave station after synchronization. If you choose yes,redis, you will use less TCP packets and bandwidth to send data to the slave station. But this will lead to a little bit of data delay in the slave station.

The delay is up to 40 milliseconds in the default configuration of the Linux kernel. If you choose no, the data latency of the slave station will be less, but the backup will require relatively more bandwidth. We optimize the potential factor by default, but it's a good idea to switch it to yes under high load or when both master and slave stations jump. The default is no.

8 、 SECURITY

①, rename-command: command rename, for some dangerous commands such as:

Flushdb (empty database)

Flushall (clear all records)

Config (the server can be configured after the client connects)

Keys (client can view all existing keys after connecting)

As a server-side redis-server, you often need to disable the above command to make the server more secure. The specific way to disable it is:

Rename-command FLUSHALL ""

You can also keep the command but not use it easily, just rename the command:

Rename-command FLUSHALL abcdefg

In this way, after restarting the server, you need to use the new command to perform the operation, otherwise the server will report an error unknown command.

9 、 CLIENTS

① and maxclients: set the maximum number of concurrent client connections. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of files that can be opened by Redis processes. Number of descriptors-32 (some will be used by redis server itself), if maxclients is set to 0. Means there are no restrictions. When the number of client connections reaches the limit, Redis closes the new connection and returns a max number of clients reached error message to the client

10 、 MEMORY MANAGEMENT

① and maxmemory: set the maximum number of concurrent client connections. By default, there is no limit. The number of client connections that Redis can open at the same time is the maximum number of files that can be opened by Redis processes. Number of descriptors-32 (some will be used by redis server itself), if maxclients is set to 0. Means there are no restrictions. When the number of client connections reaches the limit, Redis closes the new connection and returns a max number of clients reached error message to the client.

②, maxmemory-policy: clear strategy used by redis when memory usage reaches its maximum. There are several options:

1) volatile-lru uses the LRU algorithm to remove the key that sets the expiration time (LRU: recently used Least Recently Used)

2) allkeys-lru uses LRU algorithm to remove any key

3) volatile-random removes the random key that sets the expiration time

4) allkeys-random removes random ke

5) volatile-ttl removes the expired key (minor TTL)

6) noeviction noeviction does not remove any key, but returns a write error. The default option is

③, maxmemory-samples: LRU, and minimal TTL algorithms are not accurate algorithms, but relatively accurate algorithms (to save memory). You can choose the sample size for testing at will. By default, redis selects 3 samples for testing. You can set the number of samples through maxmemory-samples.

11 、 APPEND ONLY MODE

①, appendonly: the default redis uses rdb persistence, which is sufficient in many applications. However, if the redis goes down midway, it may result in a few minutes of data loss. Persistence is based on save strategy. Append Only File is another persistence method, which can provide better persistence characteristics. Redis will write the data written each time into the appendonly.aof file after receiving. Every time Redis starts, it will read the data of this file into memory and ignore the RDB file first. The default is no.

②, appendfilename: aof file name. Default is "appendonly.aof".

Configuration of ③ and appendfsync:aof persistence policies; no means that fsync is not executed, and the operating system ensures that data is synchronized to disk, which is the fastest; always means that fsync is executed every write to ensure data synchronization to disk; everysec means that fsync is executed once per second, which may result in the loss of 1s of data.

④, no-appendfsync-on-rewrite: a large number of IO will be executed when aof is rewritten or written to the rdb file. For the aof mode of everysec and always, the execution of fsync will block for too long, and the no-appendfsync-on-rewrite field is set to no by default.

For applications with high latency requirements, this field can be set to yes, otherwise it can be set to no, which is a more secure option for persistence features. Set to yes means that the new write operation is not fsync during rewrite and is temporarily stored in memory until the rewrite is completed. Default is no. Yes is recommended. The default fsync policy for Linux is 30 seconds. Data may be lost for 30 seconds. The default is no.

⑤, auto-aof-rewrite-percentage: the default value is 100. Aof automatically rewrites the configuration, when the current aof file size exceeds how many percent of the last rewritten aof file size, that is, when the aof file grows to a certain size, Redis can call bgrewriteaof to rewrite the log file. When the current AOF file size is twice the size of the AOF file obtained from the last log rewrite (set to 100), a new log rewrite process is automatically started.

⑥ 、 auto-aof-rewrite-min-size:64mb . Set the minimum aof file size that is allowed to be overridden to avoid rewriting when the agreed percentage is reached but the size is still very small.

The ⑦ and aof-load-truncated:aof files may be incomplete at the end. When redis starts, the data of the aof file is loaded into memory. Restart may occur after the operating system of the host where the redis is located goes down, especially if the ext4 file system does not add the data=ordered option. If the redis goes down or terminates abnormally, it will not cause tail incompleteness. You can choose to let redis exit or import as much data as possible.

If yes is selected, when the truncated aof file is imported, a log is automatically published to the client and then load. In the case of no, the user must manually redis-check-aof to repair the AOF file. The default is yes.

12 、 LUA SCRIPTING

①, lua-time-limit: the maximum time in ms for the execution of a lua script. The default value is 5000.

13 、 REDIS CLUSTER

① and cluster-enabled: cluster switch. The cluster mode is disabled by default.

②, cluster-config-file: the name of the cluster configuration file. Each node has a cluster-related configuration file that persists the cluster information. This file does not need to be manually configured, this configuration file is generated and updated by Redis, and each Redis cluster node requires a separate configuration file. Make sure that the name of the configuration file does not conflict with the system on which the instance is running. The default configuration is nodes-6379.conf.

③, cluster-node-timeout: a value of 15000 can be configured. Threshold of node interconnection timeout, number of cluster node timeout milliseconds

④, cluster-slave-validity-factor: a value of 10 can be configured. During a failover, all slave requests to be master, but some slave may be disconnected from master for some time, resulting in data that is too stale and such slave should not be promoted to master. This parameter is used to determine whether the disconnection between the slave node and the master is too long.

The judgment method is: compare the slave disconnection time with (node-timeout * slave-validity-factor) + repl-ping-slave-period if the node timeout time is 30 seconds and slave-validity-factor is 10, assume that the default repl-ping-slave-period is 10 seconds, that is, if it exceeds 310 seconds, slave will not attempt to fail over

⑤, cluster-migration-barrier: a value of 1 can be configured. Only when the number of slave of master is greater than this value can slave be migrated to other isolated master. For example, if this parameter is set to 2, only if a master node has two working slave nodes, one of its slave nodes will try to migrate.

⑥, cluster-require-full-coverage: by default, nodes are responsible for all slot of the cluster, and the cluster status is ok before the service can be provided. Set to no to provide services when the slot is not fully allocated. It is not recommended to open this configuration, as this will cause the master of a small partition to accept write requests all the time, resulting in data inconsistency for a long time.

After reading the above, do you have any further understanding of the Redis cache database configuration file? If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report