This brief tutorial shows students and new new users how to install and configure Redis in-memory data store and cache server on Ubuntu 18.04 | 16.04 server..
For the uninitiated, Redis is an in-memory cache and data store that is commonly used as database to store data structures such as strings, hashes, lists, sets, sorted sets with range queries, etc.
At a higher level of implementation, it can also provide high availability via Redis Sentinel including monitoring, notifications Automatic failover and automatic partitioning across multiple Redis nodes..
For more about Redis, please check out its homepage.
To get Redis on Ubuntu, follow the steps below:
Step 1: Install Redis Server
This post assumes that your account on the server is capable of running administrative privileges..
To get Redis installed, simply run the commands below on Ubuntu command line..
sudo apt update sudo apt install redis-server
After running the above commands, Redis server should be installed and ready to use…
The commands below can be used to stop, start and enable Redis Server to automatically start up everytime the system boots up…
sudo systemctl stop redis-server sudo systemctl start redis-server sudo systemctl enable redis-server
To verify if the server is running, run the commands below
sudo systemctl status redis-server
That should display the status of the Redis Server service:
Output: redis-server.service - Advanced key-value store Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled) Active: active (running) since Fri 2019-11-29 09:02:30 CST; 15s ago Docs: http://redis.io/documentation, man:redis-server(1) Main PID: 26589 (redis-server) Tasks: 4 (limit: 4674) CGroup: /system.slice/redis-server.service └─26589 /usr/bin/redis-server 127.0.0.1:6379 ...................................................
This is how you know Redis is running
Step 2: Configure Redis Server
Now that the server is installed and verified, use the steps below to configure for remote login and adjust Ubuntu firewall..
By default, Redis doesn’t allow access from remote locations ( access from different server/client).. All access is restricted to the local host of the server it is installed on.. ( example: 127.0.0.1).
In most environments, Redis Server and the applications it supports are running on a single server… In this situation, no remote access is necessary, since all the communications are done on the single host computer..
However, if both the Redis server and applications using it are on separate hosts, then remote access will be required…
To allow remote access, open Redis configuration file by running the commands below:
sudo nano /etc/redis/redis.conf
Then change the highlighted line as shown below… basically replacing 127.0.0.1 with all zeros ( 0.0.0.0 ) or restrict access to a specific host IP that will need access to Redis..
# IF YOU ARE SURE YOU WANT YOUR INSTANCE TO LISTEN TO ALL THE INTERFACES # JUST COMMENT THE FOLLOWING LINE. # ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ bind 0.0.0.0 ::1 # Protected mode is a layer of security protection, in order to avoid that # Redis instances left open on the internet are accessed and exploited.
Save the file and exit.
After making the changes to the file, restart Redis service.
sudo systemctl restart redis-server
Verify that Redis is listening for all connections on 0.0.0.0 by running the commands below:
ss -an | grep 6379
You should get an output as show below:
Output: tcp LISTEN 0 128 0.0.0.0:6379 0.0.0.0:* tcp LISTEN 0 128 [::1]:6379 [::]:*
If you’re also running Ubuntu firewall, simply add the policy below to allow all hosts on your subnet ( 192.168.0.0 ) access to the Redis server and port number..
sudo ufw allow proto tcp from 192.168.0.0/24 to any port 6379
That should do it.
To test if Redis hosted on IP address 192.168.0.2 is responding to remote hosts… type the commands below from the remote server…
redis-cli -h 192.168.0.2 ping
The Redis sever should respond with a pong
If you receive a correct reply, then all is done..
This post shows you how to install and configure Redis Server on Ubuntu 18.04 | 16.04.. If you find any errors above, please leave us a comment and report below:
You may also like the post below: