Skip to content

Commit

Permalink
更新文档
Browse files Browse the repository at this point in the history
  • Loading branch information
fangp committed Jun 7, 2018
1 parent 9269362 commit 840e80c
Show file tree
Hide file tree
Showing 14 changed files with 160 additions and 34 deletions.
129 changes: 125 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# spring-cloud-base
微服务基础框架,基于 SpringCloud 及 SpringBoot 开发。 使用 Oauth2 统一授权、认证, Oauth示例客户端使用 Vue 开发,具有用户管理、 资源管理、 角色管理等模块,后端包括授权中心、 基础数据中心(资源服务器)等应用,可作为微服务快速开发脚手架。 可通过 docker 快速构建部署。

Demo website:http://www.ityouknow.com/ username: xxx password: 123456
Demo website:http://112.74.60.248:8080/ username: test password: 123456


## Model
Expand All @@ -20,6 +20,127 @@ Demo website:http://www.ityouknow.com/ username: xxx password: 123456


## Quick Start
1. 开发环境搭建
2. 通过 docker-compose 快速启动
3. 通过共享镜像启动
### 项目结构
```
├─spring-cloud-base
│ │
│ ├─api-gateway--------------网关负载中心
│ │
│ ├─auth-center-----------------服务授权中心
│ │ ├─auth-center-api----------------授权中心公共模块
│ │ ├─auth-center-provider----------------授权中心服务端
│ │ ├─auth-spring-boot-autoconfigure----------------授权中心autoconfigure
│ │ └─auth-spring-boot-starter----------------授权中心starter模块
│ │
│ ├─common----------------通用脚手架
│ │
│ ├─config-git-----------------配置中心
│ │
│ ├─db-mybatis-pagehelper---------------Mybatis通用Mapper、分页模块
│ │ ├─db-spring-boot-autoconfigure----------------autoconfigure
│ │ ├─db-spring-boot-samples----------------db模块使用示例
│ │ └─db-spring-boot-starter----------------db starter
│ │
│ ├─docker-compose---------------docker-compose编排
│ │
│ ├─main-data--------------基础数据模块
│ │ ├─main-data-api----------------基础数据公共模块
│ │ ├─main-data-client----------------基础数据模块客户端
│ │ ├─main-data-provider----------------基础数据模块服务端
│ │
│ └─web-app--------------vue前端应用
```

### 依赖环境
JDK8、 Maven、 Mysql、 Redis、Consul(暂不支持0.7.3以上)、 Nodejs、 Docker(可选)、 docker-compose(可选)
### 运行步骤
1. Mysql导入数据: 运行main-data/schema.sql 文件
2. 更改 application配置文件(服务授权中心、网关负载中心、基础数据模块),jdbcUrl、 consul、 redis、 key-uri(服务授权中心公钥,资源服务器需配置)
3. 依此启动 mysql、 redis、 consul、 auth-center/auth-center-provider/AuthCenterProviderApplication.main(服务授权中心)、 api-gateway/ApiGatewayApplication.main()(网关负载中心)、 main-data/main-data-provider/MainDataApplication.main()(基础数据模块)、 web-app(前端vue项目)

### 通过 docker-compose 快速启动
1. 需要 docker-compose 环境,windows 可安装 DockerToolbox。
需先通过 Maven 插件 docker-maven-plugin 打包镜像,
```
<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>${docker.plugin.version}</version>
<configuration>
<imageName>${project.artifactId}</imageName>
<dockerDirectory>src/main/docker</dockerDirectory>
<resources>
<resource>
<targetPath>/</targetPath>
<directory>${project.build.directory}</directory>
<include>${project.build.finalName}.jar</include>
</resource>
</resources>
</configuration>
</plugin>
</plugins>
</build>
```

2. 分别构建 auth-center-provider、 main-data-provider、 api-gateway:
```
mvn clean
mvn package docker:build
```
构建 node-app:
```
cd /spring-cloud-base/web-app
docker build -t node-app .
```

3. 更改配置 docker-compose.yml:
```
node-app:
image: node-app
ports:
- '8080:8080'
depends_on:
- 'auth-center'
- 'api-gateway'
# 基础路径,授权时的redirectUrl,为 宿主机IP:本容器映射端口
- BASE_URL=http://192.168.99.100:8080
# 后台接口,对于网关
- SERVER_URL=http://192.168.99.100:18000
# 授权中心
- AUTH_URL=http://192.168.99.100:18001/auth
```

4. 运行
```
cd /spring-cloud-base/docker-compose
docker-compose up [-d]
```

### 通过共享镜像启动

## Preview
* 登陆页:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/login.png)

* 用户管理:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/user.png)

* 角色管理:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/role.png)

