2021-06 detailed process of installing Redis under CentOS-7

View the latest installation package address

The version of online search direct copy may change due to the long time. It's better to find the latest or stable package and use the official website address
[download on redis official website] https://redis.io/download Obtain the latest package address by reviewing the element

Use ssh to log in to the website. The following is the schematic diagram. The login command format is as follows. You can log in by yourself: ssh root@127.0.0.1

Let's go to the formal installation step. There are also instructions in the package downloaded in this step. Friends who have time can see it:

Install the necessary packages for redis

yum install gcc

Download redis installation package

//Download redis installation package
wget https://download.redis.io/releases/redis-6.2.4.tar.gz
//decompression
tar zxvf redis-6.2.4.tar.gz
//Jump to redis directory
cd redis-6.2.4
//Compile and install
make MALLOC=libc

After the above steps, redis will be compiled. Of course, after the installation is completed, you need to continue to look down. In order to facilitate subsequent settings for self startup, we install the package in / usr/local/redis-6.2.4, or directly execute make install to install it in the current directory

//It is installed in / usr/local/redis-6.2.4 directory
make install PREFIX=/usr/local/redis-6.2.4

redis startup mode

Direct start
   stay redis-6.2.4 Root directory of, execute
 . /src/redis-cli
Background start
   The first startup method is to open the window after startup, which is very unsuitable for the server. So you need to use background startup
Modify redis Conf file

Find redis.com in the package root directory Conf file
#Modify the daemon to yes, that is, it runs in the background program mode by default (remember to use the & sign to force the background to run manually earlier).

vi redis.conf
//Change the following parameter no to yes, then save and exit
daemonize no  Change to daemonize yes

Then use redis Conf start

cd redis-6.2.4/
./redis-server /usr/local/redis-6.2.4/redis.conf

This method is not used here. If you need to shut down the redis process, you must kill it. Therefore, we need to set the startup. Even if the server goes down and restarts, we don't have to worry about manually restarting the service again

Write the redis startup script to set the auto startup
   3.1 Configure the environment and copy a copy of the configuration file to the specified directory under the name of port (required) root (user)
mkdir /etc/redis
cp redis.conf /etc/redis/6379.conf
Copy the Redis startup file and modify it.

#Copy the startup script to / etc / init d/

cp /root/redis-6.2.4/utils/redis_init_script /etc/init.d/redisd
#Jump to target directory
cp /etc/init.d/
#Check whether the copy is successful
ls

Copy the startup script to / etc / init d directory, this example names the startup script redisd (usually ends with d, indicating that it is a background self startup service).
Note: the linux run level needs to be modified

#Open the script file and modify it
vi /etc/init.d/redisd

The main modifications are as follows:
1. On redis_ init_ Add the following lines to the beginning of the script file:

#!/bin/sh
# chkconfig:   2345 90 10
# description:  Start and Stop redis,Redis is a persistent key-value database
#

2: Modify startup and customer shutdown commands
The path is the PREFIX path when the command is executed. make install PREFIX=/usr/local/redis-6.2.4
EXEC: configure redis startup program path and file name
CLIEXEC: configure redis client program path and file name

EXEC=/usr/local/redis-6.2.4/bin/redis-server
CLIEXEC=/usr/local/redis-6.2.4/bin/redis-cli

3. Modify the configuration file path and pid path
Pidfile: configure the ipd file, which needs to be connected with redis_ The pidfile configuration in 6379.conf file is consistent
CONF: configure redis profile_ 6379.CONF path, configure the file copied in step 1
The corresponding configuration file CP redis conf /etc/redis/6379. conf

//The settings in the source system do not need to be changed if it is not necessary. Here, I can start normally without modification according to the original appearance of the system
PIDFILE=/var/run/redis_${REDISPORT}.pid
CONF="/etc/redis/${REDISPORT}.conf"
//If it needs to be modified, it shall be modified as follows
PIDFILE=/var/run/6379.pid
CONF="/etc/redis/6379.conf"

Set to power on and self start
#Add to startup list
chkconfig --add redis
#Set to auto start, or just execute this command
chkconfig redis on
#Check whether the startup configuration is successful
chkconfig --list
Setting environment variables
//Open the profile file in the / etc directory and add it at the bottom. The path of redis is the environment variable
vi /etc/profile

After adding, execute the following command to refresh the variable file to make it effective

source /etc/profile
Start / stop redis service
//Start redis
service redisd start
//Turn off redis
service redisd stop

You can restart the server to test whether it starts normally

Added by vonnero on Mon, 24 Jan 2022 09:21:29 +0200