preface

Today we will set up a Redis sentinel and redis cluster, for the friends who have not built a reference. Without further ado, here we go.

1. Install redis


I downloaded Redis version 4.0.

Decompress the package and run make install. Then go to the SRC directory and run make install to check whether the package is successful

Start the Redis service, redis-service

Modify the configuration file for background startup and change it to yes

Start the service

It shows that the service is up

Then connect the client to verify whether it can be used normally. The picture shows that it can be used normally

2. Build sentries


Create a new conf file, store all the configuration files, copy three copies of redis.conf to conf and rename it.

Change the configuration files of 6380 and 6381 to port 6380 and 6381 then add Slaveof 127.0.0.1 6379 respectively and start the three services

The connect client tests the data put into the master library to see if it can be retrieved from the slave library

If you can check it from the database, the master and slave are ok.

Sentinel is going to have three services so for convenience we also put sentinel’s configuration file in conf, copy sentinel. Conf to conf and rename it.

Then let’s get all the sentries up. When all three sentries get up, the following page will be displayed

It can be seen from the log that the sentry has worked, so how to verify, we stop the Redis Lord to try.

Looking at the sentinel log, 6380 is already dominant

Which means the sentinels we built are still usable.

3. Create a cluster


Let’s build a pseudo cluster, mainly because I have a Linux server, the cluster requires at least three master and slave nodes, so let’s open six ports 9000,9001,9002,9003,9004,9005 respectively, and then create a cluster directory, in which we store the configuration files of each instance.

First modify the configuration file to change the port number from 6379 to 9000,9001,9002,9003,9004,9005. Then I turned on the comment to enable the cluster. I only changed the following configuration

Port 9000 // Bind each configuration file to its own port number daemonize yes //redis run cluster-enabled yes // enable cluster Conf // Cluster configuration cluster-node-timeout 15000 // Request timeout the default value is 15 seconds. You can set the timeout value by defaultCopy the code

Then start all of them. Before starting, let’s have a look at the current startup situation of Redis, which was started when the sentinels were set up before.

Then start 9000-9005

Then start the cluster. For versions 5.0 or later, you need to start the cluster with ruby script, ok

Yum install ruby: error: ruby is missing

An error occurs when you run the cluster script command again after the installation

The redis interface was not installed, and the redis interface was not installed, so the ruby version was too low, so the ruby version was too low, but I underestimated it, and it took longer to fix the problem than the sentry and cluster. It’s all over the Internet

gpg --keyserver hkp://keys.gnupg.net --recv-keys 409B6B1796C275462A1703113804BB82D39DC0E3 7D2BAF1CF37B13E2069D6956105BD0E739499BDB
Copy the code

And then everything goes smoothly to the next step, but not to me, execute and display

Someone said that the network may be the problem, and then add ali cloud source to try again

gem sources -a http://mirrors.aliyun.com/rubygems/
Copy the code

And then the implementation or not, is really the skull pain, then read a little brother’s article, which said that you can manually import, feel to see the savior quickly operate. Ah come on finally, reference documentation, www.cnblogs.com/wxzhe/p/107…

Finally, execute the cluster Ruby command again to display

Display success, we try to enter 9000 client, must add -C otherwise the cluster is not good.

And let’s check 9002 and see if we can find it

If no problem is found, the cluster can be used.

4. To summarize


Redis sentinel and cluster setup is actually relatively easy, the only trouble is to upgrade the Ruby version, so if you want to build a cluster, or 5.0 or above is recommended, directly from the client can execute the cluster command. Ok, that’s it. See you next week.