当前位置:网站首页> 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集群与部署微服务项目内容请搜索软件开发网以前的文章或继续浏览下面的相关文章希望大家以后多多支持软件开发网!
边栏推荐
- In the new easygbs kernel version, the intranet mapping to the public network cannot be played. How to troubleshoot?
- Understand the data consistency between MySQL and redis
- Service API version design and Practice
- In the eyes of the universe, how to correctly care about counting East and West?
- What should be done when the encryptor fails to authenticate in the new version of easycvr?
- This article takes you to understand the JVM class loading mechanism
- [tcapulusdb knowledge base] example of deleting data (TDR table)
- Intelligent storage | high speed HD media processing capability
- [tcapulusdb knowledge base] [generic table] read data interface description
- How to lossless publish API gateway why do you need API gateway?
猜你喜欢

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

Game security - call analysis - write code

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

Slsa: accelerator for successful SBOM

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

Ant won the finqa competition champion and made a breakthrough in AI technology of long text numerical reasoning

Ant group's self-developed tee technology has passed the national financial technology product certification

Section 29 basic configuration case of Tianrongxin topgate firewall

Chaos engineering, learn about it
![[technical dry goods] the technical construction route and characteristics of zero trust in ant Office](/img/d1/ce999b9f72bbb8f692c4298b4042aa.png)
[technical dry goods] the technical construction route and characteristics of zero trust in ant Office
随机推荐
The technical design and practice of decrypting the red envelopes of Tiktok Spring Festival
How to set secondary title in website construction what is the function of secondary title
游戏安全丨喊话CALL分析-写代码
API gateway monitoring function the importance of API gateway
Slsa: accelerator for successful SBOM
Error message - Customizing incorrectly maintained – in transaction code ML81N
[tcapulusdb knowledge base] reading data example (TDR table)
What are the application flow restrictions of API gateway framework?
為什麼你的數據圖譜分析圖上只顯示一個值?
Application practice | Apache Doris integrates iceberg + Flink CDC to build a real-time federated query and analysis architecture integrating lake and warehouse
Six supervised learning methods: classification of poisonous mushrooms
Is the website under construction because there is no FTP upload? Can I upload without FTP
Dlib detects 68 facial features, and uses sklearn to train a facial smile recognition model based on SVM
How to lossless publish API gateway why do you need API gateway?
Grpc: quickly configure the general API to obtain process meta information
How to set up a website construction map
Tcapulusdb Jun · industry news collection
What server is used for website construction? What is the price of the server
How to set dynamic background for website construction what are the benefits of dynamic background
Detailed explanation of flutter exception capture