添加docker容器化部署支持

This commit is contained in:
macro
2019-11-20 15:52:25 +08:00
parent 19eb63ac69
commit 2d5a69b926
22 changed files with 331 additions and 101 deletions

View File

@@ -24,7 +24,7 @@ mall
├── mall-common -- 工具类及通用代码模块
├── mall-mbg -- MyBatisGenerator生成的数据库操作代码模块
├── mall-security -- 封装SpringSecurity+JWT的安全认证的模块
├── mall-registery -- 基于Eureka的微服务注册中心
├── mall-registry -- 基于Eureka的微服务注册中心
├── mall-config -- 基于Spring Cloud Config的微服务配置中心
├── mall-gateway -- 基于Spring Cloud Gateway的微服务API网关服务
├── mall-monitor -- 基于Spring Boot Admin的微服务监控中心

View File

@@ -0,0 +1,84 @@
# mall-swarm 在Linux环境下的部署
## 部署mall-registry
```bash
docker run -p 8001:8001 --name mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-registry/logs:/var/logs \
-d mall/mall-registry:1.0-SNAPSHOT
```
## 部署mall-config
```bash
docker run -p 8301:8301 --name mall-config \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-config/logs:/var/logs \
-d mall/mall-config:1.0-SNAPSHOT
```
## 部署mall-monitor
```bash
docker run -p 8101:8101 --name mall-monitor \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-monitor/logs:/var/logs \
-d mall/mall-monitor:1.0-SNAPSHOT
```
## 部署mall-gateway
```bash
docker run -p 8201:8201 --name mall-gateway \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-gateway/logs:/var/logs \
-d mall/mall-gateway:1.0-SNAPSHOT
```
## 部署mall-admin
```bash
docker run -p 8180:8180 --name mall-admin \
--link mysql:db \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-admin/logs:/var/logs \
-d mall/mall-admin:1.0-SNAPSHOT
```
## 部署mall-portal
```bash
docker run -p 8180:8180 --name mall-portal \
--link mysql:db \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-portal/logs:/var/logs \
-d mall/mall-portal:1.0-SNAPSHOT
```
## 部署mall-search
```bash
docker run -p 8180:8180 --name mall-search \
--link mysql:db \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-search/logs:/var/logs \
-d mall/mall-search:1.0-SNAPSHOT
```
## 部署mall-demo
```bash
docker run -p 8082:8082 --name mall-demo \
--link mysql:db \
--link mall-registry:mall-registry \
-v /etc/localtime:/etc/localtime \
-v /mydata/app/mall-demo/logs:/var/logs \
-d mall/mall-demo:1.0-SNAPSHOT
```

View File

@@ -14,7 +14,6 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<skipTests>true</skipTests>
</properties>
<parent>
@@ -55,33 +54,33 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--<plugin>-->
<!--<groupId>com.spotify</groupId>-->
<!--<artifactId>docker-maven-plugin</artifactId>-->
<!--<version>1.1.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>build-image</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>build</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<imageName>mall/${project.artifactId}:${project.version}</imageName>-->
<!--<dockerHost>http://192.168.3.101:2375</dockerHost>-->
<!--<baseImage>java:8</baseImage>-->
<!--<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>-->
<!--<resources>-->
<!--<resource>-->
<!--<targetPath>/</targetPath>-->
<!--<directory>${project.build.directory}</directory>-->
<!--<include>${project.build.finalName}.jar</include>-->
<!--</resource>-->
<!--</resources>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -10,4 +10,6 @@ spring:
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
defaultZone: http://mall-registry:8001/eureka/
instance:
prefer-ip-address: true

View File

@@ -5,7 +5,7 @@
<groupId>com.macro.mall</groupId>
<artifactId>mall-config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<name>mall-config</name>
<description>mall-config project for mall</description>
@@ -32,6 +32,33 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -0,0 +1,4 @@
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/

View File

@@ -0,0 +1,4 @@
eureka:
client:
service-url:
defaultZone: http://mall-registry:8001/eureka/

View File

@@ -16,7 +16,3 @@ spring:
password: 123456
clone-on-start: true
search-paths: '{application}'
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/

View File

@@ -50,8 +50,34 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -10,4 +10,6 @@ spring:
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
defaultZone: http://mall-registry:8001/eureka/
instance:
prefer-ip-address: true

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.macro.mall</groupId>
<artifactId>mall-gateway</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<name>mall-gateway</name>
<description>mall-gateway project for mall</description>
@@ -31,6 +31,33 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -0,0 +1,5 @@
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
registry-fetch-interval-seconds: 10

View File

@@ -0,0 +1,7 @@
eureka:
client:
service-url:
defaultZone: http://mall-registry:8001/eureka/
registry-fetch-interval-seconds: 10
instance:
prefer-ip-address: true

View File

