docker-compose 完整打包发布, 多服务,多节点SPRING CLOUD ,EUREKA 集群
这里不再使用 端口映射的方式,因为不同主机上,Feign 根据 docker hostname访问会有问题.
把打包的好jar copy到docker镜像里
有几个服务,就复制几个dockerfile
Dockerfile
FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144 #
MAINTAINER zhenweilai <181282945@qq.com> COPY jar /usr/local RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && \
echo 'Asia/Shanghai' >/etc/timezone
开启两个eureka,互相注册
开启两个api服务,
开启两个app服务.
开启一个zuul路由服务
docker-compose
version: '2'
services:
eureka_master:
build: eurekaserver
network_mode: "host"
command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka1 --eureka.instance.other-hostname=eureka2 --server.port=8000 --eureka.instance.other-port=8001
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always eureka_backup:
build: eurekaserver
network_mode: "host"
command: java -jar /usr/local/eurekaserver.jar --spring.profiles.active=test --eureka.instance.hostname=eureka2 --eureka.instance.other-hostname=eureka1 --server.port=8001 --eureka.instance.other-port=8000
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always api_8070:
build: api
network_mode: "host"
command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8070
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always api_8071:
build: api
network_mode: "host"
command: java -jar /usr/local/api.jar --spring.profiles.active=test --server.port=8071
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always router:
build: router
network_mode: "host"
command: java -jar /usr/local/router.jar --spring.profiles.active=test --server.port=8088
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always app_8060:
build: app
network_mode: "host"
command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8060
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always app_8080:
build: app
network_mode: "host"
command: java -jar /usr/local/app.jar --spring.profiles.active=test --server.port=8080
depends_on:
- eureka_master
- eureka_backup
volumes:
- /usr/local/microservice/log:/usr/local/microservice/log
restart: always
应用application.yml,注册到两个eureka
eureka:
instance:
appname: app
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
#续约更新时间间隔
lease-renewal-interval-in-seconds: 10
#续约到期时间
lease-expiration-duration-in-seconds: 30
client:
serviceUrl:
defaultZone: http://username:password@eureka1:8000/eureka/,http://username:password@eureka2:8001/eureka/
eureka application.yml
eureka:
instance:
hostname: localhost
other-port: 8001
other-hostname: backup
appname: eureka-server
instance-id: ${spring.cloud.client.ipAddress}:${server.port}
lease-expiration-duration-in-seconds: 5
server:
#5秒清理一次
eviction-interval-timer-in-ms: 5
client:
register-with-eureka: true
fetch-registry: true
service-url:
defaultZone: http://username:password@${eureka.instance.other-hostname}:${eureka.instance.other-port}/eureka/
输入命令:docker-compose up --build -d
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> 7a1be0756dca
Removing intermediate container 5c45807bbc81
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Running in e8988ea8a1f8
---> ad26f883175e
Removing intermediate container e8988ea8a1f8
Successfully built ad26f883175e
Successfully tagged microservice_eureka_backup:latest
Building eureka_master
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 7a1be0756dca
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> ad26f883175e
Successfully built ad26f883175e
Successfully tagged microservice_eureka_master:latest
Building cloudinvoice_8080
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> b9fe90218b85
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 709a728e383a
Successfully built 709a728e383a
Successfully tagged microservice_cloudinvoice_8080:latest
Building cloudinvoice_8060
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> b9fe90218b85
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 709a728e383a
Successfully built 709a728e383a
Successfully tagged microservice_cloudinvoice_8060:latest
Building api_8070
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 5b85563136e5
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 679564f7d414
Successfully built 679564f7d414
Successfully tagged microservice_api_8070:latest
Building api_8071
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> 5b85563136e5
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 679564f7d414
Successfully built 679564f7d414
Successfully tagged microservice_api_8071:latest
Building router
Step 1/4 : FROM registry.cn-hangzhou.aliyuncs.com/laizhenwei/jre:8u144
---> 1b97d252ae81
Step 2/4 : MAINTAINER zhenweilai <@qq.com>
---> Using cache
---> bf31044329be
Step 3/4 : COPY jar /usr/local
---> Using cache
---> c88e35c7fc38
Step 4/4 : RUN cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' >/etc/timezone
---> Using cache
---> 288ce24cfef0
Successfully built 288ce24cfef0
Successfully tagged microservice_router:latest
Recreating microservice_eureka_master_1 ...
Recreating microservice_eureka_backup_1 ...
Recreating microservice_eureka_master_1
Recreating microservice_eureka_backup_1 ... done
Recreating microservice_app_8060_1 ...
Recreating microservice_api_8070_1 ...
Recreating microservice_api_8070_1
Recreating microservice_router_1 ...
Recreating microservice_api_8071_1 ...
Recreating microservice_cloudinvoice_8060_1
Recreating microservice_api_8071_1
Recreating microservice_app_8080_1 ...
Recreating microservice_router_1
Recreating microservice_app_8080_1 ... done
docker-compose ps
Name Command State Ports
---------------------------------------------------------------------------------
microservice_api_8070_1 java -jar /usr/local/api ... Up
microservice_api_8071_1 java -jar /usr/local/api ... Up
microservice_app_8060_1 java -jar /usr/local/app ... Up
microservice_app_8080_1 java -jar /usr/local/app... Up
microservice_eureka_backup_1 java -jar /usr/local/eurek ... Up
microservice_eureka_master_1 java -jar /usr/local/eurek ... Up
microservice_router_1 java -jar /usr/local/route ... Up
192.168.51.60:8000
docker-compose 完整打包发布, 多服务,多节点SPRING CLOUD ,EUREKA 集群的更多相关文章
- Spring Cloud微服务笔记(三)服务治理:Spring Cloud Eureka快速入门
服务治理:Spring Cloud Eureka 一.服务治理 服务治理是微服务架构中最为核心和基础的模块,它主要用来实现各个微服务实例的自动化注册与发现. 1.服务注册: 在服务治理框架中,通常会构 ...
- Docker Compose搭建Redis一主二从三哨兵高可用集群
一.Docker Compose介绍 https://docs.docker.com/compose/ Docker官方的网站是这样介绍Docker Compose的: Compose是用于定义和运行 ...
- spring cloud深入学习(二)-----服务注册中心spring cloud eureka
服务治理 主要用来实现各个微服务实例的自动化注册与发现,为啥需要这玩意呢?在一开始比如A系统调用B服务,可能通过手工维护B服务的实例,并且还得采用负载均衡等方式,这些全部都得需要手工维护,等后面系统越 ...
- 第三章 服务治理:Spring Cloud Eureka
Spring Cloud Eureka是Spring Cloud Netflix 微服务套件中的一部分,它基于Netflix Eureka做了二次封装,主要负责完成微服务架构中的服务治理功能.Spri ...
- 微服务架构之spring cloud eureka
Spring Cloud Eureka是spring cloud的核心组件,负责服务治理功能,起到中心枢纽作用,其它组件都依赖eureka来获取服务,然后再根据项目需求实现自己的业务,eureka在整 ...
- 第三章 服务治理: Spring Cloud Eureka
Spring Cloud Eureka是 Spring Cloud Netflix微服务套件中的一部分,它基于Netflix Eureka做了二次封装,主要负责完成微服务架构中的服务治理功能 服务治理 ...
- 服务治理:Spring Cloud Eureka
Spring Cloud Eureka主要负责完成微服务架构中服务治理功能. 服务治理是微服务架构中最为核心和基础模块,主要用来实现各个微服务实例的自动注册和发现. 服务注册 微服务实例启动后向注册中 ...
- 微服务架构集大成者—Spring Cloud (转载)
软件是有生命的,你做出来的架构决定了这个软件它这一生是坎坷还是幸福. 本文不是讲解如何使用Spring Cloud的教程,而是探讨Spring Cloud是什么,以及它诞生的背景和意义. 1 背景 2 ...
- 主流微服务一站式解决方案Spring Cloud Alibaba入门看这篇就足够了
学习路线 **本人博客网站 **IT小神 www.itxiaoshen.com 生态概述 架构演进 什么是微服务 https://martinfowler.com/microservices/ Mic ...
随机推荐
- 苹果系统css样式变化
原因:苹果自带样式覆盖了 参考文章比较详细,就不自己写了,copy了一份~~~ @参考文章 只要在样式里面加一句去掉css去掉iPhone.iPad的默认按钮样式就可以了!~ input[type=& ...
- 转-Determining whether a Computer Needs to be Rebooted
1 如何检查机器是否因为装了Windows更新而需要重新启动 2 Determining whether a Computer Needs to be Rebooted 3 How can I tel ...
- 用Python实现几种排序算法
#coding=utf-8 # 1 快速排序算法 def qksort(list): if len(list)<=1: return list else: pivot = list[0] les ...
- j2e中操作EXCEL
在j2e中操作excel,无非2种情况,在这里我贴部分代码做个例子就OK,不管是导入和导出都是操作的都是流 1,导入,浏览器输入EXCEL到java后台解析 package action; impor ...
- MongoDB投影有$slice如何只显示该字段
简单的投影 稍微用过MongoDB的都知道,投影很简单,就直接 db.student.find({_id:ObjectId('5a5085aed8f10c1a6cc0395b')},{comments ...
- PHP实现QQ登录的开发教程
第三方登录,就是使用大家比较熟悉的比如QQ.微信.微博等第三方软件登录自己的网站,这可以免去注册账号.快速留住用户的目的,免去了相对复杂的注册流程.下边就给大家讲一下怎么使用PHP开发QQ登录的功能. ...
- 为mysql数据库建立索引
前些时候,一位颇高级的程序员居然问我什么叫做索引,令我感到十分的惊奇,我想这绝不会是沧海一粟,因为有成千上万的开发者(可能大部分是使用MySQL的)都没有受过有关数据库的正规培训,尽管他们都为客户做过 ...
- HTTP基本知识
1.TCP/IP 传输控制协议/因特网互联协议 (1)应用层:决定向用户提供应用服务时通信的活动(FTP.DNS和HTTP都属于该层). (2)传输层:提供处于网络连接中的两台计算机之间的数据传输(T ...
- BSGS(Baby Steps,Giant Steps)算法详解
BSGS(Baby Steps,Giant Steps)算法详解 简介: 此算法用于求解 Ax≡B(mod C): 由费马小定理可知: x可以在O(C)的时间内求解: 在x=c之后又会循环: 而BS ...
- cmd中控制某个命令执行多少次
for /l %i in (1,1,5) do calc五次启动计算器程序for /l %i in (start ,step,end) do commandfor /l 表示从数字start开始,以s ...