Oops! Something went wrong while submitting the form.
We use cookies to improve your browsing experience on our website, to show you personalised content and to analize our website traffic. By browsing our website, you consent to our use of cookies. Read privacy policy.
In the first part of this blog, we saw how to install standalone redis service on DC/OS with Persistent storage using RexRay and AWS EBS volumes.
A single server is a single point of failure in every system, so to ensure high availability of redis database, we can deploy a master-slave cluster of Redis servers. In this blog, we will see how to setup such 6 node (3 master, 3 slave) Redis cluster and persist data using RexRay and AWS EBS volumes. After that we will see how to import existing data into this cluster.
Redis Cluster
It is form of replicated Redis servers in multi-master architecture. All the data is sharded into 16384 buckets, where every master node is assigned subset of buckets out of them (generally evenly sharded) and each master replicated by its slaves. It provides more resilience and scaling for production grade deployments where heavy workload is expected. Applications can connect to any node in cluster mode and the request will be redirected to respective master node.
Objective: To create a Redis cluster with number of services in DCOC environment with persistent storage and import the existing Redis dump.rdb data to the cluster.
Prerequisites:
Make sure rexray component is running and is in a healthy state for DCOS cluster.
Steps:
As per Redis doc, the minimal cluster should have at least 3 master and 3 slave nodes, so making it a total 6 Redis services.
All services will use similar json configuration except changes in names of service, external volume, and port mappings.
We will deploy one Redis service for each Redis cluster node and once all services are running, we will form cluster among them.
We will use host network for Redis node containers, for that we will restrict Redis nodes to run on particular node. This will help us to troubleshoot cluster (fixed IP, so we can restart Redis node any time without data loss).
Using host network adds a prerequisites that number of dcos nodes >= number of Redis nodes.
Click on the Add button in Services tab of DCOS UI
Click on JSON configuration
Add below json config for Redis service, change the values which are written in BLOCK letters with # as prefix and suffix.
#NODENAME# - Name of Redis node (Ex. redis-node-1)
#NODEHOSTIP# - IP of dcos node on which this Redis node will run. This ip must be unique for each Redis node. (Ex. 10.2.12.23)
#VOLUMENAME# - Name of persistent volume, Give name to identify volume on AWS EBS (Ex. <dcos cluster="" name="">-redis-node-<node number="">)</node></dcos>
#NODEVIP# - VIP For the Redis node. It must be ‘Redis’ for first Redis node, for others it can be the same as NODENAME (Ex. redis-node-2)
After updating the highlighted fields, copy above json to json configuration box, click on ‘Review & Run’ button in the right corner, this will start the service with above configuration.
Once above service is UP and Running, then repeat the step 2 to 4 for each Redis node with respective values for highlighted fields.
So if we go with 6 node cluster, at the end we will have 6 Redis nodes UP and Running, like:
Note: Since we are using external volume for persistent storage, we can not scale our services, i.e. each service will only one instance max. If we try to scale, we will get below error :
2. Form the Redis cluster between Redis node services:
To create or manage Redis-cluster, first deploy redis-cluster-util container on DCOS using below json config:
If all OK, it will show OK with status, else it will show ERR with the error message.
3. Import existing dump.rdb to Redis cluster
At this point, all the Redis nodes should be empty and each one should have an ID and some assigned slots:
Before reuse an existing dump data, we have to reshard all slots to one instance. We specify the number of slots to move (all, so 16384), the id we move to (here Node 1 - 10.0.1.90:6379) and where we take these slots from (all other nodes).
Now we have dump.rdb in our redis-cluster-util container, we can import it to our Redis cluster. Execute and go to the redis-cluster-util container using:
WARNING: Like our Oracle DB instance can have multiple databases, similarly Redis saves keys in keyspaces. Now when Redis is in cluster mode, it does not accept the dumps which has more than one keyspaces. As per documentation: “Redis Cluster does not support multiple databases like the stand alone version of Redis. There is just database 0 and the SELECT command is not allowed. “
So while importing such multi-keyspace Redis dump, server fails while starting on below issue :
Above error shows that server saved this key to instance 10.0.9.203:6379, so client redirected it. To follow redirection, use flag “-c” which says it is a cluster mode, like:
Application entrypoint for Redis cluster is mostly depends how your Redis client handles cluster support. Generally connecting to one of master nodes should do the work.
Use below host:port in your applications :
redis.marathon.l4lb.thisdcos.directory:6379
Automation of Redis Cluster Creation
We have automation script in place to deploy 6 node Redis cluster and form a cluster between them.
It deploys 6 marathon apps for 6 Redis nodes. All nodes are deployed on different nodes with CLUSTER_NAME as prefix to volume name.
Once all nodes are up and running, it deploys redis-cluster-util app which will be used to form Redis cluster.
Then it will print the Redis nodes and their IP addresses and prompt the user to proceed cluster creation.
If user selects to proceed, it will run redis-cluster-util app and create the cluster using IP addresses collected. Util container will prompt for some input that the user has to select.
Conclusion
We learned about Redis cluster deployment on DCOS with Persistent storage using RexRay. We also learned how rexray automatically manages volumes over aws ebs and how to integrate them in DCOS apps/services. We saw how to use redis-cluster-util container to manage Redis cluster for different purposes, like forming cluster, resharding, importing existing dump.rdb data etc. Finally, we looked at the automation part of whole cluster setup using dcos cli and bash.
Installing Redis Cluster with Persistent Storage on Mesosphere DC/OS
In the first part of this blog, we saw how to install standalone redis service on DC/OS with Persistent storage using RexRay and AWS EBS volumes.
A single server is a single point of failure in every system, so to ensure high availability of redis database, we can deploy a master-slave cluster of Redis servers. In this blog, we will see how to setup such 6 node (3 master, 3 slave) Redis cluster and persist data using RexRay and AWS EBS volumes. After that we will see how to import existing data into this cluster.
Redis Cluster
It is form of replicated Redis servers in multi-master architecture. All the data is sharded into 16384 buckets, where every master node is assigned subset of buckets out of them (generally evenly sharded) and each master replicated by its slaves. It provides more resilience and scaling for production grade deployments where heavy workload is expected. Applications can connect to any node in cluster mode and the request will be redirected to respective master node.
Objective: To create a Redis cluster with number of services in DCOC environment with persistent storage and import the existing Redis dump.rdb data to the cluster.
Prerequisites:
Make sure rexray component is running and is in a healthy state for DCOS cluster.
Steps:
As per Redis doc, the minimal cluster should have at least 3 master and 3 slave nodes, so making it a total 6 Redis services.
All services will use similar json configuration except changes in names of service, external volume, and port mappings.
We will deploy one Redis service for each Redis cluster node and once all services are running, we will form cluster among them.
We will use host network for Redis node containers, for that we will restrict Redis nodes to run on particular node. This will help us to troubleshoot cluster (fixed IP, so we can restart Redis node any time without data loss).
Using host network adds a prerequisites that number of dcos nodes >= number of Redis nodes.
Click on the Add button in Services tab of DCOS UI
Click on JSON configuration
Add below json config for Redis service, change the values which are written in BLOCK letters with # as prefix and suffix.
#NODENAME# - Name of Redis node (Ex. redis-node-1)
#NODEHOSTIP# - IP of dcos node on which this Redis node will run. This ip must be unique for each Redis node. (Ex. 10.2.12.23)
#VOLUMENAME# - Name of persistent volume, Give name to identify volume on AWS EBS (Ex. <dcos cluster="" name="">-redis-node-<node number="">)</node></dcos>
#NODEVIP# - VIP For the Redis node. It must be ‘Redis’ for first Redis node, for others it can be the same as NODENAME (Ex. redis-node-2)
After updating the highlighted fields, copy above json to json configuration box, click on ‘Review & Run’ button in the right corner, this will start the service with above configuration.
Once above service is UP and Running, then repeat the step 2 to 4 for each Redis node with respective values for highlighted fields.
So if we go with 6 node cluster, at the end we will have 6 Redis nodes UP and Running, like:
Note: Since we are using external volume for persistent storage, we can not scale our services, i.e. each service will only one instance max. If we try to scale, we will get below error :
2. Form the Redis cluster between Redis node services:
To create or manage Redis-cluster, first deploy redis-cluster-util container on DCOS using below json config:
If all OK, it will show OK with status, else it will show ERR with the error message.
3. Import existing dump.rdb to Redis cluster
At this point, all the Redis nodes should be empty and each one should have an ID and some assigned slots:
Before reuse an existing dump data, we have to reshard all slots to one instance. We specify the number of slots to move (all, so 16384), the id we move to (here Node 1 - 10.0.1.90:6379) and where we take these slots from (all other nodes).
Now we have dump.rdb in our redis-cluster-util container, we can import it to our Redis cluster. Execute and go to the redis-cluster-util container using:
WARNING: Like our Oracle DB instance can have multiple databases, similarly Redis saves keys in keyspaces. Now when Redis is in cluster mode, it does not accept the dumps which has more than one keyspaces. As per documentation: “Redis Cluster does not support multiple databases like the stand alone version of Redis. There is just database 0 and the SELECT command is not allowed. “
So while importing such multi-keyspace Redis dump, server fails while starting on below issue :
Above error shows that server saved this key to instance 10.0.9.203:6379, so client redirected it. To follow redirection, use flag “-c” which says it is a cluster mode, like:
Application entrypoint for Redis cluster is mostly depends how your Redis client handles cluster support. Generally connecting to one of master nodes should do the work.
Use below host:port in your applications :
redis.marathon.l4lb.thisdcos.directory:6379
Automation of Redis Cluster Creation
We have automation script in place to deploy 6 node Redis cluster and form a cluster between them.
It deploys 6 marathon apps for 6 Redis nodes. All nodes are deployed on different nodes with CLUSTER_NAME as prefix to volume name.
Once all nodes are up and running, it deploys redis-cluster-util app which will be used to form Redis cluster.
Then it will print the Redis nodes and their IP addresses and prompt the user to proceed cluster creation.
If user selects to proceed, it will run redis-cluster-util app and create the cluster using IP addresses collected. Util container will prompt for some input that the user has to select.
Conclusion
We learned about Redis cluster deployment on DCOS with Persistent storage using RexRay. We also learned how rexray automatically manages volumes over aws ebs and how to integrate them in DCOS apps/services. We saw how to use redis-cluster-util container to manage Redis cluster for different purposes, like forming cluster, resharding, importing existing dump.rdb data etc. Finally, we looked at the automation part of whole cluster setup using dcos cli and bash.
Velotio Technologies is an outsourced software product development partner for top technology startups and enterprises. We partner with companies to design, develop, and scale their products. Our work has been featured on TechCrunch, Product Hunt and more.
We have partnered with our customers to built 90+ transformational products in areas of edge computing, customer data platforms, exascale storage, cloud-native platforms, chatbots, clinical trials, healthcare and investment banking.
Since our founding in 2016, our team has completed more than 90 projects with 220+ employees across the following areas:
Building web/mobile applications
Architecting Cloud infrastructure and Data analytics platforms