Detailed Redis configuration file
unit
When redis starts, it will read the configuration file redis.conf
1k => 1000 bytes
1kb => 1024 bytes
1m => 1000000 bytes
1mb => 1024*1024 bytes
1g => 1000000000 bytes
1gb => 1024*1024*1024 bytes
Units in redis are case-insensitive, for example, 1GB 1Gb 1gB
means the same thing
INCLUDES contains
The redis.conf
used in the environment can contain other redis.conf
, they will be integrated into a configuration file to provide use
NETWORK network
bind 0.0.0.0
protected-mode yes
port 6379
bind
Binding address, if binding 127.0.0.1 is local access, if you need remote access, you can bind a real ip address
protected-mode
Whether the protected mode is enabled, the default is enabled
port
Port settings, the default port is 6379, we can also modify it to other available ports, such as when clustering, it will be modified to the port
GENERAL Universal
Common configuration, commonly used are
daemonize yes
pidfile /var/run/redis_6379.pid
loglevel notice
logfile ""
databases 16
always-show-logo no
set-proc-title yes
daemonize
Whether to run as a daemon process, the default is no, we can change it to yes if we need
pidfile
To run redis in the background, we need to make a pid file
loglevel
log level
291 # Specify the server verbosity level.
292 # This can be one of:
293 # debug (a lot of information, useful for development/testing)
294 # verbose (many rarely useful info, but not a mess like the debug level)
295 # notice (moderately verbose, what you want in production probably)
296 # warning (only very important / critical messages are logged)
It's the same as what we used in our project:
- debug
Debug information for development and testing
- verbose
Rarely useful information
- notice
Prompt information, what you expect to see in a production environment
- warning
Alarm information, important information will be printed to the log
logfile
Specify the redis log file path
databases
redis database, default is 16
always-show-logo
Whether to always display the reids logo, which is the logo below
_._
_.-``__ ''-._
_.-`` `. `_. ''-._ Redis 6.2.5 (00000000/0) 64 bit
.-`` .-```. ```\/ _.,_ ''-._
( ' , .-` | `, ) Running in standalone mode
|`-._`-...-` __...-.``-._|'` _.-'| Port: 6379
| `-._ `._ / _.-' | PID: 29303
`-._ `-._ `-./ _.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' | https://redis.io
`-._ `-._`-.__.-'_.-' _.-'
|`-._`-._ `-.__.-' _.-'_.-'|
| `-._`-._ _.-'_.-' |
`-._ `-._`-.__.-'_.-' _.-'
`-._ `-.__.-' _.-'
`-._ _.-'
`-.__.-'
SNAPSHOTTING snapshots
Snapshot, here is the persistence of redis, how many times the operation is performed in the specified time, it will be persisted to the file
There are two types of persistence for redis
- RDB
- AOF
Redis is an in-memory database. Program downtime or power failure will cause data loss, so redis has such a persistence strategy
# save 3600 1
# save 300 100
# save 60 10000
- save 3600 1
If there is one operation in redis within 3600 s, data persistence will be done
- save 300 100
If 100 operations occur in redis within 300s, data persistence will be done
- save 60 10000
If redis has 10,000 operations within 60s, data persistence will be done
Later, when we write about persistence in detail, let's talk about and actually test persistence.
stop-writes-on-bgsave-error yes
rdbcompression yes
rdbchecksum yes
dir ./
stop-writes-on-bgsave-error
Whether the redis persistence error continues to execute the redis program, the default is open, the persistence error cannot affect the execution of the redis program, it needs to proceed normally
rdbcompression
Whether the persistent file needs to be compressed, it is enabled by default, this function will consume more performance
rdbchecksum
When saving rdb persistent files, error checking will be performed
dir
rdb file save directory
REPLICATION master-slave replication
The configuration of master-slave replication is at this location
Detailed follow-up writing is written in detail when active replication
SECURITY
Security-related configuration files of redis, let's take a look at the password
# The requirepass is not compatable with aclfile option and the ACL LOAD
# command, these will cause requirepass to be ignored.
#
# requirepass foobared
Redis does not set a password by default, but we must set a password for remote access security
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) ""
127.0.0.1:6379> config set requirepass 888888
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "888888"
退出 redis 客户端,再次连接 redis-server
root@iZuf66y3tuzn4wp3h02t7pZ:~# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.
After setting a password for redis, exit the redis client, connect to redis-server again, and find that redis has insufficient permission to report an error. At this time, we need a password to use redis-client to connect to redis-server.
127.0.0.1:6379> auth 888888
OK
127.0.0.1:6379> ping
PONG
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "888888"
CLIENTS client
Limit the number of client connections
maxclients 10000
maxclients
Redis limits the number of client connections to 10,000 by default. We can also modify this number to what we expect
MEMORY MANAGEMENT memory management
maxmemory <bytes>
maxmemory-policy noeviction
maxmemory
The maximum memory capacity configured by redis, in bytes
maxmemory-policy
What is the processing strategy after the redis memory reaches the upper limit? There are the following options:
- noeviction
never expires, returns an error
- volatile-ttl
delete expiring
- allkeys-random
delete key randomly
- volatile-random
Randomly delete keys that are about to expire
- allkeys-lru
Delete the key of the lru algorithm
- volatile-lru
Only perform LRU on keys with an expiration time set
LRU (Least recently used, least recently used)
APPEND ONLY MODE Append mode (aof configuration)
APPEND ONLY MODE is used for persistence of AOF
appendonly no
appendfilename "appendonly.aof"
# appendfsync always
appendfsync everysec
# appendfsync no
appendonly
It is turned off by default, and redis uses the rdb persistence mode by default, which is basically sufficient.
appendfilename
aof the name of the persistent file
appendfsync
Persistent synchronization strategy
- always synchronizing every modification, consuming performance
- everysec performs synchronization every second, and the data of the last 1 s will be lost under abnormal conditions
- no Do not actively synchronize data, the system will automatically synchronize, this method is the fastest, but the probability of losing data is high
The common and frequently changed locations of redis configuration files are shared with you. It needs a lot of application in actual study and work, and practice makes perfect.
References:
Welcome to like, follow, favorite
Friends, your support and encouragement are the motivation for me to persist in sharing and improve quality
Okay, here it is this time
Technology is open, and our mentality should be open. Embrace change, live in the sun, and move forward.
I am little devil boy Nezha , welcome to like, follow and favorite, see you next time~
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。