How to Install & Configure Redis on openSUSE Leap 15

Redis is an open-source (BSD licensed), in-memory key-value data structure store used as a database, cache, and message broker. Redis supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperlog logs, geospatial indexes, and streams. Redis also provides high availability with Redis Sentinel software logic, creating automatic partitioning across Redis nodes with Redis Cluster.

You will know how to install and configure Redis on your openSUSE Leap 15 operating system.

Advertisement

Prerequisites

  • Recommended OS: openSUSE Leap – 15.x.
  • User account: A user account with sudo or root access.
  • Required Packages: wget

Update Operating System

Update your openSUSE operating system to make sure all existing packages are up to date:

sudo zypper refresh

Once refreshed, run the update command.

sudo zypper update

The tutorial will be using the sudo command and assuming you have sudo status.

To verify sudo status on your account:

sudo whoami

Example output showing sudo status:

[joshua@opensuse ~]$ sudo whoami
root

To set up an existing or new sudo account, visit our tutorial on adding a User to Sudoers on openSUSE.

To use the root account, use the following command with the root password to log in.

su

Import Repository for Redis on openSUSE Leap

By default, Redis is available in openSUSE repositories, but it is not the latest version. However, the latest stable version can be easily installed in a few steps.

First, run the following command in your terminal that will import the Redis repository, which contains the last 6 series.

openSUSE 15.4:

sudo zypper ar https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.4/server:database.repo

openSUSE 15.3:

sudo zypper ar https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.3/server:database.repo

openSUSE 15.2:

sudo zypper ar https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.2/server:database.repo

Once the repository has been added, refresh your repository cache.

sudo zypper refresh

Example output (Using openSUSE Leap 15.3):

How to Install & Configure Redis on openSUSE Leap 15

Type A (For always trust), then press the ENTER KEY to proceed and complete the GPG import for the repository containing Redis.

Advertisement

Install Redis on openSUSE Leap 15

With the repository now imported and in working order, you can begin installing the latest version of the Redis server on your openSUSE Leap system. To start, use the following command.

sudo zypper install redis

Example output:

How to Install & Configure Redis on openSUSE Leap 15

Type Y, then press the ENTER KEY to proceed and complete the installation.

Verify Redis was installed correctly by verifying its version and build command:

redis-cli --version

Example output:

redis-cli 6.2.6
Advertisement

Create Redis Systemd Service

With installing Redis using the alternative method of using the latest version, you will need to create your Systemd service for it, and this can be luckily done in a few steps.

First, open a file that will be your service file for Redis.

sudo nano /etc/systemd/system/redis.service

Next, copy and paste the following.

[Unit]
Description=Redis In-Memory Data Store
After=network.target

[Service]
User=redis
Group=redis
ExecStart=/usr/sbin/redis-server /etc/redis/redis.conf
LimitNOFILE=10240
ExecStop=/usr/bin/redis-cli shutdown
Restart=always

[Install]
WantedBy=multi-user.target

Using nano as per the tutorial command, use (CTRL+O) to save and (CTRL+X) to exit the file.

Next, rename the example configuration file. For best practice, do not use the move command; instead, use copy since if you want to restart over, you have a new configuration file as a backup.

sudo cp /etc/redis/default.conf.example /etc/redis/redis.conf

Give Redis the correct file permission.

sudo chown redis.redis /etc/redis/redis.conf

Now start the Redis service and enable it on boot.

sudo systemctl enable redis --now

Example output:

Created symlink /etc/systemd/system/multi-user.target.wants/redis.service → /etc/systemd/system/redis.service.

Some of the Systemd service commands that may come in handy in your Linux terminal to control Redis are follows.

To enable automatic start for Redis service on system boot:

sudo systemctl enable redis

To start the Redis service:

sudo systemctl start redis

Next, verify the status and make sure Redis is running and, more importantly, with no errors:

systemctl status redis

Example output:

How to Install & Configure Redis on openSUSE Leap 15

Note, Reddis actively listens to localhost on the default port 6379. To confirm this type, the following:

ps -ef | grep redis

Example output:

How to Install & Configure Redis on openSUSE Leap 15

Now, while you are testing everything is working and operational, it’s a good idea to connect to your Redis service and then perform a ping test.

To perform the test, enter the following command:

redis-cli

Once connected, your terminal will display (127.0.0.1:6379). Now ping the Redis service as follows:

