1.安装jenkins
我后端使用的是宝塔面板来安装的容器化jenkins,要选中允许外部访问,安装完之后没有那个选项了,一开始安装的时候要选中不使用域名和后面的允许外部访问。Jenkins 版本为: 2.462.1
2.配置Jenkins
2.1 Git plugin
安装完毕之后可以在项目构建的之后直接从gitee中拉取代码,不过需要先配置全局凭证,我这边使用的是账户密码。
2.2Maven Integration plugin
安装完毕之后可以构建maven项目。
2.3Publish Over SSH
安装之后可以将代码推送到远程服务器,首先保存全局凭证,此处我使用的还是账号密码,然后再system下配置Publish Over SSH。之后点击下方测试查看是否可以正常连接。
然后在项目构建中,Post Steps下面添加生成后的步骤,"通过SSH发送文件或执行命令"选项, 然后添加如下配置:
服务器是上面配置的。
源文件:定义为:**/*
,不过为了不必要的传输改为 **/ruoyi-admin.jar
。
删除前缀:是根据打包后文件所在路径来进行删除,不然会把目录也推送到远程服务器。
远程目录:远程目录为空时,默认使用上面服务器配置的路径
Exec 命令:在远程服务器上执行的命令
3. 构建记录和访问结果
channel stopped
SSH: Connecting from host [d4ea9e4c162f]
SSH: Connecting with configuration [one day server] ...
SSH: Creating session: username [root], hostname [154.64.000.102], port [22]
SSH: Connecting session ...
SSH: Connected
SSH: Opening SFTP channel ...
SSH: SFTP channel open
SSH: Connecting SFTP channel ...
SSH: Connected
SSH: cd [/develop/ruoyi/]
SSH: OK
SSH: cd [/develop/ruoyi/]
SSH: OK
SSH: put [ruoyi-admin.jar]
SSH: Opening exec channel ...
SSH: EXEC: channel open
SSH: EXEC: STDOUT/STDERR from command [cd /develop/ruoyi/nohup java -jar ruoyi-admin.jar] ...
SSH: EXEC: connected
Application Version: 4.7.9
Spring Boot Version: 2.5.15// _ooOoo_ //
// o8888888o //
// 88" . "88 //
// (| ^_^ |) //
// O\ = /O //
// ____/`---'\____ //
// .' \\| |// `. //
// / \\||| : |||// \ //
// / _||||| -:- |||||- \ //
// | | \\\ - /// | | //
// | \_| ''\---/'' | | //
// \ .-\__ `-` ___/-. / //
// ___`. .' /--.--\ `. . ___ //
// ."" '< `.___\_<|>_/___.' >'"". //
// | | : `- \`.;`\ _ /`;.`/ - ` : | | //
// \ \ `-. \_ __\ /__ _/ .-` / / //
// ========`-.____`-.___\_____/___.-`____.-'======== //
// `=---=' //
// ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ //
// 佛祖保佑 永不宕机 永无BUG //11:32:16.142 [main] INFO c.r.RuoYiApplication - [logStarting,55] - Starting RuoYiApplication using Java 1.8.0_362 on instance-6obVdquJ with PID 332642 (/develop/ruoyi/ruoyi-admin.jar started by root in /develop/ruoyi)
11:32:16.161 [main] DEBUG c.r.RuoYiApplication - [logStarting,56] - Running with Spring Boot v2.5.15, Spring v5.3.33
11:32:16.162 [main] INFO c.r.RuoYiApplication - [logStartupProfileInfo,686] - The following 1 profile is active: "druid"
11:32:16.166 [background-preinit] INFO o.h.v.i.util.Version - [<clinit>,21] - HV000001: Hibernate Validator 6.2.5.Final
11:32:19.002 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-authCache]
11:32:20.217 [main] INFO c.a.d.p.DruidDataSource - [init,1002] - {dataSource-1} inited
11:32:21.523 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [loginRecordCache]
11:32:21.620 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - ==> Preparing: select config_id, config_name, config_key, config_value, config_type, create_by, create_time, update_by, update_time, remark from sys_config
11:32:21.860 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - ==> Parameters:
11:32:21.894 [main] DEBUG c.r.s.m.S.selectConfigList - [debug,135] - <== Total: 11
11:32:21.901 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.906 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.907 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.907 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.908 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.909 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.909 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.910 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.911 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.912 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:21.912 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-config]
11:32:22.539 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - ==> Preparing: select dict_code, dict_sort, dict_label, dict_value, dict_type, css_class, list_class, is_default, status, create_by, create_time, remark from sys_dict_data WHERE status = ?
11:32:22.550 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - ==> Parameters: 0(String)
11:32:22.573 [main] DEBUG c.r.s.m.S.selectDictDataList - [debug,135] - <== Total: 29
11:32:22.577 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.579 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.579 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.580 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.581 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.582 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.582 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.583 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.583 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.585 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-dict]
11:32:22.851 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1220] - Using default implementation for ThreadExecutor
11:32:22.878 [main] INFO o.q.c.SchedulerSignalerImpl - [<init>,61] - Initialized Scheduler Signaller of type: class org.quartz.core.SchedulerSignalerImpl
11:32:22.879 [main] INFO o.q.c.QuartzScheduler - [<init>,229] - Quartz Scheduler v.2.3.2 created.
11:32:22.880 [main] INFO o.q.s.RAMJobStore - [initialize,155] - RAMJobStore initialized.
11:32:22.881 [main] INFO o.q.c.QuartzScheduler - [initialize,294] - Scheduler meta-data: Quartz Scheduler (v2.3.2) 'quartzScheduler' with instanceId 'NON_CLUSTERED'Scheduler class: 'org.quartz.core.QuartzScheduler' - running locally.NOT STARTED.Currently in standby mode.Number of jobs executed: 0Using thread pool 'org.quartz.simpl.SimpleThreadPool' - with 10 threads.Using job-store 'org.quartz.simpl.RAMJobStore' - which does not support persistence. and is not clustered.11:32:22.882 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1374] - Quartz scheduler 'quartzScheduler' initialized from an externally provided properties instance.
11:32:22.882 [main] INFO o.q.i.StdSchedulerFactory - [instantiate,1378] - Quartz scheduler version: 2.3.2
11:32:22.883 [main] INFO o.q.c.QuartzScheduler - [setJobFactory,2293] - JobFactory set to: org.springframework.scheduling.quartz.SpringBeanJobFactory@14fc1f0
11:32:22.950 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - ==> Preparing: select job_id, job_name, job_group, invoke_target, cron_expression, misfire_policy, concurrent, status, create_by, create_time, remark from sys_job
11:32:22.952 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - ==> Parameters:
11:32:22.957 [main] DEBUG c.r.q.m.S.selectJobAll - [debug,135] - <== Total: 3
11:32:23.374 [main] INFO o.a.s.c.e.EhCacheManager - [getCache,169] - Using existing EHCache named [sys-userCache]
11:32:23.704 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Initializing ProtocolHandler ["http-nio-80"]
11:32:23.704 [main] INFO o.a.c.c.StandardService - [log,173] - Starting service [Tomcat]
11:32:23.705 [main] INFO o.a.c.c.StandardEngine - [log,173] - Starting Servlet engine: [Apache Tomcat/9.0.75]
11:32:23.778 [main] INFO o.a.c.c.C.[.[.[/] - [log,173] - Initializing Spring embedded WebApplicationContext
11:32:26.083 [main] INFO o.a.c.h.Http11NioProtocol - [log,173] - Starting ProtocolHandler ["http-nio-80"]
11:32:26.741 [main] INFO o.q.c.QuartzScheduler - [start,547] - Scheduler quartzScheduler_$_NON_CLUSTERED started.
11:32:26.754 [main] INFO c.r.RuoYiApplication - [logStarted,61] - Started RuoYiApplication in 11.293 seconds (JVM running for 12.178)
(♥◠‿◠)ノ゙ 若依启动成功 ლ(´ڡ`ლ)゙ .-------. ____ __ | _ _ \ \ \ / / | ( ' ) | \ _. / ' |(_ o _) / _( )_ .' | (_,_).' __ ___(_ o _)' | |\ \ | || |(_,_)' | | \ `' /| `-' / | | \ / \ / ''-' `'-' `-..-'
4.使用docker启动项目
保证远程服务器已经安装docker,然后将下面的命令放到exce命令里面
# 打开文件发送到的路径
cd /develop/ruoyi/
# 停止容器ruoyi
docker stop ruoyi
# 删除容器ruoyi
docker rm ruoyi
# 删除标签为admin-image的镜像(应该是,需要测试)
docker rmi -f admin-image
# 根据dockerfile创建新的标签为admin-image的镜像。
# 后面的.代表执行dockerfile,dockerfile和ruoyi-admin.jar在同级目录下
docker build -t admin-image .
# 后台启动容器,容器名称为ruoyi,对外暴露端口号80
# -d为后台启动
docker run -d --name ruoyi -p 80:80 admin-image
下面是dockerfile:
# 基础镜像
FROM openjdk:8-jre
# 挂载目录
VOLUME /home/ruoyi
# 创建目录
RUN mkdir -p /home/ruoyi
# 指定路径
WORKDIR /home/ruoyi
# 设置时区为上海
RUN ln -snf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime && echo 'Asia/Shanghai' > /etc/timezone
# 复制jar文件到路径
COPY ./ruoyi-admin.jar /home/ruoyi/ruoyi-admin.jar
# 启动系统服务
ENTRYPOINT ["java","-Xms125m","-Xmx125m","-jar","ruoyi-admin.jar"]