[Graphic tutorial] Install Redis on Centos stand-alone

 

1.1. Install Redis dependencies

Redis is written based on C language, so you first need to install the gcc dependencies required by Redis:

yum install -y gcc tcl

1.2. Upload the installation package and decompress it

For example, Kege put it in the /usr/local/src directory:

unzip:

tar -xzf redis-6.2.6.tar.gz

After decompression:

Enter the redis directory:

cd redis-6.2.6

Run the compile command:

make && make install

If there are no errors, the installation should be successful.

The default installation path is in /usr/local/binthe directory :

This directory is configured as an environment variable by default, so these commands can be run from any directory. in:

  • redis-cli: is the command line client provided by redis

  • redis-server: is the redis server startup script

  • redis-sentinel: is the redis sentinel startup script

1.3. Startup

There are many ways to start redis, for example:

  • start by default

  • Specify the configuration to start

  • boot up

1.3.1. Start by default

After the installation is complete, enter the redis-server command in any directory to start Redis:

redis-server

As shown in the picture:

This kind of startup belongs to 前台启动, it will block the entire session window, and CTRL + CRedis will stop when the window is closed or pressed. Not recommended.

1.3.2. Specified configuration startup

If you want Redis to 后台start with mode, you must modify the Redis configuration file, which is under the redis installation package we decompressed earlier ( /usr/local/src/redis-6.2.6), and the name is redis.conf:

First check whether it is currently in the installation directory of Redis:

Modify redis.conf

Let's make a backup of this configuration file first:

cp redis.conf redis.conf.bck

Then modify some configurations in the redis.conf file

# The address allowed to be accessed, the default is 127.0.0.1, which will result in only local access. If you change it to 0.0.0.0, you can access it from any IP. Do not set it to 0.0.0.0 in the production environment. bind 0.0.0.0 
# 
Daemon process, after changing it to yes, it can run in the background 
daemonize yes  
# Password, you must enter the password to access Redis after setting 
requirepass 123321

Other common configurations of Redis:

# Listening port 
port 6379 
# Working directory, the default is the current directory, that is, the command when running redis-server, logs, persistence and other files will be saved in this directory dir. # The number of databases, set to 1, means only 
1 
is used There are 16 libraries by default, numbered 0~15 
databases 1 
# Set the maximum memory maxmemory that redis can use 
512mb 
# Log file, the default is empty, no log is recorded, you can specify the log file name 
logfile "redis.log"

Start Redis:

# Enter the redis installation directory 
cd /usr/local/src/redis-6.2.6 
# Start 
redis-server redis.conf

Out of service:

# Use redis-cli to execute the shutdown command to stop the Redis service, 
#Because the password was configured before, you need to specify the password through -u 
redis-cli -u 123321 shutdown

1.3.3. Boot up automatically

We can also implement boot self-starting through configuration.

First, create a new system service file:

vi /etc/systemd/system/redis.service

The content is as follows:

[Unit]
Description=redis-server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/bin/redis-server /usr/local/src/redis-6.2.6/redis.conf
PrivateTmp=true

[Install]
WantedBy=multi-user.target

Then reload the system service:

systemctl daemon-reload

Now, we can use the following set of commands to operate redis:

# Start 
systemctl start redis 
# Stop 
systemctl stop redis 
# Restart 
systemctl restart redis 
# View status 
systemctl status redis

Execute the following command to make redis boot up automatically:

systemctl enable redis

Good article recommendation:

Redis series

Custom Annotation Series Tutorials

docker series tutorial

distributed correlation

Kai brother recommended

Guess you like

Origin blog.csdn.net/kaizi_1992/article/details/128680101