ping

Example output:

How to Install & Configure Redis on openSUSE Leap 15

Type the following to exit the Redis instance:

exit

How to Configure Redis

Redis can be configured in a few ways. The most notable action of why people use Redis is for caching purposes. To do this, you need to open the /etc/redis/redis.conf file using nano editor.

sudo nano /etc/redis/redis.conf

Configure Max Memory

Now, add the following to the end of the file. Note that you can change the memory value to whatever you like or, more importantly, optimal for your web application and server hardware.

maxmemory 500mb 
maxmemory-policy allkeys-lru

As you can see, the setting in the guide has 500MB dedicated to Redis as it is on a dedicated host with lots of RAM to spare. Once the 500MB is exhausted, Redis removes any key as per the LRU algorithm.

Configure Network Access

Another option is to listen to all services or set an IP address/subnet if you like your Redis service.

First, find line 69 in the configuration file.

First, to listen to all network interfaces, Comment “#” the line bind to IP:

Example:

# bind 127.0.0.1 ::1

Alternative Method:

bind 0.0.0.0/0

Note, make sure your internal network is trustworthy and appropriate security controls are in place.

To bind to an IP address, make sure it is a static IP address.

Example:

bind 192.150.5.2

To bind a network subnet.

Example:

bind 192.150.5.0/24

Note, it is highly suggested to set a password when using subnet or access to all interfaces to listen to.

Configure Password

Another security feature to further harden Redis is setting a password on the Redis instance.

Navigate to line 507, uncomment the “# requiredpass” line, and set a password.

Example:

requiredpass APASSWORD

Make sure this password is robust, numbers, letters, special symbols, and capitals randomized as Redis servers can be bruted forced on a decent box very well.

Next, when invoking the Redis-CLI, use the following command with the password that was set for the user.

Example:

auth THEPASSWORDSET

“THEPASSWORDSET” is the password that was created.

When users fail to log in, they will see the following error message.

(error) NOAUTH Authentication required.

When a user successfully logs in, they will see the following message.

OK

Once done, save your changes (CTRL+O) then exit (CTRL+X). Now restart the Redis service by typing:

sudo systemctl restart redis

Overall, there are many options for Redis, which are very well explained in the configuration file. Take the time to read through.

Configure Firewalld for Redis

By default, no rules are set up for Redis. This means you will need to create allow rules which is essential to stop attacks on Redis, failure to secure Redis will lead to issues down the track, so do not skip this unless you have other means to protect your Redis installation.

First, add a new dedicated zone for Redis firewalld policy:

sudo firewall-cmd --permanent --new-zone=redis

Next, specify the allowed IP addresses permitted to access the Redis.

sudo firewall-cmd --permanent --zone=redis --add-source=1.2.3.4

Replace 1.2.3.4 with the IP address that will be added to the allow list.

Once you have finished adding the IP addresses, open the port of the Redis. By default, this is TCP port 6379.

sudo firewall-cmd --permanent --zone=redis --add-port=6379/tcp

Note, you can change the default port in your configuration file if you change the firewall port open rule above to the new value.

After running those commands, reload the firewall to implement the new rules:

sudo firewall-cmd --reload

Example output if successful:

success

Now, as you tested at the start of the guide by pinging your Redis service to make sure it was operational, you can try the firewall rules and changes in IP by using the “redis-cli” command:

redis-cli -h  <ip address> ping

If setup correctly, the output should be:

pong

How to Remove (Uninstall) Redis

To remove Redis, use the following command in your terminal.

sudo zypper remove redis

This will remove Redis from your system immediately.

To remove the repository you imported if you never use Redis again.

openSUSE 15.4:

sudo zypper rr https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.4/server:database.repo

openSUSE 15.3:

sudo zypper rr https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.3/server:database.repo

openSUSE 15.2:

sudo zypper rr https://download.opensuse.org/repositories/server:/database/openSUSE_Leap_15.2/server:database.repo

Comments and Conclusion

In the tutorial, you have learned how to install Redis on openSUSE Leap 15 by importing the database repository containing the latest version of Redis and testing the service by pinging it and changing the memory limit and network interface to suit various setups.

To find more information about managing your Redis installation, visit the Redis documentation page.

Subscribe
Notify of
0 Comments
Inline Feedbacks
View all comments
adplus-dvertising
0
Would love your thoughts, please comment.x
()
x