How To Install Redis 6.0 On Ubuntu 22.04

How To Install Redis 6.0 On Ubuntu 22.04

In this short tutorial we will learn how to install Redis on Ubuntu 22.04 LTS Linux operating system. Redis (Remote Dictionary Server) is an open source in-memory data structure store, used as a distributed, in-memory key–value database, cache and message broker, with optional durability. Redis can be used as a database server, as a message broker or for caching data in memory for faster retrieval.

Installing Redis On Ubuntu 22.04

In this tutorial, we will install Redis version 6.0.16 on the Ubuntu 2204 operating system. The following are the steps for installing Redis on Ubuntu 22.04.

  1. Update Ubuntu 22.04 System
  2. Installing Redis
  3. Configuring Redis Server
  4. Securing Redis
  5. Testing Redis

The detailed task above, will be explained in the sub-chapter below.

1. Update Ubuntu 22.04 System

The first step of Redis 6.0 installation is to update local packages software. This task will cut down the installation time and it also helps prevent zero-day exploits against outdated software. We will use command line :

$ sudo apt update
$ sudo apt upgrade

2. Installing Redis

Redis Server package is available on the Ubuntu upstream repository. After updating our system, we will install Redis by submitting the following commands line :

$ sudo apt install redis-server

Output :

ramans@infodiginet:~$ sudo apt install redis-server
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following additional packages will be installed:
  libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-tools
Suggested packages:
  ruby-redis
The following NEW packages will be installed:
  libjemalloc2 liblua5.1-0 liblzf1 lua-bitop lua-cjson redis-server redis-tools
0 upgraded, 7 newly installed, 0 to remove and 0 not upgraded.
Need to get 1.273 kB of archives.
After this operation, 5.725 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 libjemalloc2 amd64 5.2.1-4ubuntu1 [240 kB]
Get:2 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 liblua5.1-0 amd64 5.1.5-8.1build4 [99,9 kB]
Get:3 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 liblzf1 amd64 3.6-3 [7.444 B]
Get:4 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 lua-bitop amd64 1.0.2-5 [6.680 B]
Get:5 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 lua-cjson amd64 2.1.0+dfsg-2.1 [17,4 kB]
Get:6 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 redis-tools amd64 5:6.0.16-1ubuntu1 [856 kB]
Get:7 http://id.archive.ubuntu.com/ubuntu jammy/universe amd64 redis-server amd64 5:6.0.16-1ubuntu1 [45,9 kB]        
Fetched 1.273 kB in 1min 26s (14,8 kB/s)                                                                             
Selecting previously unselected package libjemalloc2:amd64.
(Reading database ... 271426 files and directories currently installed.)
Preparing to unpack .../0-libjemalloc2_5.2.1-4ubuntu1_amd64.deb ...
Unpacking libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
Selecting previously unselected package liblua5.1-0:amd64.
Preparing to unpack .../1-liblua5.1-0_5.1.5-8.1build4_amd64.deb ...
Unpacking liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Selecting previously unselected package liblzf1:amd64.
Preparing to unpack .../2-liblzf1_3.6-3_amd64.deb ...
Unpacking liblzf1:amd64 (3.6-3) ...
Selecting previously unselected package lua-bitop:amd64.
Preparing to unpack .../3-lua-bitop_1.0.2-5_amd64.deb ...
Unpacking lua-bitop:amd64 (1.0.2-5) ...
Selecting previously unselected package lua-cjson:amd64.
Preparing to unpack .../4-lua-cjson_2.1.0+dfsg-2.1_amd64.deb ...
Unpacking lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Selecting previously unselected package redis-tools.
Preparing to unpack .../5-redis-tools_5%3a6.0.16-1ubuntu1_amd64.deb ...
Unpacking redis-tools (5:6.0.16-1ubuntu1) ...
Selecting previously unselected package redis-server.
Preparing to unpack .../6-redis-server_5%3a6.0.16-1ubuntu1_amd64.deb ...
Unpacking redis-server (5:6.0.16-1ubuntu1) ...
Setting up libjemalloc2:amd64 (5.2.1-4ubuntu1) ...
Setting up lua-cjson:amd64 (2.1.0+dfsg-2.1) ...
Setting up liblzf1:amd64 (3.6-3) ...
Setting up lua-bitop:amd64 (1.0.2-5) ...
Setting up liblua5.1-0:amd64 (5.1.5-8.1build4) ...
Setting up redis-tools (5:6.0.16-1ubuntu1) ...
Setting up redis-server (5:6.0.16-1ubuntu1) ...
Created symlink /etc/systemd/system/redis.service → /lib/systemd/system/redis-server.service.
Created symlink /etc/systemd/system/multi-user.target.wants/redis-server.service → /lib/systemd/system/redis-server.se
rvice.
Processing triggers for man-db (2.10.2-1) ...
Processing triggers for libc-bin (2.35-0ubuntu3.1) ...

By default, Redis service has been starting after installation completed. By default Redis does not run as a daemon. We can verify the Redis service by submitting command line :

