[redis series] redis learning 7. Details of redis configuration files you don't know

Posted by erikwebb on Sun, 06 Mar 2022 11:52:32 +0100

Detailed explanation of Redis configuration file

Company

When redis is started, 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 not case sensitive. For example, 1GB, 1GB and 1GB all mean the same thing

INCLUDES includes

Redis used in the environment Conf can contain other redis Conf, they will be integrated into a configuration file for use

NETWORK

bind 0.0.0.0 

protected-mode yes

port 6379

bind

Binding address: if binding 127.0.0.1 is local access, if remote access is required, a real ip address can be bound

protected-mode

Whether the protection mode is enabled. It is enabled by default

port

Port setting: the default port is 6379. We can also modify it to other available ports. For example, it will be modified to port when clustering

GENERAL

Common configurations include

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. The default is no. We can change it to yes if necessary

pidfile

To run redis in the background mode, we need to formulate 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)

Consistent with those used in our project:

  • debug

Debug information for development and testing

  • verbose

Rare and useful information

  • notice

Prompt information, expected to be seen in the production environment

  • warning

Alarm information and important information will be printed in the log

logfile

Specify redis log file path

databases

redis database, 16 by default

always-show-logo

Is the reids logo always displayed? This is the logo below

                _._
           _.-``__ ''-._
      _.-``    `.  `_.  ''-._           Redis 6.2.5 (00000000/0) 64 bit
  .-`` .-```.  ```\/    _.,_ ''-._
 (    '      ,       .-`  | `,    )     Running in standalone mode
 |`-._`-...-` __...-.``-._|'` _.-'|     Port: 6379
 |    `-._   `._    /     _.-'    |     PID: 29303
  `-._    `-._  `-./  _.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |           https://redis.io
  `-._    `-._`-.__.-'_.-'    _.-'
 |`-._`-._    `-.__.-'    _.-'_.-'|
 |    `-._`-._        _.-'_.-'    |
  `-._    `-._`-.__.-'_.-'    _.-'
      `-._    `-.__.-'    _.-'
          `-._        _.-'
              `-.__.-'

SNAPSHOTTING snapshot

The snapshot, which is the persistence of redis, will be persisted to the file according to the number of operations performed within the specified time

There are two ways to persist redis

  • RDB
  • AOF

Redis is an in memory database. Program downtime or power failure will lead to data loss. Therefore, 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 3600s, data persistence will be performed

  • save 300 100

If 100 redis operations occur within 300s, data persistence will be performed

  • save 60 10000

If there are 10000 operations in redis within 60s, data persistence will be performed

When we write about persistence in detail later, we will talk about persistence in detail and actually test it

stop-writes-on-bgsave-error yes

rdbcompression yes

rdbchecksum yes

dir ./

stop-writes-on-bgsave-error

Redis persistence error. Whether to continue to execute the redis program is on by default. The persistence error cannot affect the execution of the redis program. It needs to be carried out normally

rdbcompression

Whether persistent files need to be compressed is enabled by default. This function will consume performance

rdbchecksum

Error checking and verification will be performed when saving rdb persistent files

dir

Directory where rdb files are saved

REPLICATION master-slave REPLICATION

The configuration of master-slave replication is in this location

Detailed subsequent write to active replication

SECURITY security

redis security related configuration files. 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"

sign out redis Client, connect again redis-server
root@iZuf66y3tuzn4wp3h02t7pZ:~# redis-cli
127.0.0.1:6379> ping
(error) NOAUTH Authentication required.

After setting the password for redis, exit the redis client and connect to the redis server again. It is found that the error reporting permission of redis is insufficient. At this time, we need a password to connect to the redis server using the redis client

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 client connections

 maxclients 10000

maxclients

redis limits the number of client connections to 10000 by default. We can also modify this number to what we expect

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 redis memory reaches the upper limit? There are the following options:

  • noeviction

Never expire, return error

  • volatile-ttl

Delete expiring

  • allkeys-random

Randomly delete key

  • volatile-random

Randomly delete expired key s

  • allkeys-lru

Delete the key of lru algorithm

  • volatile-lru

LRU is only performed for key s with expiration time set

LRU (Least recently used)

APPEND ONLY 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 off by default. redis uses rdb persistence mode by default, which is basically sufficient

appendfilename

The name of the aof persistence file

appendfsync

Persistent synchronization policy

  • always synchronizes every modification, which consumes performance
  • everysec performs synchronization once every second. Under abnormal circumstances, the last 1 s data will be lost
  • If no does not actively synchronize data, the system will automatically synchronize. This method is the fastest, but it has a high probability of losing data

The commonly used and frequently changed positions of redis configuration files have been shared with you. You need to apply them more in practical learning and work. Practice makes perfect

reference material:

redis_doc

Welcome to like, follow and collect

My friends, your support and encouragement are the driving force for me to insist on sharing and improve quality

Well, that's all for this time

Technology is open, and our mentality should be open. Embrace change, grow into the sun and strive to move forward.

I'm Nezha, the Little Devil boy. Welcome to praise and pay attention to the collection. See you next time~

Topics: Redis Back-end