当前位置:网站首页>Detailed process of deploying redis cluster and micro service project in docker

Detailed process of deploying redis cluster and micro service project in docker

2022-06-23 22:52:00 1024 Q

Catalog

One 、 Use Docker The benefits of deployment

Two 、Docker And Kubernetes contrast

3、 ... and 、Redis Cluster deployment practice

Four 、Spring Boot project Packaging mirroring

Summary

One 、 Use Docker The benefits of deployment

Docker Is that : Run the same container on different instances

Docker The five advantages of : Continuous deployment and testing The multi cloud service platform supports Environmental standardization and version control Isolation Security

Two 、Docker And Kubernetes contrast

Docker Suitable for smaller applications , When the amount of concurrency is small 、 Microservices are more than 10 individual , It is recommended that Docker Deploy , such Also save resources 、 Reduce development costs .

K8S It is suitable for large clusters , High concurrency , And microservices surpass 10 individual , At the same time, the performance is also very good , On the premise of good performance , The development cost has also increased a lot

3、 ... and 、Redis Cluster deployment practice

Next, deploy the three master and three slave as shown in the figure Redis colony

Stop all containers , Delete all records

docker rm $(docker ps -a -q)

Create a custom network redis

docker network create redis --subnet 172.38.0.0/16

Create six by script redis Basic information of

for port in $(seq 1 6); \do \mkdir -p /mydata/redis/node-${port}/conftouch /mydata/redis/node-${port}/conf/redis.confcat << EOF >/mydata/redis/node-${port}/conf/redis.confport 6379 bind 0.0.0.0cluster-enabled yes cluster-config-file nodes.confcluster-node-timeout 5000cluster-announce-ip 172.38.0.1${port}cluster-announce-port 6379cluster-announce-bus-port 16379appendonly yesEOFdone

start-up 6 individual redis Containers , And mount the data

# Start at one time by script for port in $(seq 1 6); \dodocker run -p 637${port}:6379 -p 1637${port}:16379 --name redis-${port} \-v /mydata/redis/node-${port}/data:/data \-v /mydata/redis/node-${port}/conf/redis.conf:/etc/redis/redis.conf \-d --net redis --ip 172.38.0.1${port} redis:5.0.9-alpine3.11 redis-server /etc/redis/redis.conf; \done

Get into redis-1 Set the create cluster in

# Get into redis-1docker exec -it redis-1 /bin/sh# Create clusters redis-cli --cluster create 172.38.0.11:6379 172.38.0.12:6379 172.38.0.13:6379 172.38.0.14:6379 172.38.0.15:6379 172.38.0.16:6379 --cluster-replicas 1

Into the container

redis-cli -c# View details CLUSTER INFO

see nodes

CLUSTER NODES

Set the value

set k1 v1

We can see , Set the value to 13 Node , We stop the node , Get the value again to see

# New windows stop redis-3 Containers docker stop redis -3

Get in the original window k1

# You need to re-enter and get again get k1

You can see , Values have been synchronized to other nodes , After the master node hangs up , We can still get the value !

Four 、Spring Boot project Packaging mirroring

Create a SpringBoot project

TestController

@RestControllerpublic class TestController { @GetMapping("/hello") public String hello() { return "Hello World!!!"; }}

Local test successfully accessed , Then compile the project as jar package

// Enter project directory mvn clean package

download Docker Mirror image

To write Dockerfile

FROM java:8COPY *.jar /app.jarCMD ["--server.port=8080"]EXPOSE 8080ENTRYPOINT ["java", "-jar", "/app.jar"]

take jar Bao He Dockerfile Upload to server

Server files

compile Dockerfile

docker build -t xiaowang .

Test access

curl localhost:49153

Successfully uploaded the image !

Summary

That's all 【Bug The terminator 】 Yes Docker actual combat – Deploy Redis Cluster and deploy microservice projects A brief introduction , Use Docker It is very convenient to deploy our application , quick , But if the architecture is huge , Not recommended Docker 了 , We can use our k8s Cluster deployment , It is the most popular technology nowadays !

This is about Docker Deployment in China Redis This is the end of the article on clustering and deploying microservices , More about Redis Please search the previous articles of SDN or continue to browse the following related articles. I hope you will support SDN more in the future !


原网站

版权声明
本文为[1024 Q]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/174/202206231844424262.html