一 编排的微服务列表
二 修改所有微服务application.yml属性
由于使用了microservice-discovery-eureka-ha,需要将所有微服务eureka.client.service-url.defaultZone内容修改为如下:
eureka:
client:
service-url:
defaultZone: http://peer1:8761/eureka/,http://peer2:8762/eureka/
三 将代码拷贝到Linux中
[root@master docker-3-complex]# ll
total 8
-rw-r--r-- 1 root root 756 Jul 8 15:06 docker-compose.yml
drwxr-xr-x 3 root root 30 Jul 8 15:06 microservice-consumer-movie-ribbon-hystrix
drwxr-xr-x 3 root root 30 Jul 8 15:06 microservice-discovery-eureka-ha
drwxr-xr-x 3 root root 30 Jul 8 15:06 microservice-gateway-zuul
drwxr-xr-x 3 root root 30 Jul 8 15:06 microservice-hystrix-turbine
drwxr-xr-x 3 root root 47 Jul 8 15:06 microservice-provider-user
-rw-r--r-- 1 root root 1512 Jul 8 15:06 pom.xml
四 在每个项目的根目录,执行以下命令构建Docker镜像
mvn clean package docker:build
[root@master microservice-provider-user]# docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
itmuch/microservice-provider-user 0.0.1-SNAPSHOT 96712f0e00b4 39 seconds ago 693MB
itmuch/microservice-hystrix-turbine 0.0.1-SNAPSHOT 026a20efaf28 44 seconds ago 683MB
itmuch/microservice-gateway-zuul 0.0.1-SNAPSHOT cdd3c39708f7 About a minute ago 682MB
itmuch/microservice-discovery-eureka-ha 0.0.1-SNAPSHOT bd9d658fad50 2 minutes ago 685MB
itmuch/microservice-consumer-movie-ribbon-hystrix 0.0.1-SNAPSHOT 365b209ff0e0 3 minutes ago 682MB
五 编写docker-compose.yml
version: "2"
services:
peer1:
image: itmuch/microservice-discovery-eureka-ha:0.0.1-SNAPSHOT
ports:
- "8761:8761"
environment:
- spring.profiles.active=peer1
peer2:
image: itmuch/microservice-discovery-eureka-ha:0.0.1-SNAPSHOT
hostname: peer2
ports:
- "8762:8762"
environment:
- spring.profiles.active=peer2
microservice-provider-user:
image: itmuch/microservice-provider-user:0.0.1-SNAPSHOT
microservice-consumer-movie-ribbon-hystrix:
image: itmuch/microservice-consumer-movie-ribbon-hystrix:0.0.1-SNAPSHOT
microservice-gateway-zuul:
image: itmuch/microservice-gateway-zuul:0.0.1-SNAPSHOT
microservice-hystrix-turbine:
image: itmuch/microservice-hystrix-turbine:0.0.1-SNAPSHOT
六 启动与测试
1 执行以下命令启动项目
[root@master microservice-provider-user]# docker-compose up
2 输入192.168.0.100:8761
3 执行以下命令,为各个微服务扩容
docker-compose scale microservice-provider-user=3 microservice-hystrix-turbine=3 microservice-gateway-zuul=3 microservice-consumer-movie-ribbon-hystrix=3
4 再次输入192.168.0.100:8761