The environment

  • Linux: CentOS 8
  • Redis version: 6.2.5


The installation

Linux platform we use the source code of the way to install, download the source code installation package, decompress, compile.

# yum install -y wget/tar/make yum install -y wget/tar/make

Install the GCC compiler
yum install gcc
yum install gcc-c++

Check whether the installation is successful
gcc -v

Download the installation package, or you can download it offlineWget HTTP: / / https://download.redis.io/releases/redis-6.2.5.tar.gzUnzip the installation packageThe tar - ZXVF redis - 6.2.5. Tar. GzGo to the installation directory
cdRedis - 6.2.5/redis-server /redis-server /redis-server /redis-server /redis-server /redis.conf
make

# installed Redis
/usr/local/bin = /usr/local/redis = /usr/local/redis
mkdir /usr/local/redis
make install PREFIX=/usr/local/redis
Copy the code


Copy the redis.conf configuration file from redis-6.2.5 to /usr/local/redis/bin and modify it. The purpose of copying is not to modify the original file, in case of future problems to use the original file. Open the configuration file to modify the following information.

# Comment out the following line so that any IP can access the Redis service
# bind 127.0.0.1

The protected mode is disabled
protected-mode no

# Redis Port number, which can be changed
port 6380

# Copy another line and set password
# requirepass foobared
requirepass 123456

# daemon start
daemonize yes
Copy the code


Start the Redis service.

/usr/local/redis/bin/redis-server /usr/local/redis/bin/redis.conf
Copy the code


Use the ps – ef | grep redis see if redis service started successfully.

[root@chenpi bin]# ps -ef | grep redis
root       8441      1  1 10:57 ?        00:00:00 /usr/local/redis/bin/redis-server *:6380
root       8447   3979  0 10:58 pts/2    00:00:00 grep --color=auto redis
[root@chenpi bin]# 
Copy the code


Vim /etc/rc.d/rc.local edit file and add the command to start the Redis service in the last line.

#! /bin/bash
# THIS FILE IS ADDED FOR COMPATIBILITY PURPOSES
#
# It is highly advisable to create own systemd services or udev rules
# to run scripts during boot instead of using this file.
#
# In contrast to previous versions due to parallel execution during boot
# this script will NOT be run after all other services.
#
# Please note that you must run 'chmod +x /etc/rc.d/rc.local' to ensure
# that this script will be executed during boot.

touch /var/lock/subsys/local

/usr/local/redis/bin/redis-server  /usr/local/redis/bin/redis.conf
Copy the code


Add the Redis service port to the firewall; otherwise, the external system cannot access the Redis service. Add ports, restart the firewall, and view the ports opened by the firewall.

[root@chenpi bin]# firewall-cmd --zone=public --add-port=6380/tcp --permanent
success
[root@chenpi bin]# systemctl restart firewalld
[root@chenpi bin]# firewall-cmd --zone=public --list-ports
6380/tcp
[root@chenpi bin]# 
Copy the code


validation

Use the built-in client to interact with Redis.

/usr/local/redis/bin/redis-cli -p 127.0.0.1 -p 6380
Copy the code


If no password is entered for authentication after the client is successfully connected, an error occurs when you run the Redis command.

D:\devTools\Redis3.2.1>redis-cli.exe -h 127.0.0.1 -p 6380
127.0.0.1:6380> KEYS *
(error) NOAUTH Authentication required.
127.0.0.1:6380> AUTH 123456
OK
127.0.0.1:6380> KEYS *
(empty list or set) 127.0.0.1:6380 >Copy the code


Of course, it is possible to specify the password when using the client connection command, but it is not recommended because it is displayed in clear text.

/usr/local/redis/bin/redis-cli -p 127.0.0.1 -p 6380 -a 123456
Copy the code


After successfully connecting to the Redis client, you can run the following command to exit the connection and stop the Redis service.

# exit the connection
exit

# Close the Redis service
shutdown
Copy the code



I am Chen PI, an ITer of Internet Coding. I search “Chen PI’s JavaLib” on wechat and read the latest articles as soon as possible, reply to [information], and then I can get the technical materials, electronic books, interview materials of first-line big factories and excellent resume templates carefully arranged by me.