当前位置:网站首页> 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集群与部署微服务项目内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- Go build command (go language compilation command) complete introduction
- Understand the data consistency between MySQL and redis
- Advantages of micro service registry Nacos over Eureka
- SQL Server Common SQL
- Targeted, real-time audio and video optimization in remote control
- 5 minutes to explain what is redis?
- sql server常用sql
- Talk about the problems and solutions of IT enterprise fixed assets management system
- AAAI 2022 | Tencent Youtu 14 papers were selected, including image coloring, face security, scene text recognition and other frontier fields
- [tcapulusdb knowledge base] insert data example (TDR table)
猜你喜欢

SLSA: 成功SBOM的促进剂

C#/VB.NET Word转Text

游戏安全丨喊话CALL分析-写代码

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

在宇宙的眼眸下,如何正确地关心东数西算?

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

解密抖音春节红包背后的技术设计与实践

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

PHPMailer 发送邮件 PHP

Ant group's self-developed tee technology has passed the national financial technology product certification
随机推荐
Ant group's self-developed tee technology has passed the national financial technology product certification
混沌工程,了解一下
0day1- (cve-2021-44228) log4j2 rce recurrence
SQL Server common SQL
Ranking of high cost performance commercial endowment insurance products in 2022
The technical design and practice of decrypting the red envelopes of Tiktok Spring Festival
Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse
Impala port
专业“搬砖”老司机总结的 12 条 SQL 优化方案,非常实用!
Six supervised learning methods: classification of poisonous mushrooms
Interviewer: the difference between uselayouteffect and useeffect
[tcapulusdb knowledge base] [generic table] read data interface description
How to use xshell to log in to the server through the fortress machine? How does the fortress machine configure the tunnel?
How to set the text style as PG in website construction
FTP server setup setting website information can I set up FTP myself
How to choose the server for website construction, including which servers and how much to rent
解密抖音春节红包背后的技术设计与实践
Grpc: quickly configure the general API to obtain process meta information
Implement sequence restriction on memory operations
How to batch output EAN13 code to PDF