Redis installation and startup (the latest nanny tutorial in 2022)

Redis installation and startup

Redis official website address: https://redis.io/

1. Install Redis on a single machine

1.1. Install Redis dependencies

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

yum install -y gcc tcl

1.2. Upload the installation package and extract it

If you are lazy to go to the official website to download the installation package, the installation package of redis-6.2.6 is attached below the blog post.

I put it in the /usr/local/src directory

unzip:

tar -xzf redis-6.2.6.tar.gz

Enter the redis directory:

cd redis-6.2.6

Run the compile command:

make && make install


If there is no error (as shown below), the installation should be successful.
The default installation path is in the /usr/local/bin directory:

This directory is configured to environment variables by default, so you can run these commands from any directory. in:

  • redis-cli: is the command line client provided by redis
  • redis-server: is the server startup script of redis
  • redis-sentinel: is the sentinel startup script of redis

1.3. Start

There are many ways to start redis, for example:

  • Start by default
  • Start with the specified configuration
  • Auto-start

1.3.1. Default start

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

redis-server

As shown in the figure:
This kind of startup belongs to the foreground startup and will block the entire session window. Redis stops when the window is closed or CTRL + C is pressed. Not recommended.

1.3.2. Specify the configuration to start

If you want Redis to start in the background, you must modify the Redis configuration file, under the redis installation package we decompressed before (/usr/local/src/redis-6.2.6), named redis.conf:

Backup this configuration file:

cp redis.conf redis.conf.bck

Then modify some configurations in the redis.conf file:

# The address that is allowed to access, the default is 127.0.0.1, which can only be accessed locally. If it is modified to 0.0.0.0, it can be accessed at any IP, and the production environment should not be set to 0.0.0.0
bind 0.0.0.0
# The daemon process can run in the background after modifying it to yes
daemonize yes 
# Password, you must enter the password to access Redis after setting
requirepass 123321

Other common configurations of Redis:

# listening port
port 6379
# The 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 one library is used, there are 16 libraries by default, numbered 0~15
databases 1
# Set the maximum memory that redis can use
maxmemory 512mb
# The log file, the default is empty, no log is recorded, the log file name can be specified
logfile "redis.log"

Start Redis:

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

Out of service:

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

1.3.3. Self-start at boot

It can also be configured to automatically start at boot.

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 system services:

systemctl daemon-reload

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

# start up
systemctl start redis
# stop
systemctl stop redis
# reboot
systemctl restart redis
# View status
systemctl status redis

Execute the following command to make redis start automatically:

systemctl enable redis

2.Redis client

After installing Redis, we can operate Redis and implement CRUD of data. This requires a Redis client, including:

  • command line client
  • Graphical desktop client
  • programming client

2.1. Graphical desktop client

The great god on GitHub wrote the graphical desktop client of Redis, address: https://github.com/uglide/RedisDesktopManager

However, the repository provides the source code of RedisDesktopManager and does not provide the windows installation package.

The installation package can be found in the following warehouse (the Baidu network disk link is attached below, and you can also save and download it directly): https://github.com/lework/RedisDesktopManager-Windows/releases

2.2.1. Installation

Download and unzip the graphical desktop client for Redis and run the installer to install:

"Fool-style installation, I forgot to take screenshots of the specific steps here. Don't panic, just have a hand."

After the installation is complete, find the rdm.exe file in the installation directory and double-click it to run:

2.2.2. Establish a connection

Click the Connect to Redis Server button in the upper left corner:

Fill in the Redis service information in the pop-up window:

If the connection fails please check:
1. Is the redis service enabled?
2. Turn off the firewall (systemctl stop firewalld)
3. Confirm the password is correct

The connection was established successfully:

Redis has 16 warehouses by default, numbered from 0 to 15. The number of warehouses can be set through the configuration file, but it does not exceed 16, and the warehouse name cannot be customized.

If you are connecting to the Redis service based on redis-cli, you can use the select command to select the database:

# Select library 0
select 0

Redis installation package and Redis graphical desktop client
Link: https://pan.baidu.com/s/1v_1Fv4RaFKxx3ttvcecknQ
Extraction code: Chui

Tags: Database Redis Cache

Posted by David Rech on Sun, 16 Oct 2022 01:32:58 +0300