forked from WinterChenS/my-site
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
dianYu edited this page Feb 1, 2019
·
1 revision
Welcome to the my-site wiki!
<div class="mt-0 mt-lg-1 flex-shrink-0 gh-header-actions">
<a href="#wiki-pages-box" class="d-md-none ">Jump to bottom</a>
</div>
<div class="mt-2 mt-md-1 pb-3 gh-header-meta">
WinterChenS.github.io edited this page <relative-time datetime="2018-05-03T12:13:29Z" title="2018年5月3日 GMT+8 下午8:13">on 3 May 2018</relative-time>
·
<a href="/WinterChenS/my-site/wiki/%E5%A6%82%E4%BD%95%E9%83%A8%E7%BD%B2My-Site/_history" class="muted-link">
1 revision
</a>
</div>
部署的方式分为两种:
- docker容器部署;
- 普通jar包部署;
git clone https://github.com/WinterChenS/my-site.git
目录结构:
my-site
├── file
├── lu_tale.sql
├── src
├── docker
├── main/java
└── main/resources
└── pom.xml
有docker启动和jar包启动两种方式,默认为jar包启动。 确认基础环境搭建完成之后,即可进行部署,详见基础环境
- 修改配置文件中的mysql地址和端口,本网站的文章使用的是markdown,如果需要使用图片直接上传,需要七牛云对象存储的配置.
由于本网站很多功能都与markdown息息相关,blog和摄影作品的上传都是用了七牛云对象存储服务,如果需要使用图片上传服务的话,需要进行服务的配置,该配置在QiniuCloudService.java
中:
没有使用的同学可以参照官方文档:官方文档
- ACCESS_KEY:存取键
- SECRET_KEY:秘钥
- BUCKET:仓库名
- QINIU_UPLOAD_SITE:外网访问地址
当然,也可以不使用七牛云,可以自己上传之后再贴进来,不过这样比较麻烦就是了!
- 导入数据库文件:file/lu_tale.sql
- 使用maven进行打包
mvn clean package
在target包下找到生成的jar包:
## 开发环境 dev
nohup java -jar my-site-1.0.0.RELEASE.jar --spring.profiles.active=dev
## 生产环境 prod
nohup java -jar my-site-1.0.0.RELEASE.jar --spring.profiles.active= prod
将项目 my-site
拷贝服务器中,进入项目路径下进行打包测试.
#打包
mvn package
#启动
java -jar target/my-site-1.0.0.RELEASE.jar
看到 Spring Boot 的启动日志后表明环境配置没有问题,接下来我们使用 DockerFile 构建镜像。
mvn package docker:build
第一次构建可能有点慢,当看到以下内容的时候表明构建成功:
[INFO] Building image springboot/my-site
Step 1/4 : FROM openjdk:8-jdk-alpine
---> 224765a6bdbe
Step 2/4 : VOLUME /tmp
---> Using cache
---> bef8b6ae93aa
Step 3/4 : ADD my-site-1.0.0.RELEASE.jar app.jar
---> fe7f4dff781d
Step 4/4 : ENTRYPOINT java -Djava.security.egd=file:/dev/./urandom -jar /app.jar
---> Running in 7def475e609d
---> 66653a573692
Removing intermediate container 7def475e609d
ProgressMessage{id=null, status=null, stream=null, error=null, progress=null, progressDetail=null}
Successfully built 66653a573692
Successfully tagged springboot/my-site:latest
[INFO] Built springboot/my-site
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 25.119 s
[INFO] Finished at: 2018-05-03T19:16:05+08:00
[INFO] Final Memory: 48M/578M
[INFO] ------------------------------------------------------------------------
然后我们使用docker images
命令查看镜像:
hendonghuadeMacBook-Pro% docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
springboot/my-site latest 66653a573692 47 seconds ago 142MB
<none> <none> 1bec22fbcef1 6 days ago 133MB
openjdk 8-jdk-alpine 224765a6bdbe 3 months ago 102MB
springboot/my-site
就是我们构件好的镜像,下一步就是运行该镜像
docker run -p 8080:8080 -t springboot/my-site
启动完成之后我们使用docker ps
查看正在运行的镜像:
chendonghuadeMacBook-Pro% docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0617b1dc12f1 springboot/my-site "java -Djava.secur..." 46 seconds ago Up 44 seconds 0.0.0.0:8080->1111/tcp festive_pike
启动成功之后访问: http://localhost:8080 访问首页 http://localhost:8080/admin 访问后台 默认账密:admin 123456
</div>
</div>
<div id="wiki-rightbar" class="mt-4 ml-md-6 flex-shrink-0 width-full wiki-rightbar">
<div id="wiki-pages-box" class="mb-4 wiki-pages-box js-wiki-pages-box" role="navigation">
<ul class="m-0 p-0 list-style-none" data-filterable-for="wiki-pages-filter" data-filterable-type="substring">
<li class="Box-row">
<strong><a class="d-block" href="/WinterChenS/my-site/wiki">Home</a></strong>
</li>
<li class="Box-row">
<strong><a class="d-block" href="/WinterChenS/my-site/wiki/%E5%A6%82%E4%BD%95%E9%83%A8%E7%BD%B2My-Site">如何部署My Site</a></strong>
</li>
</ul>
</div>
<h5 class="mt-0 mb-2">Clone this wiki locally</h5>
<div class="width-full input-group">
<input id="wiki-clone-url" type="text" data-autoselect="" class="form-control input-sm text-small text-gray input-monospace" aria-label="Clone URL for this wiki" value="https://github.com/WinterChenS/my-site.wiki.git" readonly="readonly">
<span class="input-group-button">
<clipboard-copy for="wiki-clone-url" aria-label="Copy to clipboard" class="btn btn-sm zeroclipboard-button" tabindex="0" role="button">
<svg class="octicon octicon-clippy" viewBox="0 0 14 16" version="1.1" width="14" height="16" aria-hidden="true"><path fill-rule="evenodd" d="M2 13h4v1H2v-1zm5-6H2v1h5V7zm2 3V8l-3 3 3 3v-2h5v-2H9zM4.5 9H2v1h2.5V9zM2 12h2.5v-1H2v1zm9 1h1v2c-.02.28-.11.52-.3.7-.19.18-.42.28-.7.3H1c-.55 0-1-.45-1-1V4c0-.55.45-1 1-1h3c0-1.11.89-2 2-2 1.11 0 2 .89 2 2h3c.55 0 1 .45 1 1v5h-1V6H1v9h10v-2zM2 5h8c0-.55-.45-1-1-1H8c-.55 0-1-.45-1-1s-.45-1-1-1-1 .45-1 1-.45 1-1 1H3c-.55 0-1 .45-1 1z"></path></svg>
</clipboard-copy>
</span>
</div>
</div>