Redis cluster, high availability cluster configuration, from the main Redis Sentinel +

Explain in advance the following steps to create the relevant steps are redis clusters highly available clusters, redis clusters into clusters and distributed high-availability cluster.

First of all I Redis is installed on Centos years, so in order to facilitate the operation is best to install the tool connection to the server, such as FinalShell or equal putty. Then my Redis is installed in the docker inside, if you do not use the following steps can save docker docker installation.

1. If you have installed you can first remove the old version

[root@localhost ~]# yum -y remove docker

2. Installation Management yum yum-utils source

[root@localhost ~]# yum install -y yum-utils

3. Set docker source

[root@localhost ~]# yum-config-manager --add-repo https://download.docker.com/linux/centos/docker-ce.repo

 4. Set metadata cache

[root@localhost ~]# yum makecache fast

5. Getting Started docker

[root@localhost ~]# yum -y install docker-ce

 6. Start docker

[root@localhost ~]# systemctl start docker

7. Verify

 

[root@localhost ~]# docker run hello-world

If the download fails, you can enter by vim /etc/docker/daemon.json configuration, as follows, fill in double quotes download the source, you can use Ali cloud download the source, the speed will be faster than abroad. Once you've configured "systemctl daemon-reload", and then restart the docker services.

{
    "registry-mirrors": [""]
}

Redis installed

拉取镜像
[root@localhost ~]# docker pull redis

       After installing redis, you can switch to the root directory, create redis directory, create a directory in the conf and data redis directory, copy files from redis.conf redis installed inside or outside of the container to the directory you just created in the conf folder followed by the steps of:

Next, create sentinel.conf, and above all create the same three. Proceed as follows:

       Followed by vim sentinel1.conf the like, in three sentinel1.conf, sentinel2.conf, sentinel3.conf which are added as follows:

sentinel monitor mymaster 172.17.0.2 6379 1
sentinel down-after-milliseconds mymaster 30000
sentinel parallel-syncs mymaster 1
sentinel failover-timeout mymaster 15000

# 和redis.conf中配置保持一致
protected-mode no

       vim editing content redis1.conf inside, three had redis editing documents, entering in the command line, the input / dir search, find the position in FIG., the default dir ./ modify dir / data from the command line. Then switch to the command line, search / protected-mode, find the protected-mode yes, the default is yes, modify the protected-mode no.

And when modifying redis2.conf redis3.conf accordance with the above configuration, another way to modify the operation, because the main redis1.conf as, redis2 and redis3 as from the need to configure the server. 172.17.0.2 ip is the main redis

    Next, we create these files are mapped, is mapped to the docker container of redis, I posted the following chart and point code map in the red box are the need to pay attention, because I was switched to / redis / conf / configured directory $ PWD need not change it, or to have the corresponding path.

[root@localhost conf]# docker run -p 7000:6379 --name redis1 -v $PWD/redis1.conf:/etc/redis/redis.conf -v $PWD/sentinel1.conf:/etc/redis/sentinel.conf -d redis:latest redis-server /etc/redis/redis.conf

[root@localhost conf]# docker run -p 7002:6379 --name redis2 -v $PWD/redis2.conf:/etc/redis/redis.conf -v $PWD/sentinel2.conf:/etc/redis/sentinel.conf -d redis:latest redis-server /etc/redis/redis.conf

[root@localhost conf]# docker run -p 7003:6379 --name redis3 -v $PWD/redis3.conf:/etc/redis/redis.conf -v $PWD/sentinel3.conf:/etc/redis/sentinel.conf -d redis:latest redis-server /etc/redis/redis.conf

    Once configured, you can view the information of the corresponding redis1 inspect redis1 by docker.

    Restart After the above three steps are completed container.

[root@localhost conf]# docker restart redis1
redis1
[root@localhost conf]# docker restart redis2
redis2
[root@localhost conf]# docker restart redis3
redis3

    After the restart to verify whether the three main container is correct from the relationship.


输入docker exec -it redis1 /bin/bash   
之后输入redis-cli
再接下来输入info,便能看到主从关系的信息

[root@localhost conf]# docker exec -it redis1 /bin/bash
root@adf0aab58403:/data# redis-cli
127.0.0.1:6379> info

        Can be seen from FIG role: master, represents the main server, connected_slaves: 2 there are two representatives from the connection, the next two lines represent their information. After reading through exit to exit, the same steps to see the other two are correct (Note: the display from server role: slave and its master server which master_host: 172.17.0.2).

      To ensure that our configuration is correct, we can verify, as shown writing to the main server, the server from read out from the inside.

       Then verify Sentinel mechanism configured above sentinel.conf sentry mechanism which has already been configured, so here only need to verify what you can. In order to facilitate connection to the server to verify four window open, switch to the next / redis / conf / directory, and then enter the following drawing command to start in the first window redis

      If you have the following graphics as well as the box information represents a normal start. Similarly the other two in the other two windows start command to the above figure corresponding to redis1 redis2 or redis3 can.

    We redis1 to turn off, there is no mechanism to verify sentry take effect in another window by docker stop redis1. After turn off the same input

[root@localhost ~]# docker exec -it redis2 /bin/bash
root@c8650f288777:/data# redis-cli
127.0.0.1:6379> info

    By the graph we can see redis1 primary server hang after, according to the Sentinel mechanisms to redis2 chosen as the primary server. Redis above step is to cluster configuration, and I hope you find these helpful.

Published 15 original articles · won praise 11 · views 2794

Guess you like

Origin blog.csdn.net/YCarlos/article/details/99675961