[学成在线]22-自动部署项目

news2025/5/6 0:52:11

自动部署

实战流程

下边使用jenkins实现CI/CD的流程。

1、将代码使用Git托管

2、在jenkins创建任务,从Git拉取代码。

3、拉取代码后进行自动构建:测试、打包、部署。

首先将代码打成镜像包上传到docker私服。

自动创建容器、启动容器。

4、当有代码push到git实现自动构建。

代码提交至Git

修改pom.xml文件

在pom.xml添加docker-maven-plugin插件实现将springboot工程创建镜像,此pom.xml添加docker-maven-plugin插件用于生成镜像。

分别修改system-api、content-api、media-api、gateway、auth、checkcode服务的pom.xml文件。

插件的坐标如下:

<dependency>
    <groupId>com.spotify</groupId>
    <artifactId>docker-maven-plugin</artifactId>
    <version>1.2.2</version>
</dependency>

修改pom.xml文件,以xuecheng-plus-checkcode为例,如下:

<build>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <version>${spring-boot.version}</version>
            <executions>
                <execution>
                    <goals>
                        <goal>repackage</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
        <plugin>
            <groupId>com.spotify</groupId>
            <artifactId>docker-maven-plugin</artifactId>
            <version>1.2.2</version>
            <configuration>
                <!--修改imageName节点的内容,改为私有仓库地址和端口,再加上镜像id和 TAG,我们要直接传到私服-->
                <!--配置最后生成的镜像名,docker images里的,我们这边取项目名:版本-->
                <!--<imageName>${project.artifactId}:${project.version}</imageName>-->
                <imageName>192.168.101.65:5000/${project.artifactId}:${project.version}</imageName>
                <!--也可以通过以下方式定义image的tag信息。 -->
                <!-- <imageTags>
                     <imageTag>${project.version}</imageTag>
                     &lt;!&ndash;build 时强制覆盖 tag,配合 imageTags 使用&ndash;&gt;
                     <forceTags>true</forceTags>
                     &lt;!&ndash;build 完成后,push 指定 tag 的镜像,配合 imageTags 使用&ndash;&gt;
                     <pushImageTag>true</pushImageTag>
                 </imageTags>-->
                <baseImage>java:8u20</baseImage>
                <maintainer>docker_maven docker_maven@email.com</maintainer>
                <workdir>/root</workdir>
                <cmd>["java", "-version"]</cmd>
                <!--来指明Dockerfile文件的所在目录,如果配置了dockerDirectory则忽略baseImage,maintainer等配置-->
                <!--<dockerDirectory>./</dockerDirectory>-->
                <!--2375是docker的远程端口,插件生成镜像时连接docker,这里需要指定docker远程端口-->
                <dockerHost>http://192.168.101.65:2375</dockerHost>
                <!--入口点,project.build.finalName就是project标签下的build标签下 的filename标签内容,testDocker-->
                <!--相当于启动容器后,会自动执行java -jar ...-->
                <entryPoint>["java", "-Dfile.encoding=utf-8","-jar", "/root/${project.build.finalName}.jar"]</entryPoint>
                <!--是否推送到docker私有仓库,旧版本插件要配置maven的settings文件。 -->
                <pushImage>true</pushImage>
                <registryUrl>192.168.101.65:5000</registryUrl>  <!-- 这里是复制 jar 包到 docker 容器指定目录配置 -->
                <resources>
                    <resource>
                        <targetPath>/root</targetPath>
                        <directory>${project.build.directory}</directory>
                        <!--把哪个文件上传到docker,相当于Dockerfile里的add app.jar /-->
                        <include>${project.build.finalName}.jar</include>
                    </resource>
                </resources>
            </configuration>
        </plugin>
    </plugins>
</build>

其中system-api服务的bootstrap.yml修改如下:

server:
  servlet:
    context-path: /system
  port: 63110
#微服务配置
spring:
  application:
    name: system-api
  datasource:
    driver-class-name: com.mysql.cj.jdbc.Driver
    url: jdbc:mysql://192.168.101.65:3306/xcplus_system?serverTimezone=UTC&userUnicode=true&useSSL=false&
    username: root
    password: mysql
  cloud:
    nacos:
      server-addr: 192.168.101.65:8848
      discovery:
        namespace: dev166
        group: xuecheng-plus-project
