How to Setup Redis Cluster on Ubuntu 20.04. This article will start with an introduction of Redis server and it’s features, followed by the benefits of Redis Cluster and then setup of Redis Cluster on Ubuntu 20.04.
What is Redis Server?
Redis server stands for Remote Dictionary Server and in memory, fast, open source and key value data store. It is used as a database, message broker or a cache. It supports data structures (strings, hashes, lists, sets, bitmaps, hyperloglogs and geospatial indexes).
There is two ways to set up your environment with Redis.
1. Redis Sentinel —when speed is not your primary concern. Best for small implementation. 2. Redis Cluster which gives high availability plus clustering solution. Great for high availability and fast speed.
Redis cluster offers a convenient way to run the Redis server installation where operational data is shared across multiple Redis nodes. Redis cluster is a native sharding implementation that aids data distribution across multiple nodes. This type of cluster also provides a degree of available space for the data partitions during the time of nodes failure or inability to communicate with other nodes.
Features of Redis Cluster
The following are the key features of the Redis cluster:
All data nodes in the Redis cluster are directly connected with a service channel.
It consists of TCP protocol base port + 4000 nodes.
It is a native Solution.
Node to node protocol is binary and they are optimized for bandwidth and speed.
Clients talk as usual using ASCII protocols with minor additions.
Nodes never proxy with queries.
Every ping and pong Packet contains a gossip section.
The Redis cluster provides high performance and linear scalability up to 1000+ nodes. In the Redis cluster nodes, no proxies, asynchronous and no merge operations are used on values.
It provides a better way to write safely, as the system tries to retain all the message, that originated from the clients connected with the master nodes.
The Redis cluster is able to survive multiple data partitions where the majority of the data nodes are reachable.
In this post about how to Setup Redis Cluster on Ubuntu 20.04, we will show you how to install two node Redis Cluster on Ubuntu 20.04.
For the purpose of this article, we will use the following setup:
First, you will need to install Redis server package on both master and slave hosts. You can install it by running the following command on both hosts:
apt-get install redis-server -y
Once the Redis server is installed, you can verify the status of the Redis service using the following command:
systemctl status redis
You will get the following output:
● redis-server.service - Advanced key-value store
Loaded: loaded (/lib/systemd/system/redis-server.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2022-01-11 09:00:51 UTC; 13s ago
Docs: http://redis.io/documentation,
man:redis-server(1)
Main PID: 1213 (redis-server)
Tasks: 4 (limit: 2353)
Memory: 1.8M
CGroup: /system.slice/redis-server.service
└─1213 /usr/bin/redis-server 127.0.0.1:6379
Jan 11 09:00:51 master systemd[1]: Starting Advanced key-value store...
Configure Redis Master
At this point, the Redis server is up and running on both hosts. Now, you will need to configure the Redis master and slave server.
First, go to the Redis Master node and edit the Redis main configuration file using the following command:
nano /etc/redis/redis.conf
Change the following line to set keepalive time:
tcp-keepalive 60
Uncomment and change the following line to make the server accessible from the remote hosts:
bind 127.0.0.1 69.28.84.50
Change the following lines for backing up data:
appendonly yes
appendfilename "appendonly.aof"
Following that, change the following line to set the master password:
In this part of how to Setup Redis Cluster on Ubuntu 20.04 is to check your Master Slave. If your Master server fails then you can promote the slave server to act as the backup master server. That way Redis server can continue to work while we resolve the issues on the master server.
To promote the Redis slave server as the master, connect to slave instance with the following command:
redis-cli -h 69.28.85.189 -p 6379
Next is to authenticate the Slave instance with a password:
69.28.85.189:6379> auth slavepassword
Following that is to turn off slave behavior with the following command:
69.28.85.189:6379> SLAVEOF NO ONE
Your Slave server will now act as a master server. You can check it with the following command:
Once the Redis Master server is up you will need to demote the slave server. On the Slave server, run the following command to reconnect it as a slave to the original master server:
69.28.85.189:6379> SLAVEOF 69.28.84.50 6379
Now, verify the behavior of the Slave server using the following command:
69.28.85.189:6379> INFO
You should see that your Slave server is now back to work as a slave.
How to Setup Redis Cluster on Ubuntu 20.04 Conclusion
In the above guide, we explained how to set up two node Redis cluster on Ubuntu 20.04 server. You can now add more slave nodes to scale the Redis cluster. I hope this setup will help you to prevent data loss. Redis is great for fast speed, its ability to store data types like sets and lists and strong contender for persistence.
Redis Cluster is a high availability and horizontal scalability solution for Redis that helps large organizations to split the data into multiple nodes to prevent data fail.
Redis cluster is self managed and it’s big benefit is that it removes the single point of failure that proxy servers brought.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.