Redis server install and configure

Introduction

Redis server is an open-source (BSD licensed), in-memory data structure store used as a database, cache, and message broker. Gives data structures as stringshasheslistssetssorted sets, including range queries, bitmaps, hyperloglogs, geospatial indexes, and streams. In addition to, Redis has built-in replicationLua scriptingLRU evictiontransactions, and different levels of on-disk persistence and provides tremendous availability via Redis Sentinel and automated partitioning with Redis Cluster.

Also Written in C and works in most POSIX like Linux, *BSD, and OS X, without dependencies.Linux and OS X are mostly the operating systems that Redis was developed and tested. Also I would recommend using Linux for deployment. So Redis may work in the Solaris systems.There is no official statement that supports Windows builds.

Installing required packages

  1. firstly, Install Epel repository to obtain the redis package required
[root@unixcop ~]# dnf install epel-release -y
Last metadata expiration check: 0:04:26 ago on Fri 13 Aug 2021 02:51:22 PM UTC.
Dependencies resolved.
========================================================================================================
 Package                     Architecture          Version                  Repository             Size
========================================================================================================
Installing:
 epel-release                noarch                8-11.el8                 extras                 24 k

Transaction Summary
========================================================================================================
Install  1 Package

Total download size: 24 k
Installed size: 35 k
Downloading Packages:
epel-release-8-11.el8.noarch.rpm                                         40 kB/s |  24 kB     00:00
--------------------------------------------------------------------------------------------------------
Total                                                                   7.1 kB/s |  24 kB     00:03
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                1/1
  Installing       : epel-release-8-11.el8.noarch                                                   1/1
  Running scriptlet: epel-release-8-11.el8.noarch                                                   1/1
  Verifying        : epel-release-8-11.el8.noarch                                                   1/1

Installed:
  epel-release-8-11.el8.noarch

Complete!
[root@unixcop ~]#

2. Install Redis package

[root@unixcop ~]# dnf install redis -y
Extra Packages for Enterprise Linux Modular 8 - x86_64                  176 kB/s | 927 kB     00:05
Extra Packages for Enterprise Linux 8 - x86_64                          4.3 MB/s |  10 MB     00:02
Last metadata expiration check: 0:00:03 ago on Fri 13 Aug 2021 02:57:53 PM UTC.
Dependencies resolved.
========================================================================================================
 Package        Architecture    Version                                        Repository          Size
========================================================================================================
Installing:
 redis          x86_64          5.0.3-2.module_el8.2.0+318+3d7e67ea            appstream          925 k
Enabling module streams:
 redis                          5

Transaction Summary
========================================================================================================
Install  1 Package

Total download size: 925 k
Installed size: 3.2 M
Downloading Packages:
redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64.rpm                    978 kB/s | 925 kB     00:00
--------------------------------------------------------------------------------------------------------
Total                                                                   503 kB/s | 925 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                1/1
  Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64                               1/1
  Installing       : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64                               1/1
  Running scriptlet: redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64                               1/1
  Verifying        : redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64                               1/1

Installed:
  redis-5.0.3-2.module_el8.2.0+318+3d7e67ea.x86_64

Complete!
[root@unixcop ~]#

3. So Start Redis daemon after successful installation

[root@unixcop ~]# systemctl start redis
[root@unixcop ~]# systemctl enable redis
Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /usr/lib/systemd/system/redi
s.service.
[root@unixcop ~]#

4. Configure Redis server for remote access

vi /etc/redis.conf
     46 ################################## NETWORK #####################################
     47
     48 # By default, if no "bind" configuration directive is specified, Redis listens
     49 # for connections from all the network interfaces available on the server.
     50 # It is possible to listen to just one or multiple selected interfaces using
     51 # the "bind" configuration directive, followed by one or more IP addresses.
     52 #
     53 # Examples:
     54 #
     55 bind 127.0.0.1 192.168.56.102

5. Also Configure Redis password to secure connection.Can make a more secure password.If you haven’t set up a password yet, instructions in this section show how to set the database server password.

Now generate a password.

[root@unixcop ~]# echo "unixcop.com" | sha256sum
3d6b487de4c43d829f2817c4156d6f32790189d8e27640f6927b5e3da8997883  -
[root@unixcop ~]#

6. Add the generated password to the Redis configuration

vi /etc/redis.conf
################################## SECURITY ###################################

# Require clients to issue AUTH <PASSWORD> before processing any other
# commands.  This might be useful in environments in which you do not trust
# others with access to the host running redis-server.
#
# This should stay commented out for backward compatibility and because most
# people do not need auth (e.g. they run their own servers).
#
# Warning: since Redis is pretty fast an outside user can try up to
# 150k passwords per second against a good box. This means that you should
# use a very strong password otherwise it will be very easy to break.
#
# requirepass foobared
requirepass 3d6b487de4c43d829f2817c4156d6f32790189d8e27640f6927b5e3da8997883

7. Restart Redis server services

systemctl restart redis

8. Now validate connection using radis-cli. Error seen below is normal

[root@unixcop ~]# redis-cli -h 192.168.56.192 ping
(error) NOAUTH Authentication required.

9. Now try command authenticates with the password specified in the Redis configuration file.

[root@unixcop ~]# redis-cli
127.0.0.1:6379> auth 3d6b487de4c43d829f2817c4156d6f32790189d8e27640f6927b5e3da8997883
OK
127.0.0.1:6379> config get requirepass
1) "requirepass"
2) "3d6b487de4c43d829f2817c4156d6f32790189d8e27640f6927b5e3da8997883"
127.0.0.1:6379>

6. Also Check if the Redis port is listening

[root@unixcop ~]# netstat -an|grep 6379
tcp        0      0 192.168.56.192:6379          0.0.0.0:*               LISTEN
tcp        0      0 127.0.0.1:6379          0.0.0.0:*               LISTEN
[root@unixcop ~]#

7. In addition to, Validate if everything is set up properly, you can try to ping the Redis from your remote machine using the redis-cli utility which provides a command-line interface to a Redis:

[root@unixcop ~]# redis-cli -h 192.168.56.192 ping
PONG
[root@unixcop ~]#

Conclusion Redis server

So To learn more about how to use Redis, visit their official documentation page. Also Try PostgreSQL.Please feel free to comment about this tutorial.

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Latest articles

x