22.6 C
Texas
angeloma
Senior Writer and partner

How to install Redis on Ubuntu 20.04?

Hello, friends in this post, we will show you how to install Redis on Ubuntu 20.04

As we well know Ubuntu 20.04 is a great operating system that is used in many servers. That’s why it has quite important tools in this area as is the case of Redis.

For those who don’t know, Redis is a database engine in memory, based on storage in hash tables (key/value). Thanks to its speed and ease of use, Redis is a popular choice for web, mobile, gaming, advertising technology, and IoT applications. Also, it is released under the BSD license which makes it open-source.

So, whenever you need to enter and request data quickly, Redis is a good alternative to traditional relational databases.

- Advertisement -

So today you will learn how to install it.

Install Redis on Ubuntu 20.04

Redis is available in the official Ubuntu 20.04 repositories. This is perhaps the easiest and safest way to install Redis. Remember that on a server it is sometimes preferable to sacrifice new features for the sake of stability.

So, open a terminal or connect to your server through SSH and update your system.

:~$ sudo apt update
:~$ sudo apt upgrade

This ensures that your system will be ready for the installation of Redis. Also, you will have the security patches installed and thus a more stable system.

So, install Redis with the following command:

:~$ sudo apt install redis-server
[sudo] password for angelo:
Reading package lists… Done
Building dependency tree
Reading state information… Done
The following additional packages will be installed:
libatomic1 libhiredis0.14 libjemalloc2 liblua5.1-0 lua-bitop lua-cjson redis-tools
Suggested packages:
ruby-redis
The following NEW packages will be installed:
libatomic1 libhiredis0.14 libjemalloc2 liblua5.1-0 lua-bitop lua-cjson redis-server redis-tools
0 upgraded, 8 newly installed, 0 to remove and 0 not upgraded.
Need to get 925 kB of archives.
After this operation, 4123 kB of additional disk space will be used.
Do you want to continue? [Y/n]
1.- Install Redis on Ubuntu 20.04
1.- Install Redis on Ubuntu 20.04

Once the proposal for units has been accepted, the whole process will begin.

In the end, you can check whether the Redis service is running. You can do this using systemd like any other system service.

:~$ sudo systemctl status redis-server
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 Wed 2020-07-22 19:54:09 UTC; 28s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1480 (redis-server)
Tasks: 4 (limit: 846)
Memory: 1.9M
CGroup: /system.slice/redis-server.service
└─1480 /usr/bin/redis-server 127.0.0.1:6379
Jul 22 19:54:09 osradar systemd[1]: Starting Advanced key-value store…
Jul 22 19:54:09 osradar systemd[1]: redis-server.service: Can't open PID file /run/redis/redis-server.pid (yet?) after start: Operation not permitted
Jul 22 19:54:09 osradar systemd[1]: Started Advanced key-value store.
2.- Redis service status
2.- Redis service status

As you can see, Redis is installed and running smoothly.

Configuring Redis on Ubuntu 20.04

Even though Redis is ready for battle, some of his settings need to be reviewed. These will allow a smooth use of the program and allow you to get the most out of it.

First of all, the /etc/redis/redis.conf file is where all Redis’ settings are located. It is very well documented so you can customize it to the maximum by just reading it.

First, we will make a backup. In case we make a mistake we can always go back to the original configuration.

:~$ sudo cp /etc/redis/redis.conf /etc/redis/redis.conf.bak

And now, proceed to open it.

:~$ sudo nano /etc/redis/redis.conf

As I said, the archive is well documented and therefore looks quite extensive, but the reality is quite easy to follow.

In this file, you can change Redis’ default port which is 6379 to whatever you prefer.

port 6379

You can also specify a time to keep a TCP connection active.

tcp-keepalive 300

The time is based on seconds.

Or, set a maximum memory usage by Redis. This will depend on your computer and the amount of memory it has.

maxmemory 300mb

As well as the policy of the application with the maximum memory size.

maxmemory-policy noeviction

In this case, I have opted for the default setting that prohibits the use of more than memory and throws an error message.

Save all changes by pressing CTRL + O and exit the CTRL + X editor.

To apply all these changes, simply restart the Redis service.

:~$ sudo systemctl restart redis-server

And again you can check the service and verify that everything is in order.

:~$ sudo systemctl status redis-server

To access Redis’ console, type:

:~$ redis-cli

And, for example, ping to check the operation:

ping

And you’ll get a screen output like this:

3.- Redis CLI
3.- Redis CLI

So, everything is up and running.

Conclusion

Redis is a wonder of application. It stores data quite quickly and especially the response time makes it important in mobile or IoT applications. Therefore, knowing how to install it in Ubuntu 20.04 is a great step to start with this great database engine.

So, share this post and join our Telegram Channel.

- Advertisement -
Everything Linux, A.I, IT News, DataOps, Open Source and more delivered right to you.
Subscribe
"The best Linux newsletter on the web"

LEAVE A REPLY

Please enter your comment!
Please enter your name here



Latest article