# 日志文件配置路径
logging:
  config: classpath:log4j2-dev.xml

# swagger 文档配置
swagger:
  title: "学成在线系统管理"
  description: "系统管理接口"
  base-package: com.xuecheng.system
  enabled: true
  version: 1.0.0

在system-api工程添加nacos的依赖:

<dependency>
    <groupId>com.alibaba.cloud</groupId>
    <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>

删除system-service工程下的配置文件。

以上内容修改完毕再次提交Git.

自动构建测试

找到jenkins_02任务,配置源码管理

配置完毕,开始构建

通过控制台输出日志观察构建情况

如果控制台有报错,根据错误信息进行调试。

部署成功后,进入服务器查看docker容器是否启动成功

部署前端门户

在虚拟机的docker中已经部署了nginx,修改nginx.conf的配置文件

#user  nobody;
worker_processes  1;

#error_log  logs/error.log;
#error_log  logs/error.log  notice;
#error_log  logs/error.log  info;

#pid        logs/nginx.pid;


events {
    worker_connections  1024;
}


http {
     server_names_hash_bucket_size 64;
     client_max_body_size 100M; # 设置客户端请求体最大值
     client_body_buffer_size 128k; # 设置请求体缓存区大小
    include       mime.types;
    default_type  application/octet-stream;

    #log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
    #                  '$status $body_bytes_sent "$http_referer" '
    #                  '"$http_user_agent" "$http_x_forwarded_for"';

    #access_log  logs/access.log  main;

    sendfile        on;
    #tcp_nopush     on;

    #keepalive_timeout  0;
    keepalive_timeout  65;
   #文件服务
  upstream fileserver{
    server 192.168.101.65:9000 weight=10;
  } 
     #后台网关
  upstream gatewayserver{
    server 192.168.101.65:63010 weight=10;
  } 
    #gzip  on;

    server {
        listen       80;
        server_name  www.51xuecheng.cn localhost;
        #rewrite ^(.*) https://$server_name$1 permanent;
        #charset koi8-r;
        ssi on;
        ssi_silent_errors on;
        #access_log  logs/host.access.log  main;

        location / {
            alias   /etc/nginx/html/;
            index  index.html index.htm;
        }
        #api
        location /api/ {
                proxy_pass http://gatewayserver/;
        } 
        #静态资源
        location /static/img/ {  
                alias  /etc/nginx/html/img/;
        } 
        location /static/css/ {  
                alias   /etc/nginx/html/css/;
        } 
        location /static/js/ {  
                alias   /etc/nginx/html/js/;
        } 
        location /static/plugins/ {  
                alias   /etc/nginx/html/plugins/;
                add_header Access-Control-Allow-Origin http://ucenter.51xuecheng.cn;  
                add_header Access-Control-Allow-Credentials true;  
                add_header Access-Control-Allow-Methods GET;
        } 
        location /plugins/ {  
                alias   /etc/nginx/html/plugins/;
        } 
        location /course/preview/learning.html {
                alias /etc/nginx/html/course/learning.html;
        } 
        location /course/search.html {  
                root   /etc/nginx/html;
        } 
        location /course/learning.html {  
                root   /etc/nginx/html;
        } 
        location /course/ {  
                proxy_pass http://fileserver/mediafiles/course/;
        } 
        #openapi
        location /open/content/ {
                proxy_pass http://gatewayserver/content/open/;
        } 
        location /open/media/ {
                proxy_pass http://gatewayserver/media/open/;
        } 

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #
        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }

        # proxy the PHP scripts to Apache listening on 127.0.0.1:80
        #
        #location ~ \.php$ {
        #    proxy_pass   http://127.0.0.1;
        #}

        # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
        #
        #location ~ \.php$ {
        #    root           html;
        #    fastcgi_pass   127.0.0.1:9000;
        #    fastcgi_index  index.php;
        #    fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        #    include        fastcgi_params;
        #}

        # deny access to .htaccess files, if Apache's document root
        # concurs with nginx's one
        #
        #location ~ /\.ht {
        #    deny  all;
        #}
    }

   server {
        listen       80;
        server_name  file.51xuecheng.cn;
        #charset koi8-r;
        ssi on;
        ssi_silent_errors on;
        #access_log  logs/host.access.log  main;
        location /video {
            proxy_pass   http://fileserver;
        }

        location /mediafiles {
            proxy_pass   http://fileserver;
        }
   }
 
   server {
        listen       80;
        server_name  teacher.51xuecheng.cn;
        #charset koi8-r;
        ssi on;
        ssi_silent_errors on;
        #access_log  logs/host.access.log  main;
        location / {
            alias   /etc/nginx/html/dist/;
            index  index.html index.htm;
        }
        #location / {
        #    proxy_pass   http://uidevserver;
        #}

        location /api/ {
                proxy_pass http://gatewayserver/;
        } 
        
        
   }

    server {
        listen       80;
        server_name  ucenter.51xuecheng.cn;
        #charset koi8-r;
        ssi on;
        ssi_silent_errors on;
        #access_log  logs/host.access.log  main;
        location / {
            alias   /etc/nginx/html/ucenter/;
            index  index.html index.htm;
        }
        location /include {
            proxy_pass   http://192.168.101.65;
        }
        location /img/ {
            proxy_pass   http://192.168.101.65/static/img/;
        }
        location /api/ {
                proxy_pass http://gatewayserver/;
        } 
   }
    # another virtual host using mix of IP-, name-, and port-based configuration
    #
    #server {
    #    listen       8000;
    #    listen       somename:8080;
    #    server_name  somename  alias  another.alias;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}


    # HTTPS server
    #
    #server {
    #    listen       443 ssl;
    #    server_name  localhost;

    #    ssl_certificate      cert.pem;
    #    ssl_certificate_key  cert.key;

    #    ssl_session_cache    shared:SSL:1m;
    #    ssl_session_timeout  5m;

    #    ssl_ciphers  HIGH:!aNULL:!MD5;
    #    ssl_prefer_server_ciphers  on;

    #    location / {
    #        root   html;
    #        index  index.html index.htm;
    #    }
    #}

}

