2024-07-12
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
Redis (Remote Dictionary Server) is an open source NoSQL database written in C language. It runs on memory and supports persistence, using key-value storage. Redis is widely used in caching, real-time analysis systems, rankings and other scenarios due to its high performance, rich data type support and atomic operations.
The Redis server program is a single-process model, which means that multiple Redis processes can be started on a server at the same time, and the actual processing speed of Redis depends entirely on the execution efficiency of the main process. If only one Redis process is run on the server, when multiple clients access it at the same time, the processing capacity of the server will decrease to a certain extent; if multiple Redis processes are started on the same server, Redis will put a lot of pressure on the server's CPU while improving the concurrent processing capacity. That is: in the actual production environment, it is necessary to decide how many Redis processes to start based on actual needs. If the requirements for high concurrency are higher, you may consider starting multiple processes on the same server. If CPU resources are relatively tight, a single process is sufficient.
There are several ways to install Redis on Linux:
For most Linux distributions, Redis can be installed directly using the package manager. For example, on Ubuntu or Debian, you can useapt-get
Order:
bash复制代码
sudo apt-get update | |
sudo apt-get install redis-server |
On CentOS or Red Hat, useyum
Order:
bash复制代码
sudo yum update | |
sudo yum install redis |
Another way to install is to download the source code from the official website of Redis, and then compile and install it. The steps are as follows:
Install the compilation tools:
First, you need to install gcc and other compilation tools. On CentOS or Red Hat, you can useyum
Install:
bash复制代码
sudo yum install gcc-c++ make |
Download Redis source code:
Download the latest compressed package (such as redis-6.xxtar.gz) from the Redis official website.
Compile and install:
Unzip the downloaded compressed package, enter the unzipped directory, and execute the compilation and installation commands:
bash复制代码
tar zxvf redis-6.x.x.tar.gz | |
cd redis-6.x.x | |
make && make PREFIX=/usr/local/redis install |
Configure Redis Service:
You can use the Redisinstall_server.sh
Script to set up the Redis service, or configure it manually.
Redis configuration files are usuallyredis.conf
, you can configure various parameters of Redis by modifying this file.
bind
option or comment out the line.Redis performance optimization mainly includes memory allocation control, swappiness setting, network connection optimization and other aspects.
Memory allocation control:
Linux operating systemvm.overcommit_memory
The parameter controls the memory allocation strategy. Redis recommends setting it to 1 so that fork operations can be performed successfully even in low memory situations.
bash复制代码
echo "vm.overcommit_memory=1" >> /etc/sysctl.conf | |
sysctl vm.overcommit_memory=1 |
swappiness setting:
The swappiness parameter determines the operating system's tendency to use swap. For applications that require high concurrency and high throughput, it is recommended to set swappiness to a lower value to reduce the possibility of disk IO becoming a system bottleneck.
bash复制代码
echo "vm.swappiness=10" >> /etc/sysctl.conf | |
sysctl vm.swappiness=10 |
Network connection optimization:
Ensure stable network connection and reduce network delay and packet loss. At the same time, properly configure Redis TCP parameters, such astcp-keepalive
etc. to improve the stability and reliability of network connections.
Check Redis status:
can useredis-cli
Command to connect to the Redis server and executeINFO
command to view the current status of Redis, including memory usage, persistence status, number of connections, etc.
Viewing log files:
Redis log files are usually located in/var/log/redis/redis-server.log
, you can get error information and running status by viewing the log file.