当前位置:网站首页> 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集群与部署微服务项目内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- 2022年性价比高的商业养老保险产品排名
- Service API version design and Practice
- 在宇宙的眼眸下,如何正确地关心东数西算?
- Problem solving: inittramfs unpacking failed:decoding failed
- Chaos engineering, learn about it
- Achieve scoring (Star scoring) effect through native JS
- How to set the website address for website construction can the website be put on record
- [tcapulusdb knowledge base] example of deleting data (TDR table)
- What is the was fortress server restart was command? What are the reasons why was could not be restarted?
- What are the steps required for TFTP to log in to the server through the fortress machine? Operation guide for novice
猜你喜欢

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

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

蚂蚁集团自研TEE技术通过国家级金融科技产品认证

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

为什么你的数据图谱分析图上只显示一个值?

PHPMailer 发送邮件 PHP

蚂蚁获FinQA竞赛冠军,在长文本数值推理AI技术上取得突破

In the eyes of the universe, how to correctly care about counting East and West?

Why is only one value displayed on your data graph?

Section 30 high availability (HA) configuration case of Tianrongxin topgate firewall
随机推荐
How to batch output EAN13 code to PDF
【技术干货】蚂蚁办公零信任的技术建设路线与特点
Flutter Utils
How to set the search bar of website construction and what should be paid attention to when designing the search box
Use elastic security to detect the vulnerability exploitation of cve-2021-44228 (log4j2)
MySQL highly available version 1c1g exclusive cloud database value-added special offers!
How to set secondary title in website construction what is the function of building a website
[tcapulusdb knowledge base] [generic table] read data interface description
How to use fortress remote server two types of Fortress
SQL Server common SQL
Industry 4.0 era: the rise of low code may bring about changes in the pattern of manufacturing industry
How to set up external links in website construction
Source code analysis of jmeter5.1 core class testcompiler
What is the difference between RosettaNet, EDI ANSI X12 and EDIFACT
FTP server setup setting website information can I set up FTP myself
The technical design and practice of decrypting the red envelopes of Tiktok Spring Festival
Slsa: accelerator for successful SBOM
应用实践 | Apache Doris 整合 Iceberg + Flink CDC 构建实时湖仓一体的联邦查询分析架构
蚂蚁获FinQA竞赛冠军,在长文本数值推理AI技术上取得突破
在宇宙的眼眸下,如何正确地关心东数西算?