@@ -9,11 +9,6 @@ spring:
locator:
enabled: true
lower-case-service-id: true #使用小写service-id
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
registry-fetch-interval-seconds: 10
management: #开启SpringBoot Admin的监控
endpoints:
web:

View File

@@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.macro.mall</groupId>
<artifactId>mall-monitor</artifactId>
<version>0.0.1-SNAPSHOT</version>
<version>1.0-SNAPSHOT</version>
<name>mall-monitor</name>
<description>mall-monitor project for mall</description>

View File

@@ -0,0 +1,4 @@
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/

View File

@@ -0,0 +1,6 @@
eureka:
client:
service-url:
defaultZone: http://mall-registry:8001/eureka/
instance:
prefer-ip-address: true

View File

@@ -64,35 +64,34 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--<plugin>-->
<!--<groupId>com.spotify</groupId>-->
<!--<artifactId>docker-maven-plugin</artifactId>-->
<!--<version>1.1.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>build-image</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>build</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<imageName>mall/${project.artifactId}:${project.version}</imageName>-->
<!--<dockerHost>http://192.168.3.101:2375</dockerHost>-->
<!--<baseImage>java:8</baseImage>-->
<!--<entryPoint>["java", "-jar","-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>-->
<!--<resources>-->
<!--<resource>-->
<!--<targetPath>/</targetPath>-->
<!--<directory>${project.build.directory}</directory>-->
<!--<include>${project.build.finalName}.jar</include>-->
<!--</resource>-->
<!--</resources>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
</project>

View File

@@ -10,4 +10,6 @@ spring:
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
defaultZone: http://mall-registry:8001/eureka/
instance:
prefer-ip-address: true

View File

@@ -53,33 +53,33 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<!--<plugin>-->
<!--<groupId>com.spotify</groupId>-->
<!--<artifactId>docker-maven-plugin</artifactId>-->
<!--<version>1.1.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>build-image</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>build</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<imageName>mall/${project.artifactId}:${project.version}</imageName>-->
<!--<dockerHost>http://192.168.3.101:2375</dockerHost>-->
<!--<baseImage>java:8</baseImage>-->
<!--<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>-->
<!--<resources>-->
<!--<resource>-->
<!--<targetPath>/</targetPath>-->
<!--<directory>${project.build.directory}</directory>-->
<!--<include>${project.build.finalName}.jar</include>-->
<!--</resource>-->
<!--</resources>-->
<!--</configuration>-->
<!--</plugin>-->
<plugin>
<groupId>com.spotify</groupId>
<artifactId>docker-maven-plugin</artifactId>
<version>1.1.0</version>
<executions>
<execution>
<id>build-image</id>
<phase>package</phase>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<imageName>mall/${project.artifactId}:${project.version}</imageName>
<dockerHost>${docker.host}</dockerHost>
<baseImage>java:8</baseImage>
<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]</entryPoint>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>

View File

@@ -10,4 +10,6 @@ spring:
eureka:
client:
service-url:
defaultZone: http://localhost:8001/eureka/
defaultZone: http://mall-registry:8001/eureka/
instance:
prefer-ip-address: true

39
pom.xml
View File

@@ -31,6 +31,8 @@
</parent>
<properties>
<skipTests>true</skipTests>
<docker.host>http://192.168.6.132:2375</docker.host>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
<pagehelper-starter.version>1.2.10</pagehelper-starter.version>
@@ -181,4 +183,41 @@
</dependencies>
</dependencyManagement>
<!--<build>-->
<!--<plugins>-->
<!--<plugin>-->
<!--<groupId>org.springframework.boot</groupId>-->
<!--<artifactId>spring-boot-maven-plugin</artifactId>-->
<!--</plugin>-->
<!--<plugin>-->
<!--<groupId>com.spotify</groupId>-->
<!--<artifactId>docker-maven-plugin</artifactId>-->
<!--<version>1.1.0</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<id>build-image</id>-->
<!--<phase>package</phase>-->
<!--<goals>-->
<!--<goal>build</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--<configuration>-->
<!--<imageName>mall/${project.artifactId}:${project.version}</imageName>-->
<!--<dockerHost>http://192.168.6.132:2375</dockerHost>-->
<!--<baseImage>java:8</baseImage>-->
<!--<entryPoint>["java", "-jar", "-Dspring.profiles.active=prod","/${project.build.finalName}.jar"]-->
<!--</entryPoint>-->
<!--<resources>-->
<!--<resource>-->
<!--<targetPath>/</targetPath>-->
<!--<directory>${project.build.directory}</directory>-->
<!--<include>${project.build.finalName}.jar</include>-->
<!--</resource>-->
<!--</resources>-->
<!--</configuration>-->
<!--</plugin>-->
<!--</plugins>-->
<!--</build>-->
</project>