How to use Redis safely?

Redis is an in-memory database that is so fast to use that even Redis developers don’t want to add passwords to it. Due to security pressure, subsequent versions added passwords, but they are no longer willing to encrypt passwords, saying that it affects Redis. speed.
Then this article can teach you how to use Redis safely.
In the world of martial arts, only speed is the best. Today I will talk about how to use Redis safely.

Environment:
Operating system: CentOS7.9
Panel version: 7.9.1 (official version)
Redis version: 6.2.6
System firewall version: 3.1
First go to the software store Install Redis and open it after installation. The expected interface
is as follows:


1. Let’s first explain how to configure Redis safely from a security perspective.
1. Configure password,
as shown in the figure, open performance adjustment


requirepass parameter, I set it to dapao666!

 

 

 

After modification, remember to restart Redis to load the latest configuration.

 

You must enter your password when logging in to Redis

 

2. Open the system firewall and specify the IP to access your Redis6379 port to prevent malicious access.

 

3. If possible, specify IP in your security group to access yours. For details, please refer to Alibaba Cloud's release tutorial. Alibaba Cloud
security group release tutorial.
2. Observe the Redis load status from an operation and maintenance perspective.
The important parameters are:

used_memory_rss Redis is currently occupied. The total amount of system memory
used_memory The peak hit of Redis historical allocated memory
Search database key hit rate
If the total amount of system memory currently occupied is too large, you can reduce it through the maxmemory parameter in performance adjustment. Try not to exceed your server's value. 40% of the physical memory
is a server with 8G memory. Now allocate 1G memory, which is enough (please allocate according to your actual situation)
hit is also an important parameter. This parameter represents the cache hit rate of your data acquisition. If the hit rate If it is too low, then you need to contact the development to check the cache settings.
3. Understand Redis from the perspective of data security. Redis

provides two persistence methods, one is the default RDB method, and the other is the AOF method.
RDB is The data in the memory is written to the storage regularly according to the rules.
AOF means that each command executed will be recorded and written in the AOF file, which is equivalent to a collection of all commands. RDB
advantages: For scenarios with large amounts of data, the database The recovery integrity is not particularly sensitive. RDB's timed writing method to disk is more efficient, and the I/O consumption of disk is not that high. Usage scenarios: RDB is suitable for use that is not so sensitive to data requirements, such
as cached website images. , cached url requests, cached data combined with the database, etc.
Advantages of AOF: Record each operation in the form of a log, and save the executed commands in the AOF file. When Redis restarts, the commands in the log file will be reloaded into the memory, which is equivalent to replaying the executed commands. , in order to achieve data consistency, the most commands that are too late to be written will be lost (AOF default is to append data to the aof file in 1 second) Usage
scenarios: Businesses that are sensitive to data, such as finance, scientific data and other industries

 

 

Guess you like

Origin blog.csdn.net/u011630259/article/details/124929980