将前端门户的静态页面拷贝到 /data/soft/nginx/xuecheng_portal_static

启动nginx容器:

docker start nginx

修改本机hosts文件:

192.168.101.65   www.51xuecheng.cn 51xuecheng.cn ucenter.51xuecheng.cn teacher.51xuecheng.cn file.51xuecheng.cn

将本机的nginx服务停掉,访问www.51xuecheng.cn。

部署机构端前端

将机构端的前端工程打包,运行yarn build

打包成功在工程目录生成dist目录

将此目录的内容拷贝到虚拟机的/data/soft/nginx/xuecheng_portal_static/dist

配置触发器

当向gogs提交代码时进行自动构建

在gogs配置钩子

推送地址设置jenkins的接口:

http://192.168.101.65:8888/gogs-webhook/?job=jenkins_02

配置好可以测试一下:

测试后观察jenkina是否重新构建任务。

提交代码测试:

修改代码提交到gogs,观察jenkins是否自动构建任务

功能测试

测试认证功能

部署成功后对功能进行测试。

1、首先测试认证功能

进入www.51xuecheng.cn,点击登录,输入账号和密码进行登录。

账号和密码:t1/111111

测试内容管理

1、测试课程列表

出现 Request failed with status code 503 错误

通过nacos排查,进入服务列表

缺少system-api

排查system-api工程的bootstrap.yml配置文件、依赖包等内容。

修改代码后重新提交git

再次进行jenkins构建。

2、测试上传课程图片

首先测试修改课程,上传一个新图片。

3、测试课程发布

首先观察xxl-job调度中心是否成功注册执行器

启动课程发布任务

发布一门课程,观察content-api容器的日志

错误日志:

java.io.FileNotFoundException: file:/root/xuecheng-plus-content-api-0.0.1-SNAPSHOT.jar!/BOOT-INF/classes!/templates does not exist.

无法找到静态化的模板

屏蔽原来的方式,改如下方式

//            String classpath = this.getClass().getResource("/").getPath(); //打包jar无法获取模板
//            configuration.setDirectoryForTemplateLoading(new File(classpath + "/templates/"));
        //更改为如下方式
        configuration.setTemplateLoader(new ClassTemplateLoader(this.getClass().getClassLoader(),"/templates"));

测试媒资管理

1、配置ffmpeg的目录

将linux版本的ffmpeg拷贝到 /data/soft/service 下,在nacos配置ffmpeg 的地址:

Ffmpeg linux版本下载地址:https://johnvansickle.com/ffmpeg/

