10. Redis Sentinel on Docker // Redis High Availability using Docker containers and Redis Sentinels

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey hi everyone I hope all of you are doing great so in this video we are going to learn about setting up Reddy's High availability and Sentinel on Dockers so these are the steps which we are going to follow so first of all we are going to create a Docker Network okay so this is the command to create a Docker Network the network name is going to be called redisnet and this network is going to be used for interconnecting all the subsequent ready stockers which we are going to create so once we have the network ready then we are going to create we are going to first of all create a Docker container which is going to be running a redis master node so here you can see this is the command which is called Docker run hyphen hyphen name right is master and there is some Port mapping available and then here you can see we are using the network which we created in previous command so a network name is called redisnet and we want to run red is indeed detest mode and then we are passing this command to ready server so append only what append only going to do is basically whatever command which is going to be passed to ready so it is going to be storing those information so here is a quick explanation you can pause the screen here if you want to read it read everything once you understand and you are comfortable then you can move on so once we let's say create the master node then we are going to create two replica nodes so here you can see this is the command for creating first replica node and here you can see until here statement is same like like the above command and then in the end we are just adding one more parameter which is called slaver so we are telling that this Docker container which I am creating it is going to run ready service and then ready service which is is going to be created and that service is basically going to be replica of readys Master and here you can see redis Master is again a container which is already created previously okay so this is the name of the container which is redis master so we are going to use this container name here when we are creating replicas so that is why it is important that you create master first before creating replicas okay and one more thing here you can see Port mapping so I hope you have already understood about Port mapping by reading here in the docker command explanation however I am going to explain these things in detail when I'm creating tutorial about Docker so I think let's begin we are going to perform these steps until here then I am going to explain you further steps so first of all I'm using solar putty to connect to the server so this is the server which I have the IP for that is 192 168 43 19. so let me just connect to this server uh guys again if you want to practice it you can do it as well just create a server so here you can see I have created I have installed Centos basically on Virtual box and then I I can practice all of these I know it will not be possible for everyone to have you know three node servers or six node servers to practice all of these things so it's better you have virtualbox installed you create a server and then you install Docker on that and then you can create as many containers as you want so here you can see we are now logging to the server so I'm going to run Docker container LS command here you can see right now we do not have any container and then we are going to start creating containers one by one okay now let's also Docker Network LS so I can show you what is the existing Network so here you can see we have three networks available one is called Bridge other is called host third one is called none so we are going to create a new network name which is gonna going to be called red is hyphen net so let me create it I'm going to run it here hit enter and here you can see it has given some ID which means basically Docker network has been created so I'm going to do Docker Network LS again and here you can see in the output we have a Docker Network called redisnet now whatever Docker container which I'm creating I'm going to provide this network name so let's move on and start creating our first node which is going to be a master node so here I am going to go to the server again hit enter and here you can see it has created it has created a redis master node now I'm going to create replica nodes so I'm just going to copy the command and guys uh don't worry I'm going to give you this command in a document so I'm going to put it in a document I'm going to give you the link so you can also just copy paste it so here you can see I'm just going to create another replica okay so now we can do Docker container LS and here you can see three containers has been created and these are the names of all the containers so first container is called radius Master then we have two replicas one is called radius replica one another one is called redis replica two Okay so until now we have performed the steps now in order to set up Sentinel we also need to know the IP address of radius Master okay so here is this command this command is going to give us IP address of all the docker containers so if I run it here you can see IP address for radius Master is 172.18.0.2 and that is great so we are going to now create a radius ready Sentinel okay so now in order to in order to start running Sentinel containers we also need to have Sentinel configuration file available because Sentinel configuration file is going to be read by Sentinel so I'm going to create I'm going to create this Sentinel configuration file and notice one thing here we are going to create a three files okay for three Sentinels so we are going to have three Sentinels and this is the directory where I am going to keep all the Sentinel Sentinel configuration files so here you can see I have a directory called slash apps slash ready slash Sentinel slash sentinel1 and in this file I'm going to keep a configuration for first Sentinel okay and then here I'm going to keep configuration for second Sentinel and here I'm going to keep configuration for third Sentinel so again you can make any other directory structure which you want and you can replace it with the proper name and inside this all of this I'm creating sentinel.com file okay now here if you see this IP address we need to replace it with the IP address of the master node so I'm just going to go to go here and this is the IP address of the redis master node so I'm going to I'm going to go back here I'm going to replace it so let me change it okay so I'm I'll change it so basically what this command is doing is it is it is going to put this line okay this piece of information going to be get returned to this file which is which is going to be in this directory however if you want to create this manually you can go and create a file called sentinel.com and then you can write this information Sentinel monitor my master IP address space port number Space 2 2 is the Quorum okay so I have already discussed this and explained this in detail in the previous videos so that's why I'm not going into detail in this lesson okay so I'm just going to copy it and going to run it one by one so here you can see First Command is executed let's go on copy the second one and going to paste it here it's executed going to go to third one copy it and then we are going to go to the server paste it now all the configuration files have been created now we can go on and start creating our Sentinel containers now again for Sentinel containers here is the here is the explanation of the command which we are running so please pause it here understand each of the items which we are going to run so it is going to give you better Clarity okay you can pause the video here and once you watch it or once you understand it you can move on so now here you can see I'm just going to copy first line item and then going to go to the server run it here you can see container is created going to copy second line item going to go to the server run it again and let me clear the screen now I'm going to run third item okay now clear the screen again so now we have created a contain we have created six containers okay so we can go on and do let me go on and do Docker oh come on uh Docker container LS here you can see we have six containers now okay and if you want to see IP addresses of all the all the these containers you can again go on and run this command so here let me go here and run it here you can see we have the we have six containers and these are the container names and IP addresses now let's go on and create and and basically uh now we have everything ready so we can start seeing the logs of a sentinel just to understand what is going on so let me clear the screen again and we can run this command I have put this command to see the logs continuously so you can uh copied and run it here so I'm just gonna paste it okay seems like something went wrong while pasting it uh so let me write this here uh Docker container logs hyphen follow and here you can give the name of the container for which you want to see the logs so I want to see logs of ready Sentinel underscore one oh sorry here is a mistake we need to write follow okay so here you can see this is showing you the logs of first Sentinel so here again you can see there are various statements there are some statements starting with plus monitor plus slave and so on if you want to understand this in detail you can go to the documentation and I have given the link of the documentation as well you can go to this URL and it is a basically explaining each of the things in detail so [Music] here you can see uh what is the meaning of plus s down so s down means the specified instance is now subjectively down state and so on if you see plus Monitor and any other status basically here is the explanation for all that uh but in short let's go to the server and try to understand so now what it has done is here you can see it knows that it is uh it is able to basically pick up uh pickup Master configuration and it knows that this is a master server and the IP for The Master server is 178.18.0.2 and then it also knows about about the slave servers here you can see it is it is having entry of a slave server and slave server ending with 0.3 and 0.4 okay so this is about two slate servers now let's let me open uh one more uh console where we can go and log into ready CLI and go and see some other information as well so while it is opening uh let it open or probably let me open one more console okay so now we have three console let me open one more console so what we will do is let me run a ready Sentinel logs for all the three servers this is for first one so let me do for other one as well Docker logs uh hyphen hyphen follow red is Sentinel underscore 2 okay and for third Sentinel as well let's run the same command so it is going to be called Docker logs hyphen hyphen follow red is hyphen Sentinel underscore three okay so here you can see what is actually going on in all the Sentinel instances now let's do one thing uh we are going to go to going to I am going to connect to radius Master node and as you can see for redis master node we can just run reduce hyphen CLI and we can do Keys star now you can see currently we do not have anything written here so let me do set name and my name so here you can see it is saying okay it means this information has been written now I'm exiting from here now I'm connecting to reduce radius now I'm going to connect to replica nodes okay and let me just quickly run this command again so we get the IP address is off all the containers so here for IP address of radius replica node is 172.18.0.3 so I'm going to do red is hyphen CLI and we want to connect to a replica node so I'm going to put hyphen H for host parameter and then we can get the IP address of the node to which we want to connect so here you can see we are now connected to one of the replica node and then we are going to do Keys star and here you can see uh we wrote this information in master and now it has been replicated to replica node and we can do get name you can see the information here now if we try to write here for example let me try to write age you can see here we are getting the error that this is a read-only replica okay so it means it it is a clear indication that this is a replica node and it will not allow you to write it so this is the information about setting up so basically we have set up a we have set up a ready Sentinel High availability now I'm going to go to Python program and let me go to the Python program we will try to connect to ready Sentinel using Python program and then we will see how things work okay because the objective is to basically we need to be able to use ready Sentinel using using our program right or using our application so here you can see I am having a program already available here I'll give you the I'll give you this program as well so you don't need to copy paste anything now here one thing you need to understand we have Sentinels running okay and since now I am accessing this this Docker container from outside this server okay so in order to access this from outside the server I'm going to use uh you know you can call it as public IP address so I'm going to use this IP address okay this is just for your understanding so here you can see this IP address and this port is basically for Sentinel one and now the IP address is same however Port is different okay the port is 26380 this is for Sentinel number two and port number 26381 is for Sentinel number three so I'm going to go back to this documentation again and here you can see if you remember these are the commands which we executed to run Sentinel one to N3 so here you can see in the port mapping for first Sentinel we have given 26379 for second Sentinel we have given two six three eight zero and for third Sentinel we have given two six three eight one so this is the same port information which I am giving here in the Python program as well however this public IP is going to be same because eventually I have created all these Docker nodes on a single server okay so what I'm trying to do here is I'm trying to connect to the host server on which we have created the docker containers and then I'm asking this host server to connect me on this port okay so this port is basically is responsible for you can say Sentinel one okay now we are going to run it and here you can see we have got some error okay so I know the error is coming here because you can see here I have done some mapping stuff here I'm just going to replace it because I know the IP address is of um of Master and replica is starting from 178.18 okay previously while testing it was a different IP so I had created this program okay so here you can see now we know that IP address 172 18.0.2 is for uh which container it is for master container right we can go to this we can go here and here you can see this IP address is of Master container now if you want to access Master container from outside of this host machine in that case we have to reach using the public IP address public IP address which is going to be 192.168.43.19 in this case right here you can see even for Sentinel also my IP address is same however only the port information is changing so basically I'm asking Sentinel that if you if you get reply like this if you get this IP address so map it to Port 6379 if you get this IP address map it to 6380 if you get this output mappy26381 I think you'll be able to ex able to understand it little better once you practice this by installing uh Docker containers on a by installing radius on a Docker container so I'm going to run it again and this time you can see we have not got any error everything has executed properly now I'm going to run Master connection dot ping this also gave us a reply of true it means this is executed properly now here I'm going to update a key which is called age and then I'm going to just put some number here and here you can see we have got response of true which means this information has been written now we are going to write Age Again to get this information back from radius here you can see we have got the information back now we do want to verify it from CLI as well so I'm just going to write radius CL connect to redis using CLI and then right Keys star here you can see we have Edge information here right now you can do get age and here you can see that we have got the same information here which means using Python program as well we are able to connect to Docker containers using Sentinel as the entry point so basically in this program what is happening is let me quickly summarize because now we are we are using Sentinel right to monitor radius and to monitor whether the high availability or stuff like that okay so whenever we are going to interact with radius we are not sure of which which node is going to be the redis master right now because if let's say the primary radius Master crashes ready Sentinel is going to change going to promote any other slave any other available slave to Master Okay so first level you are always going to connect to ready Sentinel and then right with the help of Sentinel you are going to get the information of the recent Master by running something like this and then using that information you are going to connect to redis okay so this is how it works now let me do one thing Let's do let's uh perform some failover so what I will do is this is uh I'm going to stop reduce Master Okay so I'm going to write Docker container stop redis master so here you can see the redis master is stopped now here in the Sentinel we are going to see some entries which is going to tell us that it is basically it is able to detect that Master current Master is down and then it is going to promote any any of the available slave to master so we are waiting for that event to appear here again it does take some time you can you can put those information about you know how long it needs to wait and stuff like that in the redis configuration file but usually it takes like 10 seconds or so so here you can see it has already detected that Master has gone down okay and then it is going to it is saying promoting slave to master so here you can see promoting slave slave is this and it is promoting it to master so same information you will be able to see here as well okay so now our new master is this one so switch master has happened here you can see previous master was ending with 0.2 IP address now that on that IP address we have stop ready services so now new master new master is 172.18.0.3 okay here you can see we had IP addresses of everything so this I this one red is replica one which had IP address of 172.18.0.3 uh this has now become new master and if we want to connect here we can do radius hyphen CLI we can do 172.18.0.3 and connection is refused because we have not wrote hyphen h now you can do key star here you can see we are able to connect now let's put uh let me write something by writing gender maybe gender information and here you can see now this replica is allowing us to uh to write information because this is no longer a replica this has become a master now let's go back to our Python program and here you will notice I don't really need to change anything in the Python program I'm just going to run it and here you can see it now already giving me information about the new Master new available Master which is 172.18.0.3 and I can ping it yes and we can write some other information like uh like favorite movie and let's put some movie name here you can see we are getting true and then we also we can read this information and here you can see we are getting the output now I'm going to go to ready CLI going to do keys star again here you can see favorite movie is appearing here okay so it means now failover is working properly now let's do one thing we are going to bring back uh bring back redis master so I'm gonna do radius container start radius Master now guys notice one thing this even though you know this node we have named it as redis Master however now a replica node has become a redis master so now when this node comes up this node is no longer going to be a master this is going to become a replica node for a new master which is which is this one right which is ending with 0.3 so I'm just going to hit enter and this container has started now let's see what is coming here here you can see an entry of minus s down so what is the meaning of minus s down so let's go here you can read here minus s down means the specified instance is no longer in down state okay so let's go here and it is talking that it is telling you that this slave which was basically previously master and now has become slave this is now no longer in down state okay so this has come up and now it is uh it is a replica of this master new master which is basically our new master okay so here you can see we have performed failover and then we have performed a restoration as well now everything will continue to work as it is you can connect to any of the node using redis hyphen CLI again I think I don't want to go along uh go and keep on explaining the same thing but yeah I think you understood the pawn point so if you have any question please feel free to let me know in the comment section I'll be more than happy to assist you thank you so much for watching
Info
Channel: Vikas Jha
Views: 4,425
Rating: undefined out of 5
Keywords: redis docker, redis sentinel docker, sentinel docker, redis sentinel, redis sentinel failover, redis sentinel python, redis sentinel get master, redis sentinel config, redis sentinel commands, redis high availability, redis high availability failover and restore, redis high availability setup, redis high availability aws, redis sentinel example, check redis sentinel status
Id: XxR6M6XQq6I
Channel Id: undefined
Length: 24min 14sec (1454 seconds)
Published: Sat Mar 11 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.