当前位置:网站首页> Docker中部署Redis集群与部署微服务项目的详细过程
Docker中部署Redis集群与部署微服务项目的详细过程
2022-06-23 21:49:00 【1024问】
一、使用Docker部署的好处
二、Docker 与 Kubernetes 对比
三、Redis集群部署实战
四、Spring Boot项目 打包镜像
小结

Docker的好处在于:在不同实例上运行相同的容器
Docker的五大优点: 持续部署与测试、多云服务平台支持、环境标准化和版本控制、隔离、安全
Docker适用于较为小的应用,并发量不大的情况下、微服务为超过10个,建议适用Docker部署,这样也省资源、可减少开发成本。
K8S适用于大集群的情况,高并发,并且微服务超过了10个,同时性能也是非常好的,性能好的前提下,开发成本也增加了不少!
三、Redis集群部署实战下面部署如图所示三主三从的Redis集群

停掉所有的容器,删除全部记录
docker rm $(docker ps -a -q)创建自定义网络redis
docker network create redis --subnet 172.38.0.0/16
通过脚本创建六个redis的基本信息
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
启动6个redis容器,并进行数据挂载
# 通过脚本一次性启动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
进入redis-1中设置创建集群
# 进入redis-1docker exec -it redis-1 /bin/sh# 创建集群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
进入容器
redis-cli -c# 查看详细信息CLUSTER INFO
查看nodes
CLUSTER NODES
设置值
set k1 v1
我们可以看到,将值设置在了 13节点上,我们把该节点停止,再次获取值查看
# 新开窗口停止redis-3容器docker stop redis -3在原来窗口获取k1
# 需要重新进入再次获取get k1
可以看到,值已经同步到了其它节点,主节点挂掉后,我们照样可以拿到值!
四、Spring Boot项目 打包镜像创建一个SpringBoot项目
TestController
@RestControllerpublic class TestController { @GetMapping("/hello") public String hello() { return "Hello World!!!"; }}本地测试成功访问,然后编译项目为jar包
// 进入项目目录mvn clean package下载Docker镜像

编写Dockerfile
FROM java:8COPY *.jar /app.jarCMD ["--server.port=8080"]EXPOSE 8080ENTRYPOINT ["java", "-jar", "/app.jar"]将jar包和Dockerfile上传至服务器

服务器文件

编译Dockerfile
docker build -t xiaowang .
测试访问
curl localhost:49153
成功上传镜像!
小结以上就是【Bug 终结者】对 Docker实战 – 部署Redis集群与部署微服务项目 的简单介绍,使用Docker部署我们的应用很方便,快捷,但是架构庞大的话,就不建议使用Docker了,可以采用我们的k8s集群部署,是当下最流行的技术!
到此这篇关于Docker中部署Redis集群与部署微服务项目的文章就介绍到这了,更多相关Redis集群与部署微服务项目内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- What are the steps required for TFTP to log in to the server through the fortress machine? Operation guide for novice
- Performance test - LoadRunner obtains the return value and user-defined parameters (parameter operation)
- Interviewer: the difference between uselayouteffect and useeffect
- Talking about using email to attack social engineering
- Consequences of website construction without SSL authentication are websites without SSL authentication reliable
- SAP mm ml81n creates a service receipt for a purchase order and reports an error - no matching Po items selected-
- The article "essence" introduces you to VMware vSphere network, vswitch and port group!
- MySQL数据库配置信息查看与修改方法详解
- [tcapulusdb knowledge base] update data example (TDR table)
- Game security - call analysis - write code
猜你喜欢

Opengauss Developer Day 2022 was officially launched to build an open source database root community with developers

Why is only one value displayed on your data graph?

Save: software analysis, verification and test platform

Hackinglab penetration test question 8:key can't find it again

The technical design and practice of decrypting the red envelopes of Tiktok Spring Festival

為什麼你的數據圖譜分析圖上只顯示一個值?

Section 29 basic configuration case of Tianrongxin topgate firewall

【技术干货】蚂蚁办公零信任的技术建设路线与特点

Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse

蚂蚁获FinQA竞赛冠军,在长文本数值推理AI技术上取得突破
随机推荐
How to use FTP to upload websites to the web
What are the steps required for TFTP to log in to the server through the fortress machine? Operation guide for novice
How to set up external links in website construction
openGauss Developer Day 2022正式开启,与开发者共建开源数据库根社区
為什麼你的數據圖譜分析圖上只顯示一個值?
In the new easygbs kernel version, the intranet mapping to the public network cannot be played. How to troubleshoot?
Analysis and application of ThreadLocal source code
Detailed explanation of flutter exception capture
Detailed explanation of GC principle
Core features and technical implementation of FISCO bcos v3.0
How to batch output EAN13 code to PDF
Chaos engineering, learn about it
SQL Server common SQL
How to access the top-level domain name and automatically jump to the secondary domain name?
Low code technology
What should I do if the RDP fortress server connection times out? Why should enterprises use fortress machines?
Implement sequence restriction on memory operations
Consequences of website construction without SSL authentication are websites without SSL authentication reliable
Why don't people like PHP?
MySQL highly available version 1c1g exclusive cloud database value-added special offers!