Docker Configuration of redis Sentinel Mode on of Multiple Servers
- 2021-10-11 20:06:06
- OfStack
Preface
The redis1 you learned earlier runs on a single 1 server and is deployed directly on the server. I heard that using docker will make the configuration process easier (it doesn't). This time, configure Redis1 Master 1 Slave 3 Sentinel on the basis of using Docker. This article is to configure data nodes, that is, 1 master and 1 slave nodes.
Condition
3 servers (because at least 3 sentinels are required for security) "can be rented on Alibaba Cloud for several hours"
Server 1: 8.131. 78.18 Server 2: 8.131. 69.106 Server 3: 8.131. 71.196 Port numbers 7000, 17000 have been released on the security group (Alibaba Cloud) Environment: centos8.0
Installing Docker
Execute the following instructions line by line:
# 1. Update the compilation environment
yum -y install gcc
# 2. Ibid.
yum -y install gcc-c++
# 3. Installation docker
# 3.1 Uninstall the old version
yum remove docker \
docker-client \
docker-client-latest \
docker-common \
docker-latest \
docker-latest-logrotate \
docker-logrotate \
docker-engine
# 3.2 Installation package required for installation
yum install -y yum-utils
# 3.3 Set up the mirror warehouse, it is recommended to use the domestic mirror, which is faster
yum-config-manager \
--add-repo \
https://mirrors.aliyun.com/docker-ce/linux/centos/docker-ce.repo
# 3.4 Update yum Package index, which can cache packages locally 1 Portions
yum makecache
# 3.5 Installation docker Relative docker-ce Community edition
yum install -y https://mirrors.aliyun.com/docker-ce/linux/centos/7/x86_64/edge/Packages/containerd.io-1.2.13-3.1.el7.x86_64.rpm
# 3.6 Installation
yum install docker-ce docker-ce-cli containerd.io
# 3.7 Start docker
systemctl start docker
# 3.8 Set to background startup
systemctl enable docker
# 3.9 Use docker version Check to see if you follow the success
docker version
# 3.10 Test (you can not do it)
docker run hello-world
# 3.11 Uninstall and delete (for reference only, not this time)
yum remove docker-ce docker-ce-cli containerd.io
rm -rf /var/lib/docker
# 4. Configure accelerator
sudo mkdir -p /etc/docker
sudo tee /etc/docker/daemon.json <<-'EOF'
{
"registry-mirrors": ["https://qdxc3615.mirror.aliyuncs.com"]
}
EOF
sudo systemctl daemon-reload
sudo systemctl restart docker
Configuring redis Master and Slave Nodes
The servers we use are Server 1 and Server 3 (originally 1 master and 2 slave, I turned off Server 2).
TIPS: For xshell, you can use the right-click to select the send key to enter to all sessions, so you don't need to configure it twice. Or use the scp statement to share the configured files with other servers:
# scp local_file remote_username@remote_ip:remote_folder
scp redis.conf root@58.131.71.196:/blue/redis02
1. Create the folder first, be careful not to put it under the home path, otherwise it is easy for the container to fail because of permission problems. The directory I created is/blue/redis02, and the instructions are relatively simple:
cd /
mkdir blue && cd blue
mkdir redis02 && cd redis02
2. Dockerfile and Dockerfile were created to load the environment we needed.
vi Dockerfile
# Dockerfile The contents are as follows:
# Mirroring from the base redis Inheritance
FROM redis
MAINTAINER blue<blue@email.com>
# Will Dockerfile Copy the files in the directory to the container /usr/local/etc/redis Directory
COPY redis.conf /usr/local/etc/redis/redis.conf
# Installation 1 Some environment
RUN apt-get update
RUN apt-get install -y vim
RUN apt-get install procps --assume-yes
VOLUME ["/data"]
WORKDIR /etc/redis
# Open port 7000
EXPOSE 7000
# Startup using a configuration file
CMD [ "redis-server", "/usr/local/etc/redis/redis.conf"]
3. Download one redis. conf from the official website and make the following modifications. redis. conf is one configuration of redis, which is basically the same as the configuration of redis1 master 1 slave 3 sentinel of stand-alone machine.
# Comment out bind 127.0.0.1
# bind 127.0.0.1
port 7000
# If it is here, yes Will affect startup using configuration files
daemonize no
pidfile /var/run/redis_7000.pid
# You need to set the following two passwords, and the passwords should be 1 To
requirepass testmaster123
masterauth testmaster123
# Modify the protection mode, if it is yes Causes the external server to be inaccessible
protected-mode no
# For servers 3 , also need to add 1 Sentence , Indicates that it is a server 1 Slave server of
# slaveof Lord . Machine .I.P Port
slaveof 8.131.78.18 7000
4. After saving the above configuration, you can use the following statement to create an image. This process takes a long time and needs patience:
# Should be used docker build -t myredis . It is more recognizable, but it was successful as a test, and I don't want to modify it. This sentence is based on our Dockerfile Create 1 A new mirror image. You can put him push Go to the warehouse so that you can pull it directly next time.
docker build -t test .
5. Start the container with the following statement:
# Startup container
docker run -d -p 7000:7000 --name redis-test test
# The following statement looks at the container in operation
docker ps
# Enter the container
docker exec -it redis-test /bin/bash
6. Inside the container, you can view running threads using the following statement:
# View running threads
ps -ef
# Use redis Client access 7000 Port
redis-cli -p 7000
# Enter password
auth testmaster123
# View information
info replication
# The following is the information returned from the node
# Replication
role:slave
master_host:8.131.78.18
master_port:7000
master_link_status:up
master_last_io_seconds_ago:10
master_sync_in_progress:0
slave_repl_offset:28
slave_priority:100
slave_read_only:1
connected_slaves:0
master_replid:438c700922a30ebbc66ee5c89a176c426924b2a7
master_replid2:0000000000000000000000000000000000000000
master_repl_offset:28
second_repl_offset:-1
repl_backlog_active:1
repl_backlog_size:1048576
repl_backlog_first_byte_offset:1
repl_backlog_histlen:28
At this point, the master and slave nodes are successfully configured.