videoprocess:
 ffmpegpath: /root/soft/ffmpeg

2、测试上传视频

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/2356687.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

Golang|使用函数作为参数和使用接口的联系

函数作为数据类型的一种&#xff0c;可以成为其他函数的参数。在 Go&#xff08;Golang&#xff09; 中&#xff0c;函数作为参数 和 接口&#xff08;interface&#xff09;&#xff0c;本质上都和抽象、灵活调用有关 —— 都是让代码更灵活、更可扩展的手段。不过它们各有侧重…

MATLAB技巧——norm和vecnorm两个函数讲解与辨析

在 MATLAB 中,norm 和 vecnorm 是两个用于计算向量或矩阵范数的函数,虽然它们的功能相似,但在使用场景和适用性上存在一些区别。本文将详细解释这两个函数的用途、功能以及如何选择合适的函数。 文章目录 norm函数用法范数类型vecnorm函数用法范数类型选择合适的函数示例对比…

ubuntu的libc 库被我 sudo apt-get --reinstall install libc6搞没了

我系统的libc 没了 今天为了运行一个开源的yuv 播放器&#xff0c;在运行的时候提醒 Inconsistency detected by ld.so: dl-call-libc-early-init.c: 37: _dl_call_libc_early_init: Assertion sym ! NULL failed!然后听从AI 的建议 当我去执行ls 时&#xff0c;系统提示 就这…

Ubuntu搭建Conda+Python开发环境

目录 一、环境说明 1、测试环境为ubuntu24.04.1 2、更新系统环境 3、安装wget工具 4、下载miniconda安装脚本 二、安装步骤 1、安装miniconda 2、source conda 3、验证版本 4、配置pip源 三、conda用法 1、常用指令 一、环境说明 1、测试环境为ubuntu24.04.1 2、更…

Python全流程开发实战:基于IMAP协议安全下载个人Gmail邮箱内所有PDF附件

在日常办公场景中&#xff0c;面对成百上千封携带PDF附件的邮件&#xff0c;手动逐一下载往往耗时耗力&#xff0c;成为效率瓶颈。如何通过代码实现“一键批量下载”&#xff1f;本文将以**“Gmail全量PDF附件下载工具”**开发为例&#xff0c;完整拆解从需求分析到落地交付的P…

Pytest-mark使用详解(跳过、标记、参数 化)

1.前言 在工作中我们经常使用pytest.mark.XXXX进行装饰器修饰&#xff0c;后面的XXX的不同&#xff0c;在pytest中有不同的作 用&#xff0c;其整体使用相对复杂&#xff0c;我们单独将其抽取出来做详细的讲解。 2.pytest.mark.skip()/skipif()跳过用例 import pytest #无条…

【浅尝Java】Java简介第一个Java程序(含JDK、JRE与JVM关系、javcdoc的使用)

&#x1f35e;自我激励&#xff1a;每天努力一点点&#xff0c;技术变化看得见 文章目录 Java语言概述Java是什么Java语言的重要性Java语言发展简史Java语言特性 第一个Java程序main方法示例运行Java程序JDK、JRE、JVM之间的关系注释基本规则注释规范 标识符关键字 Java语言概述…

项目三 - 任务2:创建笔记本电脑类(一爹多叔)

在本次实战中&#xff0c;我们通过Java的单根继承和多接口实现特性&#xff0c;设计了一个笔记本电脑类。首先创建了Computer抽象类&#xff0c;提供计算的抽象方法&#xff0c;模拟电脑的基本功能。接着定义了NetCard和USB两个接口&#xff0c;分别包含连接网络和USB设备的抽象…

Electron学习+打包

1. 什么是 Electron&#xff1f; Electron 是⼀个 跨平台桌⾯应⽤ 开发框架&#xff0c;开发者可以使⽤&#xff1a;HTML、CSS、JavaScript 等 Web 技术来构建桌⾯应⽤程序&#xff0c;它的本质是结合了 Chromium 和 Node.js &#xff0c;现在⼴泛⽤于桌⾯应 ⽤程序开发&a…

NumPy线性代数功能全解析:矩阵运算与方程求解实用指南

NumPy 是线性代数领域中高效的工具。它可以帮助完成矩阵运算和方程求解。本文将介绍 NumPy 中用于线性代数的常用函数。 矩阵乘法 矩阵乘法会根据两个矩阵生成一个新矩阵。具体做法是将第一个矩阵的每一行与第二个矩阵的每一列相乘&#xff0c;并将乘积相加&#xff0c;得到新…