* 应用管理:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/client.png)

* 系统管理:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/system.png)

* 模块管理:
![avatar](https://github.com/fp2952/spring-cloud-base/tree/master/doc/module.png)

11 changes: 7 additions & 4 deletions api-gateway/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,20 @@
</dependencies>

<!-- 普通的maven打包方式 -->
<!--<build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>-->
</build>
<!-- 普通的maven打包方式 -->
<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->
<build>
<!--<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -81,6 +84,6 @@
</configuration>
</plugin>
</plugins>
</build>
</build>-->
<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->
</project>
8 changes: 2 additions & 6 deletions api-gateway/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
FROM frolvlad/alpine-oraclejdk8:slim
FROM livingobjects/jre8
VOLUME /tmp
ADD api-gateway-1.0-SNAPSHOT.jar app.jar
ADD wait-for-it.sh /wait-for-it.sh
#RUN bash -c 'touch /app.jar'
RUN bash -c 'touch /app.jar'
RUN chmod +x /wait-for-it.sh
# install bash
RUN apk update
RUN apk upgrade
RUN apk add --no-cache bash
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 18000
11 changes: 7 additions & 4 deletions auth-center/auth-center-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,18 +100,21 @@


<!-- 普通的maven打包方式 -->
<!--<build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>-->
</build>
<!-- 普通的maven打包方式 -->

<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->
<build>
<!--<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -134,7 +137,7 @@
</configuration>
</plugin>
</plugins>
</build>
</build>-->
<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->

</project>
8 changes: 2 additions & 6 deletions auth-center/auth-center-provider/src/main/docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
FROM frolvlad/alpine-oraclejdk8:slim
FROM livingobjects/jre8
VOLUME /tmp
ADD auth-center-provider-1.0-SNAPSHOT.jar app.jar
ADD wait-for-it.sh /wait-for-it.sh
#RUN bash -c 'touch /app.jar'
RUN bash -c 'touch /app.jar'
RUN chmod +x /wait-for-it.sh
# install bash
RUN apk update
RUN apk upgrade
RUN apk add --no-cache bash
ENTRYPOINT ["java","-Djava.security.egd=file:/dev/./urandom","-jar","/app.jar"]
EXPOSE 18001
Binary file added doc/client.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/login.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/module.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/role.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/system.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added doc/user.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 7 additions & 4 deletions main-data/main-data-provider/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,17 +79,20 @@
</dependencies>

<!-- 普通的maven打包方式 -->
<!--<build>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<executable>true</executable>
</configuration>
</plugin>
</plugins>
</build>-->
</build>
<!-- 普通的maven打包方式 -->
<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->
<build>
<!--<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
Expand All @@ -112,7 +115,7 @@
</configuration>
</plugin>
</plugins>
</build>
</build>-->
<!-- 结合docker的maven打包方式,并上传提交创建的镜像 -->

</project>
6 changes: 5 additions & 1 deletion web-app/src/config/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ export default {
// 设置后台请求地址前缀
Vue.axios.defaults.baseURL = process.env.SERVER_URL
Vue.prototype.$auth.config.baseUrl = process.env.BASE_URL
// Vue.prototype.$auth.config.authUrl = window.serverconf[process.env.NODE_ENV]['authUrl']
Vue.prototype.$auth.config.authUrl = process.env.AUTH_URL

// build后配置
// Vue.axios.defaults.baseURL = window.serverconf[process.env.NODE_ENV]['baseURL']
// Vue.prototype.$auth.config.baseUrl = window.serverconf[process.env.NODE_ENV]['baseUrl']
// Vue.prototype.$auth.config.authUrl = window.serverconf[process.env.NODE_ENV]['authUrl']

// 配置认证头
Vue.axios.defaults.headers.common['Authorization'] = 'Bearer ' + Vue.prototype.$auth.token()
// http 拦截器
Expand Down
10 changes: 5 additions & 5 deletions web-app/static/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@ window.serverconf = {
appId: 'test',
appSecret: 'test',
production: {
baseUrl: 'http://192.168.99.100:8080',
authUrl: 'http://192.168.99.100:21001/auth',
baseURL: 'http://192.168.99.100:21000'
baseUrl: 'http://112.74.60.248:8080/demo',
authUrl: 'http://112.74.60.248:18001/auth',
baseURL: 'http://112.74.60.248:18000'
},
development: {
baseUrl: 'http://127.0.0.1:8080',
authUrl: 'http://192.168.99.100:21001/auth',
baseURL: 'http://192.168.99.100:21000'
authUrl: 'http://192.168.99.100:18001/auth',
baseURL: 'http://192.168.99.100:18000'
}
}

0 comments on commit 840e80c

Please sign in to comment.