Commit 4fa72a58 by tangyi

调整部署文档

parent 2f3b9c16
......@@ -4,15 +4,17 @@
## 简介
重写[spring-cloud-online-exam](https://gitee.com/wells2333/spring-cloud-online-exam)
- 重写[spring-cloud-online-exam](https://gitee.com/wells2333/spring-cloud-online-exam)
采用前后端分离技术
- 采用前后端分离技术
前端采用`vue2.0`,通过`jwt`和后端交互
- 前端采用`vue2.0`,通过`jwt`和后端交互
后端基于`spring boot``spring cloud``MySQL`等技术实现权限管理、考试管理等功能。
- 后端基于`spring boot``spring cloud``MySQL`等技术实现权限管理、考试管理等功能。
访问地址:[在线体验](http://182.254.233.125)(服务器资源有限,只部署了前端页面)
- [在线体验-前台](http://www.it99.club)
- [在线体验-后台](http://www.it99.club:81)
## 技术选型
......@@ -118,19 +120,21 @@
## 问题反馈
欢迎提交 issue,请写清楚遇到问题的原因,浏览器和操作系统环境,重现的流程
欢迎提交 issue,请写清楚遇到问题的原因、浏览器、操作系统环境、重现的流程和报错日志等
如果有开发能力,建议在本地调试出出错的代码。
## 参考资料
[在线考试系统V2.0部署文档](doc/在线考试系统V2.0_部署文档.md)
- [在线考试系统V2.0部署文档](doc/在线考试系统V2.0_部署文档.md)
- [在线考试系统V2.0部署文档(docker版)](doc/在线考试系统V2.0_部署文档(docker版).md)
[在线考试系统V2.0部署文档(docker版)](doc/在线考试系统V2.0_部署文档(docker版).md)
- [在线考试系统V2.0项目结构说明文档](doc/在线考试系统V2.0_项目结构说明.md)
[在线考试系统V2.0项目结构说明文档](doc/在线考试系统V2.0_项目结构说明.md)
- [微服务架构下的安全设计方案](http://ehedgehog.net/2019/03/23/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84%E5%AE%89%E5%85%A8%E8%AE%BE%E8%AE%A1%E6%96%B9%E6%A1%88/)
[微服务架构下的安全设计方案](http://ehedgehog.net/2019/03/23/%E5%BE%AE%E6%9C%8D%E5%8A%A1%E6%9E%B6%E6%9E%84%E4%B8%8B%E7%9A%84%E5%AE%89%E5%85%A8%E8%AE%BE%E8%AE%A1%E6%96%B9%E6%A1%88/)
- [在线考试系统V2.0镜像构建、推送、部署](http://ehedgehog.net/2019/04/22/%E5%9C%A8%E7%BA%BF%E8%80%83%E8%AF%95%E7%B3%BB%E7%BB%9FV2.0%E9%95%9C%E5%83%8F%E6%9E%84%E5%BB%BA%E3%80%81%E6%8E%A8%E9%80%81%E3%80%81%E9%83%A8%E7%BD%B2/)
***
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
主要介绍如何基于docker、docker-compose部署后端项目、前端项目,主要的步骤是本地构建镜像,推送的远程仓库,远程服务器从远程仓库拉去镜像运行
主要介绍如何基于docker、docker-compose部署后端项目、前端项目,主要的步骤是本地构建镜像,推送的远程仓库,远程服务器从远程仓库拉去镜像运行
主要介绍如何基于docker、docker-compose部署后端项目、前端项目,主要的步骤是本地构建镜像,推送的远程仓库,远程服务器从远程仓库拉去镜像运行
## 安装docker、docker-compose
## 前提
linux系统安装`docker``docker-compose`
- 服务器:2核4G、CentOS 7.2 64位
windows系统安装`Docker for Windows`
- 注册阿里云账号
## 部署后端项目
### 安装MySQL
## 安装MySQL
MySQL需要单独安装,创建数据库和执行初始化脚本:
......@@ -18,146 +16,93 @@ MySQL需要单独安装,创建数据库和执行初始化脚本:
`/doc/deploy/mysql/microservice-auth.sql`
### 安装fastDfs
## 安装docker、docker-compose
非必须,如果需要用到附件上传的相关功能才安装
linux系统安装`docker``docker-compose`
基于`docker`安装`fastDfs`,网上有教程
windows系统安装`Docker for Windows`
### 修改配置
## 安装fastDfs
修改`docker-compose.env`,其它基本不用修改
参考:[fastdfs文件系统单机环境搭建和spring boot整合](https://blog.csdn.net/baidu_36415076/article/details/79505027)
包括数据库IP、端口、用户名和密码,fastDfs的IP、端口
## 拉取镜像
![image](images/deploy/config_docker_env.png)
### 构建镜像
`spring-microservice-exam`目录下运行:
1. 登录阿里云Docker Registry
```
mvn clean package -DskipTests=true docker:build
```
![image](images/deploy/config_docker_mvn.png)
docker login --username=你的阿里云账号 registry.cn-hangzhou.aliyuncs.com
构建成功:
![image](images/deploy/config_docker_mvn_success.png)
### 运行
1. 运行基础镜像(consul、redis、rabbitMq、config-service)
如:
docker login --username=tb70177569 registry.cn-hangzhou.aliyuncs.com
```
docker-compose -f docker-compose-base.yml up -d
```
`-d`表示后台运行
![image](images/deploy/config_docker_base.png)
2. 运行服务镜像(gateway-service、auth-service、user-service、exam-service)
```
docker-compose -f docker-compose-services.yml up -d
```
2. 拉取镜像
3. 检查是否启动成功
拉取各服务的镜像:
```
docker ps
```
也可以访问`localhost:8500`查看服务是否注册成功
4. 停止运行
后端镜像:
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/config-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/auth-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/user-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/exam-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/gateway-service:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/monitor-service:2.0
以基础镜像为例:
```
docker-compose -f docker-compose-base.yml stop
前端镜像:
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-web:2.0
```
## 部署前端项目
`spring-microservice-exam-ui`为例,`spring-microservice-exam-web`同理
## 修改配置
### 修改配置
将源码目录下的`docker-compose.env``docker-compose-base.yml``docker-compose-services.yml``docker-compose-nginx.yml``nginx.conf`上传到服务器的`/spring-microservice-exam/`目录下
修改`spring-microservice-exam-ui/config/proxyConfig.js`里的后端api网关地址,一般情况下是不需要修改的
目录结构:
![image](images/deploy/config_docker_ui_proxy.png)
![image](images/deploy/docker_root.png)
### 打包
修改`docker-compose.env`
`spring-microservice-exam-ui`目录下运行:
```
npm run build
```
包括数据库IP、端口、用户名和密码,fastDfs的IP、端口
运行成功后会生成`dist`目录,里面是项目的静态资源
![image](images/deploy/config_docker_env.png)
### 构建镜像
## 运行
`spring-microservice-exam-ui`目录下运行:
1. 按顺序执行:
```
docker build -t registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0 .
```
![image](images/deploy/config_docker_ui_build.png)
### 运行
运行基础服务:
docker-compose -f docker-compose-base.yml up -d
运行:
运行后端服务:
docker-compose -f docker-compose-services.yml up -d
运行前端服务:
docker-compose -f docker-compose-nginx.yml up -d
```
docker run -d -p 80:80 --name spring-microservice-exam-ui registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
```
![image](images/deploy/config_docker_ui_run.png)
## 推送到至远程仓库
以阿里云为例:
在容器镜像服务菜单下,新建镜像仓库`spring-microservice-exam-ui`
![image](images/deploy/config_docker_aliyun.png)
推送镜像
![image](images/deploy/config_docker_aliyun_push.png)
推送成功
![image](images/deploy/config_docker_aliyun_push_success.png)
`-d`表示后台运行
## 远程服务器拉去镜像运行
2. 检查是否启动成功
```
docker pull registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
docker ps
```
![image](images/deploy/config_docker_pull.png)
## 访问
```
docker run -d -p 80:80 --name spring-microservice-exam-ui registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
```
前台地址:ip:80
基于docker-compose运行后端项目:
后台地址:ip:81
```
docker-compose -f docker-compose-base.yml up -d
```
## 参考资料
```
docker-compose -f docker-compose-services.yml up -d
```
- [安装docker](https://www.cnblogs.com/yufeng218/p/8370670.html)
## 参考资料
- [安装docker-compose](https://www.jianshu.com/p/94760f35c98c)
待补充
- [在线考试系统V2.0镜像构建、推送、部署](http://ehedgehog.net/2019/04/22/%E5%9C%A8%E7%BA%BF%E8%80%83%E8%AF%95%E7%B3%BB%E7%BB%9FV2.0%E9%95%9C%E5%83%8F%E6%9E%84%E5%BB%BA%E3%80%81%E6%8E%A8%E9%80%81%E3%80%81%E9%83%A8%E7%BD%B2/)
\ No newline at end of file
......@@ -105,7 +105,6 @@ fastDfs的IP和端口号:
#### 监控
| 名称 | 地址 |
| --------- | -------- |
| rabbitMq监控 | localhost:15672 |
......
version: '2'
services:
# ---------------------------
# 前台
# ---------------------------
spring-microservice-exam-web:
image: registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-web:2.0
volumes:
# 挂载nginx的配置文件
- ./nginx.conf:/etc/nginx/nginx.conf
container_name: web-service
env_file: docker-compose.env # 从文件中获取配置
restart: always
ports:
- "80:80"
networks:
- net
# ---------------------------
# 后台
# ---------------------------
spring-microservice-exam-ui:
image: registry.cn-hangzhou.aliyuncs.com/spring-microservice-exam/spring-microservice-exam-ui:2.0
volumes:
# 挂载nginx的配置文件
- ./nginx.conf:/etc/nginx/nginx.conf
container_name: ui-service
env_file: docker-compose.env # 从文件中获取配置
restart: always
ports:
- "81:80"
networks:
- net
networks:
net:
driver: bridge
volumes:
data:
driver: local
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
user nginx;
worker_processes 2;
error_log /var/log/nginx/error.log warn;
pid /var/run/nginx.pid;
events {
use epoll;
worker_connections 2048;
}
http {
include /etc/nginx/mime.types;
# include /etc/nginx/conf.d/*.conf;
root /usr/share/nginx/html;
index index.html index.htm;
upstream gateway-service {
server gateway-service:8000 max_fails=3 fail_timeout=30s;
}
server {
listen 80;
server_name localhost;
location ~* /a(pi|uth) {
proxy_pass http://gateway-service;
}
location / {
}
}
}
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
<?xml version="1.0" encoding="UTF-8"?>
<configuration debug="false" scan="false">
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="online-exam"/>
<springProperty scop="context" name="spring.application.name" source="spring.application.name" defaultValue="spring-microservice-exam"/>
<property name="log.path" value="logs/${spring.application.name}" />
<!-- Console log output -->
<appender name="console" class="ch.qos.logback.core.ConsoleAppender">
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment