To install Redis, you need to know which version you need and install it in a targeted manner. For example, if you need the characteristics of the geographical collection of redis GEO, then the redis version cannot be lower than version 3.2. Due to this This feature is only available in version 3.2.
It should also be noted that Redis agrees that versions with an even minor version number (that is, the number after the first decimal point) are stable versions (such as version 2.8, version 3.0), and odd-numbered versions are unstable versions (such as Version 2.7, version 2.9), the stable version is generally required in a production environment. (Recommended: redis video tutorial)
Download the installation package
wget http://download.redis.io/releases/redis-4.0.2.tar.gz
Unzip the installation package and install
tar xzf redis-4.0.2.tar.gz cd redis-4.0.2 make make install
Redis has no other external dependencies, and the installation process is very simple. After compilation, several executable programs can be found in the src folder of the Redis source code directory. After installation, the redis executable file just installed can be found in the /usr/local/bin directory.
As shown below:
Start and stop Redis
Start Redis
Start directly
Run redis-server directly to start Redis
[root@localhost bin]# redis-server
Start Redis through the initialization script
There is an initialization script file named redis_init_script in the utils folder of the Redis source code directory. You need to configure the running mode of Redis and the storage location of persistent files and log files. The steps are as follows:
1. Configure the initialization script
First copy the initialization script to the /etc/init.d directory. The file name is redis_port number, where the port number indicates that you want Redis to The listening port number, through which the client connects to Redis. Then modify the value of the REDISPORT variable in line 6 of the script to the same port number.
2. Create the following required folders.
3. Modify the configuration file
First copy the configuration file template (redis-4.0.2/redis.conf) to the /etc/redis directory , named after the port number (such as "6379.conf"), and then edit some of the parameters according to the following table.
Now you can also use the following commands to start and shut down Redis
/etc/init.d/redis_6379 start /etc/init.d/redis_6379 stop
【Most important】 Let Redis start automatically with the system. This also requires simple modifications to the Redis initialization script. Execute the command:
vim /etc/init.d/redis_6379
In the fourth line of the opened redis initialization script file, append the following two sentences
# chkconfig: 2345 90 10 # description: Redis is a persistent key-value database
The effect after appending is as follows:
The red box in the above picture is the two additional lines of comments. Save after adding, you can use the following command to add Redis Added to the system startup items
//设置开机执行redis脚本 chkconfig redis_6379 on
After the above operation, you can also directly use the following commands to start and shut down Redis in the future, as follows
service redis_6379 start service redis_6379 stop
After the above deployment operation, the system restarts, Redis will automatically start with the system, and Redis persistence is also configured in the above steps. The next time the system or Redis is started, There is the benefit of cached data not being lost.
Stop Redis
Considering that Redis may be synchronizing data in memory to the hard disk, forcibly terminating the Redis process may result in data loss. The correct way to stop Redis is to send a SHUTDOWN command to Redis. The method is:
redis-cli SHUTDOWN
When Redis receives the SHUTDOWN command, it will first disconnect all client connections, then perform persistence according to the configuration, and finally complete the exit. .
Redis can properly handle the SIGTERM signal, so using the PID of the kill Redis process can also terminate Redis normally, and the effect is the same as sending the SHUTDOWN command.
For more redis knowledge, please pay attention to the redis introductory tutorial column.
The above is the detailed content of Introduction to the installation method of Redis under CentOS. For more information, please follow other related articles on the PHP Chinese website!