In this article, we have covered how to install Redis on AlmaLinux 8 and configure it. We will install redis-cli 5.0.3.
Redis is an open source (BSD licensed), in-memory data structure store, used as a database, cache and message broker. It supports data structures such as strings, hashes, lists, sets, sorted sets with range queries, bitmaps, hyperloglogs, geospatial indexes with radius queries and streams.
Redis was designed for use by trusted clients in a trusted environment, and has no robust security features of its own. Redis does, however, have a few security features like a basic unencrypted password as well as command renaming and disabling.
We have covered installation and configuration of Redis.
Prerequisites
Cloud instance running AlmaLinux 8.
Root access or normal user with administrative privileges.
Step 1 - Keep the server up to date
# dnf update -y
Step 2 - Install Redis
Run following DNF package manager command to install Redis.
# dnf install redis -y
Step 3 - Change supervised directive from no to systemd
This is important configuration change to make in the Redis configuration file. supervised directive allows you to delivery an init system to manage Redis as a service.
# vi /etc/redis.conf
Find supervised and change it from no to systemd which will looks like:
# 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
# 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 liveness pings back to your supervisor.
supervised systemd
Save and exit the Redis configuration file.
After editing the file, start and enable the Redis service:
# systemctl start redis
# systemctl enable redis
To verify that Redis has installed successfully, we can run following command:
# redis-cli ping
Output:
PONG
If this is the case, it means we now have Redis running on our server and we can begin configuring it to enhance its security.
Step 4 - Configure a Redit password
Configuring a Redis password enables one of its built-in security features — the auth command — which requires clients to authenticate before being allowed access to the database. Like the bind setting, the password is configured directly in Redis’s configuration file, /etc/redis.conf. Reopen that file:
# vi /etc/redis.conf
Find requirepass
# requirepass foobared
Uncomment it by removing the #, and change foobared to a very strong password of your choosing.
After setting the password, save and close the file then restart Redis:
# systemctl restart redis
To test that the password works, open the Redis client:
# redis-cli
A sequence of commands used to verify whether the Redis password is working is as follows. Before authenticating, the first command tries to set a key to a value:
127.0.0.1:6379> set key1 23
That won’t work as you have not yet authenticated, so Redis returns an error:
Output
(error) NOAUTH Authentication required.
The following command authenticates with the password specified in the Redis configuration file:
127.0.0.1:6379> auth your_redis_password
Redis will acknowledge that you have been authenticated:
Output
OK
After that, running the previous command again should be successful:
127.0.0.1:6379> set key1 23
Output
OK
The get key1 command queries Redis for the value of the new key:
127.0.0.1:6379> get key1
Output
"23"
This last command exits redis-cli. You may also use exit:
127.0.0.1:6379> quit
We have successfully seen how to install Redis on AlmaLinux 8 and configure it.
Top comments (0)