《RabbitMQ 全面解析:从原理到实战的高性能消息队列指南》

一、RabbitMQ 核心原理与架构 1. 核心组件与工作流程 RabbitMQ 基于 AMQP 协议&#xff0c;核心组件包括 生产者&#xff08;Producer&#xff09;、交换机&#xff08;Exchange&#xff09;、队列&#xff08;Queue&#xff09; 和 消费者&#xff08;Consumer&#xff09;。…

Android Framework学习二:Activity创建及View绘制流程

文章目录 Window绘制流程Window Manager Service&#xff08;WMS&#xff09;SurfaceSurfaceFlinger 安卓View层次结构ActivityPhoneWindowActivity与PhoneWindow两者之间的关系ViewRootImplDecorViewDecorView 的作用DecorView 的结构总结 Activity创建流程View invalidate调用…

python如何在深度学习框架目标检测算法使用Yolov8训练道路汽车漆面车漆缺陷数据集 建立基于YOLOv8道路汽车漆面缺陷(划痕)检测系统

基于YOLOv8道路汽车漆面缺陷&#xff08;划痕&#xff09;检测系统 文章目录 1. 安装依赖2. 数据集准备与划分3. 数据预处理4. 配置YOLOv85. 训练和评估模型6. 推理与可视化7. 构建GUI应用程序 道路汽车漆面车漆缺陷检测数据集1221张 1类 汽车漆面缺陷检测YOLO数据集 1221张…

高性能、云原生的对象存储服务MinIO 详细介绍与案例应用

什么是MinIO&#xff1f; MinIO是一个高性能、云原生的对象存储服务&#xff0c;采用Apache License v2.0开源协议发布。它与Amazon S3云存储服务API兼容&#xff0c;适合构建高性能、可扩展的存储基础设施。支持大规模非结构化数据的存储&#xff0c;适合图片、视频、日志、备…

Arduino按键开关编程详解

一、按键开关的基本原理与硬件连接 1.1 按键开关的工作原理 按键开关是一种常见的输入设备&#xff0c;其核心原理基于机械触点的闭合与断开。当用户按下按键时&#xff0c;内部的金属片会连接电路两端&#xff0c;形成通路&#xff1b;松开按键后&#xff0c;金属片在弹簧作…

鸢尾花(Iris)数据集的多模型分类与可视化分析工具

该程序是一个鸢尾花(Iris)数据集的多模型分类与可视化分析工具,主要功能如下: 1. 数据加载与预处理 功能说明: 使用sklearn.datasets.load_iris()加载经典的鸢尾花数据集。将数据转为pandas.DataFrame,并将类别数字标签映射为中文类别名(山鸢尾、变色鸢尾、维吉尼亚鸢尾…

[蓝桥杯 2023 国 Python B] 划分 Java

import java.util.*;public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);int[] arr new int[41];int sum 0;for (int i 1; i < 40; i) {arr[i] sc.nextInt();sum arr[i];}sc.close();int target sum / 2; // 最接近的两…

25.4.30数据结构|并查集 路径压缩

书接上回 上一节&#xff1a;数据结构|并查集 前言 &#xff08;一&#xff09;理论理解&#xff1a; 1、在QuickUnion快速合并的过程中&#xff0c;每次都要找根ID&#xff0c;而路径压缩让找根ID变得更加迅速直接。 2、路径压缩 针对的是findRootIndex()【查找根ID】进行的压…

MATLAB R2024a安装教程

安装步骤&#xff1a; 软件大小&#xff1a;约12.08G 安装环境&#xff1a;Win10~Win11或更高 下载好安装包&#xff0c;可以在网上找个安装包&#xff0c;比如我用国内镜像matlab地址github.com/futureflsl/matlab-chinese-mirror&#xff0c;这样下载稍微快点 1.开始安装…

WEB安全--社会工程--SET钓鱼网站

1、选择要钓鱼的网站 2、打开kali中的set 3、启动后依次选择&#xff1a; 4、输入钓鱼主机的地址&#xff08;kali&#xff09;和要伪装的网站域名&#xff1a; 5、投放钓鱼网页&#xff08;服务器域名:80&#xff09; 6、获取账号密码