Install Latest Redis Server on CentOS 7 / RHEL 7

Posted on 62 views

In this tutorial, we will cover step by step ways to install Redis on CentOS 7 / RHEL 7. Redis is an Open Source in-memory data structure store. Redis can be used as a database server, as a message broker or for caching data in memory for faster retrieval.  Among the data structures supported by Redis are:

  • Hashes
  • sets with range queries
  • Strings
  • sorted lists
  • Hyperloglogs
  • Bitmaps
  • Geospatial indexes e.t.c

For Ubuntu use: How to Install Redis on Ubuntu

For RHEL 8, use: Install and Configure Redis Server on RHEL 8 / CentOS 8

How to Install Redis on CentOS 7 / RHEL 7

In this section, we will look at how to install the latest release of Redis on CentOS 7 / RHEL 7.

Step 1: Update your CentOS 7 / RHEL 7

Ensure your system is updated before installing Redis

sudo yum -y update

Step 2: Add REMI repository

The latest version of Redis is available on Remi repository, add it by executing the command:

sudo yum -y install http://rpms.remirepo.net/enterprise/remi-release-7.rpm

Step 3: Install Redis on CentOS 7 / RHEL 7

After adding the repository, install latest Redis on CentOS 7 / RHEL 7 from the repository.

sudo yum --enablerepo=remi install redis

Get more package details from:

$ rpm -qi redis
Name        : redis
Version     : 7.0.0
Release     : 1.el7.remi
Architecture: x86_64
Install Date: Fri May 20 13:24:43 2022
Group       : Applications/Databases
Size        : 5339497
License     : BSD
Signature   : DSA/SHA1, Wed Apr 27 15:23:54 2022, Key ID 004e6f4700f97f56
Source RPM  : redis-7.0.0-1.el7.remi.src.rpm
Build Date  : Wed Apr 27 15:22:31 2022
Build Host  : builder.remirepo.net
Relocations : (not relocatable)
Packager    : Remi Collet
Vendor      : Remi's RPM repository 
URL         : http://redis.io
Bug URL     : https://forum.remirepo.net/
Summary     : A persistent key-value database
....

Step 3: Start Redis Service on CentOS 7 / RHEL 7

Redis service can be started on CentOS 7 / RHEL 7 using systemd service manager. Also, enable the service to start on system boot.

sudo systemctl enable --now redis

Step 4: Enable network Listen for Redis Service (Optional)

For network clients to connect to your Redis server, it needs the service to listen on a network IP Address.

Open the file /etc/redis.conf with your favorite text editor:

sudo vi /etc/redis.conf

Then change line 61 bind 127.0.0.1 to your server IP:

bind 172.21.10.11

To listen on all available interfaces, set like below:

bind * -::*

Configure Redis Authentication – (Optional but recommended)

Configure Redis Authentication for clients to require AUTH  before processing any other commands.

requirepass  

Example:

requirepass oobaiY8

Set Persistent Store for Recovery

Set persistence mode by changing the appendonlyvalue to yes

appendonly yes
appendfilename "appendonly.aof"

Restart redis service after making the changes

sudo systemctl restart redis

Check redis service status:

$ systemctl status  redis
 redis.service - Redis persistent key-value database
   Loaded: loaded (/usr/lib/systemd/system/redis.service; enabled; vendor preset: disabled)
  Drop-In: /etc/systemd/system/redis.service.d
           └─limit.conf
   Active: active (running) since Fri 2022-05-20 13:25:22 UTC; 2min 56s ago
 Main PID: 8847 (redis-server)
   Status: "Ready to accept connections"
   CGroup: /system.slice/redis.service
           └─8847 /usr/bin/redis-server 127.0.0.1:6379

May 20 13:25:22 centos7.example.io systemd[1]: Starting Redis persistent key-value database...
May 20 13:25:22 centos7.example.io systemd[1]: Started Redis persistent key-value database.

You can view the port and IP used by Redis service using the sscommand:

$ sudo ss -tunelp | grep 6379
tcp LISTEN 0 128 *:6379  *:*  users:(("redis-server",pid=28163,fd=4)) uid:995 ino:305

If you have an active firewalld service, allow port 6379

sudo firewall-cmd --add-port=6379/tcp --permanent
sudo firewall-cmd --reload

Step 5: Test connection to Redis Server

Confirm that you can connect to redis locally:

$ redis-cli
127.0.0.1:6379>

Test authenticate:

127.0.0.1:6379> AUTH 
OK

You should receive OK in the output. If you input a wrong password, Authentication should fail:

127.0.0.1:6379> AUTH WrongPassword
(error) ERR invalid password

Check redis information.

127.0.0.1:6379>  INFO

This will output a long list of data. You can limit the output by passing Section as an argument. E.g.

127.0.0.1:6379> INFO Server
# Server
redis_version:3.2.12
redis_git_sha1:00000000
redis_git_dirty:0
redis_build_id:7897e7d0e13773f
redis_mode:standalone
os:Linux 3.10.0-862.14.4.el7.x86_64 x86_64
arch_bits:64
multiplexing_api:epoll
gcc_version:4.8.5
process_id:3640
run_id:ef36ca5ae9d561d8d3d3ea979cc8481eab0da874
tcp_port:6379
uptime_in_seconds:145
uptime_in_days:0
hz:10
lru_clock:433261
executable:/usr/bin/redis-server
config_file:/etc/redis.conf

Step 6: Perform Redis Benchmarking

Run the benchmark with 15 parallel connections, for a total of 10k requests, against local redis to test its performance.

$ redis-benchmark -h 127.0.0.1 -p 6379 -n 10000 -c 15

# Sample output
................................................
====== LRANGE_600 (first 600 elements) ======
  10000 requests completed in 0.15 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
67114.09 requests per second

====== MSET (10 keys) ======
  10000 requests completed in 0.15 seconds
  15 parallel clients
  3 bytes payload
  keep alive: 1

100.00% <= 0 milliseconds
66666.66 requests per second

For more options and examples, use:

$ redis-benchmark --help

You have successfully installed Redis on CentOS 7 / RHEL 7.

coffee

Gravatar Image
A systems engineer with excellent skills in systems administration, cloud computing, systems deployment, virtualization, containers, and a certified ethical hacker.