centos 7.9 install redis5.05 complete tutorial, download, install, configure, boot and start remote access

foreword

To install Redis, you need to know which version you need and install it in a targeted manner.

For example, if you need the feature of redis GEO, a geographical collection, then the redis version cannot be lower than version 3.2, because this feature is only available in version 3.2.

In addition, it should be noted that Redis agrees that the minor version number (that is, the number after the first decimal point) is a stable version (such as version 2.8, 3.0), and the odd version is an unstable version (such as version 2.7, 2.9). , a stable version is generally required in a production environment.

The official description of installing Redis is as follows: Download, extract and compile Redis with:

That is: download, decompress, and compile.

Therefore, the document is only for experimentation, so install the latest official version of redis

 

We first create a new data folder under the root, and create a new redis5.0.5 under the data folder, we need to install it here

PS: Many tutorials on the Internet are directly downloaded and installed. In the current directory, it is often easy for novices to confuse. It is not clear where redis is installed, and it will cause the subsequent commands to fail to execute, because the path is inconsistent with the tutorial;

 

  1. Download the installation package

Let's go to this directory by cd /data/redis

[root@CentOS7 redis]# pwd           

#View the current directory, the source code package is downloaded in this directory /data/redis

[root@CentOS7 redis]# wget http://download.redis.io/releases/redis-5.0.5.tar.gz

2. Unzip the source package

[root@CentOS7 redis]# tar -zxvf redis-5.0.5.tar.gz   

#Decompression will generate a redis-5.0.5 directory

3. Install GCC dependencies

[root@CentOS7 redis]# yum install gcc gcc-c++ #Encounter a choice, just enter y directly

 

4. Compile & install

[root@CentOS7 redis]# cd redis-5.0.5/ #Enter the redis directory

[root@CentOS7 redis-5.0.5]# make #Wait for the compilation to complete, and proceed to the next step without reporting an error

[root@CentOS7 redis-5.0.5]# make install #Installation, when executing make install, the commands below src will be copied to /usr/local/bin/

5. run redis

[root@CentOS7 ~]# /data/redis/redis-5.0.5/src/redis-server #Run in the redis directory

[root@CentOS7 ~]# redis-server                       

 #Run in any directory, because the redis-server command is in the /usr/local/bin directory, and this directory is configured in PATH, so you can execute redis-cli or redis in the same way as ls, mkdir and other commands -server and other commands.

 

Operation after installation

Start redis as a background process

The first step: modify the redis.conf file, the redis.conf file is in the redis directory

  • The configuration allows all ip to access redis, add "#" before bind 127.0.0.1 to comment it out
  • The default is protected mode, change protected-mode yes to protected-mode no
  • The default is no daemon mode, change daemonize no to daemonize yes
  • Remove the "#" before requirepass foobared, and change the password to the password you want to set (the practice setting is 123456, that is, change foobared to 123456)

Step 2: Specify the redis.conf file to start

[root@CentOS7 redis-5.0.5]# redis-server /data/redis/redis-5.0.5/redis.conf

Step 3: Close the redis process

[root@CentOS7 redis-5.0.5]# ps -ef |grep redis #ps -aux | grep redis view redis process root 17311 1 0 15:23 ? 00:00:00 redis-server 127.0.0.1:6379

[root@CentOS7 redis-5.0.5]# kill -9 17311 #kill redis process

 

Step 4: Check whether all IP access is enabled:

[root@CentOS7 redis-5.0.5]# netstat -lunpt

If * or 0.0.0.0 is displayed in front of the port number, it means that the client can access it. If it is 127.0.0.1, it means that it can only be accessed by the local machine, and it is not commented out in the configuration file.

 

Set redis to start automatically at boot

1. Create a new redis directory under the /etc directory

[root@CentOS7 redis-5.0.5]# mkdir -pv /etc/redis

2. Copy the configuration file into /etc/redis/ and name it 6379.conf

[root@CentOS7 redis-5.0.5]# cp /data/redis/redis-5.0.5/redis.conf  /etc/redis/6379.conf

 

 

3. Create a service

When using service to manage services, a script file is created in the /etc/init.d/ directory to manage the start and stop of services.

In systemctl, it is similar, the file directory is different, create a script file redis.service in the /etc/systemd/system directory, the contents are as follows:

[Unit]

Description=Redis

After=network.target

 

[Service]

Type=forking

ExecStart=/usr/local/bin/redis-server /etc/redis/6379.conf

ExecStop=/usr/locl/bin/redis-cli -h 127.0.0.1 -p 6379 shutdown

 

RestartSec=10

Restart=always

 

[Install]

WantedBy=multi-user.target

 

4. Refresh the configuration and let systemctl recognize it

[root@CentOS7 redis]# systemctl daemon-reload

5. Start and close redis

[root@CentOS7 system]# systemctl start redis #Start redis service

[root@CentOS7 system]# systemctl stop redis #Close redis service

6. Set redis to boot

[root@CentOS7 system]# systemctl enable redis

Summarize

In the process of creating the service, due to excessive reference to the document, the Type type is not specified as forking. As a result, the startup of redis was unsuccessful (no error was reported), and the error was reported through systemctl status redis, combined with online search information to solve the problem. For the time being, the systemctl service has not been studied, and the type of configuration has not been understood. Find out next. Also study the persistence of redis.

 

In addition, pay attention to add redis port 6379 to the firewall, and restart the firewall to make it effective;

 

Log in to redis:

1.redis-cli

2.auth your password

or use directly:

redis-cli -h 127.0.0.1 -p 6379 -a your password to log in

 

 

Guess you like

Origin blog.csdn.net/qianjiu/article/details/116296538