$ sudo systemctl status redis

Output :

ramans@infodiginet:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2022-12-26 17:42:34 WIB; 23s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 6388 (redis-server)
Status: "Ready to accept connections"
Tasks: 5 (limit: 9408)
Memory: 2.7M
CPU: 107ms
CGroup: /system.slice/redis-server.service
└─6388 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" ">
Des 26 17:42:34 infodiginet systemd[1]: Starting Advanced key-value store…
Des 26 17:42:34 infodiginet systemd[1]: Started Advanced key-value store.

3. Configuring Redis Server

In Ubuntu system, the Redis configuration is located at the /etc/redis/redis.conf file. In this step, we will configure the basic Redis server.

  • Choose a ‘bind’ IP address to run the Redis service. It’s not recommended to use the public IP address for the Redis service. If we run multiple/cluster Redis service, we should use the internal network.
  • Change the ‘bind’ address with the localhost IP address for this example (IPv4 and IPv6). For security reasons to let Redis listen on localhost IP only if the services that use Redis will get installed on the same system.

By using our favorite text editor (nano or vi) we will udpdate redis configuration file.

$ sudo vi /etc/redis/redis.conf
# By default, if no "bind" configuration directive is specified, Redis listens
# for connections from all available network interfaces on the host machine.
# It is possible to listen to just one or multiple selected interfaces using
# the "bind" configuration directive, followed by one or more IP addresses.
#
# Examples:
#
# bind 192.168.1.100 10.0.0.1
 bind 127.0.0.1 ::1
#
# ~~~ WARNING ~~~ If the computer running Redis is directly exposed to the
# internet, binding to all the interfaces is dangerous and will expose the
# instance to everybody on the internet. So by default we uncomment the
# following bind directive, that will force Redis to listen only on the
# IPv4 loopback interface address (this means Redis will only be able to
# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#                        requires "expect stop" in your upstart job config
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous pings back to your supervisor.
supervised systemd

After file was updated, then we need to restart Redis server service, by submitting command line :

$ sudo systemctl restart redis-server
$ sudo systemctl enable redis-server

Output :

ramans@infodiginet:~$ sudo vi /etc/redis/redis.conf
ramans@infodiginet:~$ sudo systemctl restart redis-server
ramans@infodiginet:~$ sudo systemctl enable redis-server
Synchronizing state of redis-server.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable redis-server
ramans@infodiginet:~$ sudo systemctl status redis-server
● redis-server.service - Advanced key-value store
     Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-12-26 21:42:41 WIB; 33s ago
       Docs: http://redis.io/documentation,
             man:redis-server(1)
   Main PID: 3398 (redis-server)
     Status: "Ready to accept connections"
      Tasks: 5 (limit: 9408)
     Memory: 2.7M
        CPU: 150ms
     CGroup: /system.slice/redis-server.service
             └─3398 "/usr/bin/redis-server 127.0.0.1:6379" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "" "">

Des 26 21:42:41 infodiginet systemd[1]: Starting Advanced key-value store...
Des 26 21:42:41 infodiginet systemd[1]: Started Advanced key-value store.

4. Securing Redis Server

In this step, we will secure Redis server which was installed on our system.

4.1. Enable Password Authentication

The password authentication give user an access control to Redis server. For this purpose we need to to uncomment the ‘requirepass‘ section on the ‘redis.conf’ file and type strong password after it.

# IMPORTANT NOTE: starting with Redis 6 "requirepass" is just a compatibility
# layer on top of the new ACL system. The option effect will be just setting
# the password for the default user. Clients will still authenticate using
# AUTH <password> as usually, or more explicitly with AUTH default <password>
# if they follow the new protocol: both will work.
#
 requirepass JU880?L/p[%fa;f@jadf,xf;

# Command renaming (DEPRECATED).

4.2. Disabling Dangerous Redis Commands

Redis has a feature for disabling some specific Redis commands, it can be used to rename or disable some of the dangerous commands such as ‘FLUSHALL’ for erasing all data, ‘CONFIG’ command to set up configuration parameters through the Redis CLI, etc.

Example :

rename-command FLUSHALL "NEED4SPEED"

After all are set, then we need to restart Redis-server to take affect.

$ systemctl restart redis-server

5. Testing Redis

In this step, we will test some Redis function via Redis CLI. For starting Redis CLI, we will log in to Redis console by typing command line :

$ redis-cli

Output :

ramans@infodiginet:~$ redis-cli
127.0.0.1:6379> PING
PONG
127.0.0.1:6379> set test "OK, its working, Mantaps ... !" [EX seconds|PX millisecond127.0.0.1:6379> set test "OK, its working, Mantaps ... !"
OK
127.0.0.1:6379> get test
"OK, its working, Mantaps ... !"
127.0.0.1:6379> 

Conclusion

In this tutorial, we have learned how to install Redis version 6.0 on Ubuntu 22.04 LTS operating system.

(Visited 198 times, 1 visits today)

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *