In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the detailed analysis of the Redis configuration file redis.conf, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
Article catalogue
I. Thirty commonly used configurations
II. Memory elimination strategy of Redis
2.1 set the timeout for data
2.2 dynamic deletion of unused data using LRU algorithm
3. Custom configuration Redis
When developing under Linux, you should keep in mind that the software is installed under / opt by default. Never change the configuration file of the factory default settings directly. The correct way is to back up a copy before operation.
The configuration file of Redis is located in the Redis installation directory, and the file name is reids.conf. Here are 30 commonly used configurations. The article is accompanied by an English translation of the redis.conf file.
I. Thirty commonly used configurations
The first ten configurations
Daemonize no
Redis does not run as a daemon by default, but can be modified to enable daemons for yes.
Pidfile / var/run/redis/pid
When Redis runs as a daemon, Redis writes pid to the / var/run/redis.pid file by default, and the path can be specified through pidfile.
Port 6379
Specifies the listening port of the Redis.
Bind 127.0.0.1
The host address bound by Redis.
Timeout 300
Sets how long the connection will be closed when the client is idle. A value of 0 means to turn off the feature.
Loglevel verbose
Specifies the logging level. Redis supports four levels: debug, verbose (default), notice, and warning.
Logfile stdout
Logging method. Default is standard output. If Redis is configured as a daemon and the logging method here is standard output, the log will be sent to / dev/null.
Databases 16
Set the number of databases, the default is 0, and you can use the select command to specify the database id on the connection.
Save
Specify how long and how many update operations, the data will be synchronized to the data file, can be matched by multiple conditions. Three conditions are provided in the Redis configuration file:
Save 900 1; save 300 10; save 60 10000
Rdbcompression yes
Specify whether to compress the data when stored in the local database. The default is that yes,Redis uses LZF (compression algorithm) compression. If you want to save cpu time, you can turn this option off, but it will cause the database file to become huge.
The middle ten configurations
Dbfilename dump.rdb
Specifies the local database file name, which defaults to dump.rdb
Dir. /
Specify the local database storage directory
Slaveof
When the local machine is a slav service, the IP address and port of the master service are set. When the Redis starts, it will automatically synchronize data from the master.
Masterauth
When the master service sets password protection, the slav service connects to the password of the master.
Requirepass foobared
Set the connection password for the Redis. If the connection password is configured, the client needs to provide the password through the AUTH command when connecting to the Redis. The default is off.
Maxclients 128
Set the maximum number of client connections at a 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 can be opened by Redis processes. If you set maxclients 0, there is no limit, and 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
Specify the maximum memory limit of Redis. Redis will load data into memory at startup. After reaching the maximum memory, Redis will first try to clear the expired or expiring Key. When this method is processed, the maximum memory setting is still reached, and the write operation cannot be performed, but the read operation can still be performed. Redis's new vm mechanism stores Key in memory and value in the swap area.
Appendonly no
Specify whether to log after an update operation. By default, Redis writes data to disk. If it is not enabled, it may cause data loss for a period of time in the event of a power outage.
Appendfilename appendonly.aof
Specifies the update log file name, default to appendonly.aof.
Appendsync everysec
Specify the update log condition. There are three options:
① no: indicates that the operating system synchronizes the data cache to disk (fast),
② always: means to manually call fsync () after each operating system update to write data to disk (slow, secure),
③ everysec: represents a wonderful synchronization (efficiency compromise, default)
The last ten
Vm-enable no
Specify whether to enable the virtual memory mechanism. The default value is that the no,VM mechanism stores the data in pages, and Redis swap the less visited pages, that is, cold data to the disk, and the pages with more visits are automatically swapped out to memory by the disk.
Vm-swap-file / tmp/redis.swap
The virtual memory file path, which defaults to / tmp/redis.swap, cannot be shared by multiple Redis instances.
Vm-max-memory 0
All data larger than vm-max-memory is stored in virtual memory, no matter how small the vm-max-memory setting is, all index data is stored in memory (Redis's index data is keys), that is, when vm-max-memory is set to 0, all value actually exists on disk. Default value is 0
Vm-page-size 32
Redis swap file is divided into many page, an object can be saved on multiple page, but a page cannot be shared by multiple objects, vm-page-size is set according to the size of the stored data, if many small objects are stored, the page size is best set to 32 or 64bytes; if you store a large object, you can use a larger page, if you are not sure, use the default value.
Vm-pages 134217728
Set the number of page in the swap file, because the page table (a type of bitmap that indicates that the page is free or used) is placed in memory, and every 8 pages on disk consumes 1byte memory.
Vm-max-threads 4
Set the number of threads to access the swap file, do not exceed the number of cores of the machine, if set to 0, then all operations on the swap file are serial, which may cause a long delay. The default value is 4.
Glueoutputbuf yes
Sets whether to merge smaller packets into one packet when replying to the client, which is enabled by default.
Hash-max-zipmap-entries 64/hash-max-zipmap-value 512
Specifies that a special hashing algorithm is used when the number of elements exceeds a certain number or the largest element exceeds a critical value.
Activerehashing yes
Specifies whether to activate the reset hash, which is on by default.
Include / path/to/local.conf
Specifies to include additional profiles that can use the same profile between multiple Redis instances on the same host, while each instance has its own specific profile.
II. Memory elimination strategy of Redis
As an excellent cache middleware, Redis often stores a large amount of data. Even if cluster deployment is used to dynamically expand capacity, memory should be cleaned immediately to maintain system performance.
2.1 set the timeout for data
Expire key time (in seconds) this is the most common way
The unique way of setex (String Key, int seconds, String value) strings
Except for the string's own unique method to set the expiration time, all other methods rely on the expire method to set the time.
If the time is not set, the cache will never expire.
If you set the expiration time and then want the cache to never expire, use persist key
2.2 dynamic deletion of unused data using LRU algorithm
A page replacement algorithm for memory management. Data blocks (memory blocks) that are in memory but are not used are called LRU. The operating system removes memory and makes room to load additional data based on which data belongs to LRU.
Delete the least frequently used data in the timeout data set by volatile-lru
Allkeys-lru queries all of the key's least frequently used data for deletion, which is the most widely used strategy.
Volatile-random randomly deletes data with a timeout set
Allkeys-random queries all key and then randomly deletes them
Volatile-ttl queries all the data with timeout set, and then sorts them, and deletes the data of state-owned enterprises immediately.
If noeviction is set to this property, it will not be deleted and will be returned in case of memory overflow.
Volatile-lfu removes the least frequently used keys from all keys configured with a timeout
Allkeys-lfu removes the least frequently used key from all keys
3. Custom configuration Redis
Go to the corresponding installation directory / usr/local/redis and modify the redis.conf configuration file.
As a beginner, Redis generally needs to modify the following three items:
Change daemonize no to daemonize yes, that is, start with a daemon.
Comment out bind 127.0.01, that is, allow machines other than native machines to access the Redis service.
Use requirepass to set a password, that is, to keep the service secure / in rare cases, remote access is not possible without setting a password.
Redis adopts the mode of single-process and multi-threading. When the option daemonize in redis.conf is set to yes, daemon mode is enabled. In this mode, redis runs in the background and writes the process pid number to the file set by the redis.conf option pidfile, and redis runs all the time unless you manually kill the process. However, when the daemonize option is set to no, the current interface will enter the redis command line interface, exit forced exit or close the connection tool (putty,xshell, etc.) will cause the redis process to exit. Most of the applications developed by the server are running in the background.
Thank you for reading this article carefully. I hope the article "detailed Analysis of Redis profile redis.conf" shared by the editor will be helpful to you. At the same time, I also hope you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.