How to Manually Install Redis 6.0 on CentOS 7

install redis 6.0centos 7 redisredis manual installationsystemd redis serviceredis configuration
Published·Modified·

Redis is a fully open-source, high-performance key-value database that adheres to the BSD license. It is currently very popular and widely used. This article documents the method for manually installing the Redis service on CentOS 7.

Install Redis

First, execute the following commands to install the necessary dependencies:

# Install dependencies
yum -y install cpp binutils glibc glibc-kernheaders glibc-common glibc-devel gcc make
# Upgrade GCC
yum -y install centos-release-scl
yum -y install devtoolset-9-gcc devtoolset-9-gcc-c++ devtoolset-9-binutils
scl enable devtoolset-9 bash

At the time of writing this article, the latest stable version of Redis is 6.0. As time passes, the version will change, so please download the latest version from the official Redis website: https://redis.io/download.

# Download Redis
wget https://download.redis.io/releases/redis-6.0.9.tar.gz
# Extract Redis
tar xzf redis-6.0.9.tar.gz
# Enter the Redis directory
cd redis-6.0.9
# Compile
make

After successful compilation, the Redis service binary file is located at src/redis-server. You can run Redis directly by entering this path. However, it will run in the foreground, meaning the Redis service will stop if the process ends or the window is closed.

Run Redis

For easier management and maintenance later, you can move the Redis src directory to a specific location, such as mv src/ /usr/local/redis.

Also, copy the redis.conf file from the redis-6.0.9 directory:

cp redis.conf /etc

By default, Redis runs in the foreground. If you need it to run in the background, you must modify the redis.conf configuration file. Change:

daemonize no

to:

daemonize yes

Then restart the Redis service with the command: /usr/local/redis/redis-server /etc/redis.conf. At this point, it will run in the background. You can verify the process using the ps command:

[root@hecs-centos-7 ~]# ps -ef|grep 'redis'
root     10217     1  0 22:00 ?        00:00:00 /usr/local/redis/redis-server 127.0.0.1:6379

Set Environment Variables

Entering the absolute path for Redis every time is inconvenient. You can add the Redis path to the Linux environment variables by appending the following to the bottom of the /etc/profile file:

export PATH=$PATH:/usr/local/redis

Then run the command source /etc/profile to make it effective. Now you can execute Redis commands directly without typing the full path. For example:

[root@hecs-centos-7 ~]# redis-server -v
Redis server v=6.0.9 sha=00000000:0 malloc=jemalloc-5.1.0 bits=64 build=ef93b08070de4db5

Redis Client

After the compilation above, Redis comes with a built-in command-line client redis-cli. Enter the following command to check if Redis is running normally:

[root@hecs-centos-7 ~]# /usr/local/redis/redis-cli 
127.0.0.1:6379> ping
PONG

Register as a Systemd Service

If you need to set Redis to start automatically on boot, you can register it as a Systemd service for easier management. First, create a service file: vi /etc/systemd/system/redis.service, with the following content:

[Unit]
Description=Redis Server
After=network.target

[Service]
Type=forking
ExecStart=/usr/local/redis/redis-server /etc/redis.conf

[Install]
WantedBy=multi-user.target

Then run systemctl daemon-reload to reload the services. Next, you can use the systemctl command to manage it:

# Start Redis
systemctl start redis
# Stop Redis
systemctl stop redis
# Enable on boot
systemctl enable redis

For more information on Systemd services, refer to: Linux System Writing Systemd Service Practice.

Conclusion

Redis has many configuration parameters, which are not detailed in this article. For more usage instructions, it is recommended to refer to the official documentation. Although tools like Baota, LNMP, and Oneinstack integrate one-click Redis installation for convenience, it is also necessary to understand the manual installation method for future maintenance.

Redis Official Website: https://redis.io/

This article partially references: