前后端部署笔记

news2024/10/4 15:13:59

windows版:

如果傻呗公司让用win电脑部署,类似于我们使用笔记本做局域网服务器,社内使用。

1.安装win版的nginx、mysql、node、jdk等

2.nginx开机自启参考Nginx配置及开机自启动(Windows环境)_nginx开机自启动 windows-CSDN博客
Windows环境Nginx部署springboot+vue前后端分离项目_windows nginx配置前后端分离-CSDN博客

worker_processes  1;

events {
    worker_connections  1024;
}

http {
    include       mime.types;
    default_type  application/octet-stream;
    sendfile        on;
    keepalive_timeout  65;

    server {
        listen       80;
        server_name  localhost;

        location / {
            root   /usr/local/YiZhanShi/yizhanshi-ui;
            try_files $uri $uri/ /index.html;
            index  index.html index.htm;
        }

        location /prod-api/{
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header REMOTE-HOST $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_pass http://yizhanshi-gateway:8080/;
        
        # 添加 CORS 头
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range';

            # 对预检请求响应
        if ($request_method = 'OPTIONS') {
        add_header 'Access-Control-Allow-Origin' '*';
        add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
        add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range';
        add_header 'Access-Control-Max-Age' 1728000;
        add_header 'Content-Type' 'text/plain charset=UTF-8';
        add_header 'Content-Length' 0;
        return 204;
        }
        }

        # 避免actuator暴露
        if ($request_uri ~ "/actuator") {
            return 403;
        }

        error_page   500 502 503 504  /50x.html;
        location = /50x.html {
            root   html;
        }
    }
}

Nginx配置及开机自启动(Windows环境)_nginx开机自启动 windows-CSDN博客

3.java项目开机自启参考
win10环境中设置java开机自启动_java windows 稳定自启-CSDN博客
4.查看相关端口是否被占用就证自启成功
java:    netstat -ano | findstr 8092
nginx:   netstat -ano | findstr 80

linux版:

以docker为例
1.安装相关镜像
dockerfile:

# 基础镜像
FROM  openjdk:8-jre
# author
MAINTAINER hejiale

# 挂载目录
VOLUME /usr/local/YiZhanShi
# 创建目录
RUN mkdir -p /usr/local/YiZhanShi
# 指定路径
WORKDIR /usr/local/YiZhanShi
# 复制jar文件到路径
COPY ./jar/bishe-gateway.jar /usr/local/YiZhanShi/bishe-gateway.jar
# 启动网关服务
ENTRYPOINT ["java","-jar","bishe-gateway.jar"]
 # 基础镜像
FROM mysql:8.0.30
# author
MAINTAINER hejiale

# 执行sql脚本
ADD ./db/*.sql /docker-entrypoint-initdb.d/


# 基础镜像
FROM nacos/nacos-server:v2.3.0
# author
MAINTAINER hejiale

# 复制conf文件到路径
COPY ./conf/application.properties /home/nacos/conf/application.properties



# 基础镜像
FROM nginx
# author
MAINTAINER ruoyi

# 挂载目录
VOLUME /home/ruoyi/projects/yizhanshi-ui
# 创建目录
RUN mkdir -p /home/ruoyi/projects/yizhanshi-ui
# 指定路径
WORKDIR /home/ruoyi/projects/yizhanshi-ui
# 复制conf文件到路径
COPY ./conf/nginx.conf /etc/nginx/nginx.conf
# 复制html文件到路径
COPY ./html/dist /home/ruoyi/projects/yizhanshi-ui


# 基础镜像
FROM redis:7.2
# author
MAINTAINER hejiale

# 挂载目录
VOLUME /usr/local/YiZhanShi/redis
# 创建目录
RUN mkdir -p /usr/local/YiZhanShi/redis
# 指定路径
WORKDIR /usr/local/YiZhanShi/redis
# 复制conf文件到路径
COPY ./conf/redis.conf /usr/local/YiZhanShi/redis/redis.conf


2.配置docker-compose.yml启动镜像

# 使用时,用容器名称:容器端口号访问
version : '3.8'
services:
  yizhanshi-nacos:
    container_name: yizhanshi-nacos
    image: nacos/nacos-server:v2.3.0
    build:
      context: ./nacos
    environment:
      - MODE=standalone
    volumes:
      - ./nacos/logs:/home/nacos/logs
      - ./nacos/conf/application.properties:/home/nacos/conf/application.properties
    ports:
      - "8848:8848"
      - "9848:9848"
      - "9849:9849"
    depends_on:
      - yizhanshi-mysql
    mem_limit: 1000m

  yizhanshi-mysql:
    container_name: yizhanshi-mysql
    image: mysql:8.0.30
    build:
      context: ./mysql
    ports:
      - "13306:3306"
    volumes:
      - ./mysql/conf/my.cnf:/etc/mysql/my.cnf
      - ./mysql/logs:/var/logs/mysql
      - ./mysql/data:/var/lib/mysql
    command: [
          'mysqld',
          '--innodb-buffer-pool-size=100M',
          '--character-set-server=utf8mb4',
          '--collation-server=utf8mb4_unicode_ci',
          '--default-time-zone=+8:00',
          '--lower-case-table-names=1'
        ]
    environment:
      MYSQL_DATABASE: 'yizhanshi-system'
      MYSQL_ROOT_PASSWORD: Nwafu_176012
    mem_limit: 700m

  yizhanshi-redis:
    container_name: yizhanshi-redis
    image: redis:7.2
    build:
      context: ./redis
    ports:
      - "16379:6379"
    volumes:
      - ./redis/redis.conf:/etc/redis/redis.conf
      - ./redis/data:/data
    mem_limit: 400m

#  yizhanshi-nginx:
#    container_name: yizhanshi-nginx
#    image: nginx
#    build:
#      context: ./nginx
#    ports:
#      - "80:80"
#    volumes:
#      - ./nginx/html/dist:/home/yizhanshi/projects/yizhanshi-ui
#      - ./nginx/conf/nginx.conf:/etc/nginx/nginx.conf
#      - ./nginx/logs:/var/log/nginx
#      - ./nginx/conf.d:/etc/nginx/conf.d
#    depends_on:
#      - yizhanshi-gateway
#    links:
#      - yizhanshi-gateway
  yizhanshi-gateway:
    container_name: yizhanshi-gateway
    build:
      context: ./yizhanshi/gateway
      dockerfile: dockerfile
    ports:
      - "18080:8080"
    depends_on:
      - yizhanshi-redis
    links:
      - yizhanshi-redis
    mem_limit: 500m

  yizhanshi-auth:
    container_name: yizhanshi-auth
    build:
      context: ./yizhanshi/auth
      dockerfile: dockerfile
    ports:
      - "9200:9200"
    depends_on:
      - yizhanshi-redis
    links:
      - yizhanshi-redis
    mem_limit: 500m

  yizhanshi-modules-system:
    container_name: yizhanshi-modules-system
    build:
      context: ./yizhanshi/modules/system
      dockerfile: dockerfile
    ports:
      - "9201:9201"
    depends_on:
      - yizhanshi-redis
      - yizhanshi-mysql
    links:
      - yizhanshi-redis
      - yizhanshi-mysql
    mem_limit: 500m

  yizhanshi-place:
    container_name: yizhanshi-place
    build:
      context: ./yizhanshi/modules/place
      dockerfile: dockerfile
    ports:
      - "9202:9202"
    depends_on:
      - yizhanshi-mysql
    links:
      - yizhanshi-mysql
    mem_limit: 500m

  yizhanshi-course:
    container_name: yizhanshi-course
    build:
      context: ./yizhanshi/modules/course
      dockerfile: dockerfile
    ports:
      - "9203:9203"
    depends_on:
      - yizhanshi-mysql
    links:
      - yizhanshi-mysql
    mem_limit: 500m

  yizhanshi-talent:
    container_name: yizhanshi-talent
    build:
      context: ./yizhanshi/modules/talent
      dockerfile: dockerfile
    ports:
      - "9204:9204"
    depends_on:
      - yizhanshi-mysql
      - yizhanshi-redis
    links:
      - yizhanshi-mysql
      - yizhanshi-redis
    mem_limit: 500m

  yizhanshi-lost:
    container_name: yizhanshi-lost
    build:
      context: ./yizhanshi/modules/lost
      dockerfile: dockerfile
    ports:
      - "9205:9205"
    depends_on:
      - yizhanshi-mysql
    links:
      - yizhanshi-mysql
    mem_limit: 500m

  yizhanshi-modules-file:
    container_name: yizhanshi-modules-file
    build:
      context: ./yizhanshi/modules/file
      dockerfile: dockerfile
    ports:
      - "9300:9300"
    mem_limit: 400m
    volumes:
    - /usr/local/YiZhanShi/FileData:/usr/local/YiZhanShi/FileData

  yizhanshi-visual-monitor:
    container_name: yizhanshi-visual-monitor
    build:
      context: ./yizhanshi/visual/monitor
      dockerfile: dockerfile
    ports:
      - "9100:9100"
    mem_limit: 400m

3.编写deploy.sh脚本或者copy.sh脚本,做自动化部署

copy.sh

#!/bin/sh

# 复制项目的文件到对应docker路径,便于一键生成镜像。
usage() {
	echo "Usage: sh copy.sh"
	exit 1
}


# copy sql
#echo "begin copy sql "
#cp ../sql/yizhanshi-system-202403031520.sql ./mysql/db
#cp ../sql/yizhanshi-nacos-config-202403031522.sql ./mysql/db

# copy html
#echo "begin copy html "
#cp -r ../yizhanshi-ui/dist/** ./nginx/html/dist


# copy jar
echo "begin copy bishe-gateway "
cp ../target/bishe-gateway.jar ./yizhanshi/gateway/jar

echo "begin copy bishe-auth "
cp ../target/bishe-auth.jar ./yizhanshi/auth/jar

echo "begin copy yizhanshi-visual "
cp ../target/bishe-visual-monitor.jar  ./yizhanshi/visual/monitor/jar

echo "begin copy bishe-modules-system "
cp ../target/bishe-modules-system.jar ./yizhanshi/modules/system/jar

echo "begin copy yizhanshi-place "
cp ../target/yizhanshi-place.jar ./yizhanshi/modules/place/jar

echo "begin copy yizhanshi-course "
cp ../target/yizhanshi-course.jar ./yizhanshi/modules/course/jar

echo "begin copy yizhanshi-talent "
cp ../target/yizhanshi-talent.jar ./yizhanshi/modules/talent/jar

echo "begin copy yizhanshi-lost "
cp ../target/yizhanshi-lost.jar ./yizhanshi/modules/lost/jar

echo "begin copy bishe-modules-file "
cp ../target/bishe-modules-file.jar ./yizhanshi/modules/file/jar
#
#echo "begin copy yizhanshi-modules-job "
#cp ../yizhanshi-modules/yizhanshi-job/target/yizhanshi-modules-job.jar ./yizhanshi/modules/job/jar
#
#echo "begin copy yizhanshi-modules-gen "
#cp ../yizhanshi-modules/yizhanshi-gen/target/yizhanshi-modules-gen.jar ./yizhanshi/modules/gen/jar

deploy.sh

#!/bin/sh
#删除镜像
#docker rmi docker-yizhanshi-modules-system docker-yizhanshi-talent:latest docker-yizhanshi-auth docker-yizhanshi-lost docker-yizhanshi-place docker-yizhanshi-course:latest  docker-yizhanshi-gateway docker-yizhanshi-modules-file:latest
# 使用说明,用来提示输入参数
usage() {
	echo "Usage: sh 执行脚本.sh [port|base|modules|stop|rm]"
	exit 1
}

# 开启所需端口
port(){
	firewall-cmd --add-port=80/tcp --permanent
	firewall-cmd --add-port=8080/tcp --permanent
	firewall-cmd --add-port=8848/tcp --permanent
	firewall-cmd --add-port=9848/tcp --permanent
	firewall-cmd --add-port=9849/tcp --permanent
	firewall-cmd --add-port=6379/tcp --permanent
	firewall-cmd --add-port=3306/tcp --permanent
	firewall-cmd --add-port=9100/tcp --permanent
	firewall-cmd --add-port=9200/tcp --permanent
	firewall-cmd --add-port=9201/tcp --permanent
	firewall-cmd --add-port=9202/tcp --permanent
	firewall-cmd --add-port=9203/tcp --permanent
	firewall-cmd --add-port=9300/tcp --permanent
	service firewalld restart
}

# 启动基础环境(必须)
base(){
	docker-compose up -d yizhanshi-mysql yizhanshi-redis yizhanshi-nacos
}

# 启动程序模块(必须)
modules(){
	docker-compose up -d yizhanshi-modules-file yizhanshi-gateway yizhanshi-auth yizhanshi-modules-system yizhanshi-place yizhanshi-course yizhanshi-talent yizhanshi-lost
}
visual(){
	docker-compose up -d yizhanshi-visual-monitor
}
# 关闭所有环境/模块
stop(){
	docker-compose stop
}
# 关闭基础环境/模块
stopNacos(){
	docker-compose stop yizhanshi-nacos
}
# 关闭业务环境/模块
stopBusiness(){
	docker-compose stop yizhanshi-modules-file yizhanshi-gateway yizhanshi-auth yizhanshi-modules-system yizhanshi-place yizhanshi-lost   yizhanshi-course yizhanshi-talent
}
stopVisual(){
	docker-compose stop yizhanshi-visual-monitor
}

# 删除所有环境/模块
rm(){
	docker-compose rm
}
# 删除基础环境/模块
rmNacos(){
	docker-compose rm yizhanshi-nacos
}
# 删除所有环境/模块
rmBusiness(){
	docker-compose rm yizhanshi-modules-file yizhanshi-gateway yizhanshi-auth yizhanshi-modules-system yizhanshi-place yizhanshi-course yizhanshi-talent yizhanshi-lost  yizhanshi-visual-monitor
}
rmVisual(){
	docker-compose rm yizhanshi-visual-monitor
}

# 根据输入参数,选择执行对应方法,不输入则执行使用说明
case "$1" in
"port")
	port
;;
"base")
	base
;;
"modules")
	modules
;;
"visual")
	visual
;;
"stop")
	stop
;;
"stopNacos")
	stopNacos
;;
"stopBusiness")
	stopBusiness
;;
"stopVisual")
	stopVisual
;;
"rm")
	rm
;;
"rmNacos")
	rmNacos
;;
"rmBusiness")
	rmBusiness
;;
"rmVisual")
	rmVisual
;;
*)
	usage
;;
esac

4.运行只需要,先在copy.sh和deploy.sh文件夹下进行命令
sh copy.sh -> sh deploy.sh  base/modules 即可
5.结构:

注意:如果条件不允许前后端局域网内开发,每次都需要部署,每次上传新jar包时,必须先删除镜像(docker rmi yizhanshi-gateway:latest),再进行sh deploy.sh modules之类的命令,重新打镜像。

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

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

相关文章

mapboxGL中山体背景+边界阴影的一种实现方案

概述 很多地图可视化的项目中有要求实现如下的效果,本文借助QGIS、PS和turf.js,在mapboxGL中实现山体背景+边界阴影的效果。 实现效果 实现 1. 需要数据 要实现这样的效果,我们需要如下数据: 山体背景图地级市数据…

[卷积神经网络]RepConv和重参数化

RepConv是Yolov7,YoloV9中一个重要的结构,其主要用于在保持精度不退化的情况下提升推理速度。RepConv在学习阶段和推理阶段拥有不同的结构,这使得其推理阶段的复杂度大大降低。这项技术的核心在于重参数化。 一、重参数化 重参数化的主要思想是将卷积(C…

2024年弘连网络FIC大会竞赛题线下决赛题

总结: FIC决赛的时候,很多小问题没发现,在pve平台做题确实很方便。 这套题目复盘完,服务器这块的知识确实收获了很多,对pve集群平台和网络拓扑也有了一定的认识,感谢各位大佬悉心指导。 接下来&#xff0…

工具使用-网络性能测试工具(iperf)-TCP 和 UDP 的吞吐量-包转发率参数的理解

时间戳:2024年5月26日15:18:39 iperf 和 netperf 都是最常用的网络性能测试工具,测试 TCP 和 UDP 的吞吐量。它们都以客户端和服务器通信的方式,测试一段时间内的平均吞吐量。 接下来,我们就以 iperf 为例,看一下 TC…

C语言PTA练习题:三角形类别,输入三角形三条边,求面积,四则计算器,猴子吃桃

7-1 三角形类别 输入三个整数,以这三个数为边长,判断是否构成三角形;若不能输出"no",若构成三角形,进一步判断它们构的是:锐角三角形或直角三角形或钝角三角形.分别输出"ruijiao",&qu…

Spring MVC+mybatis项目入门:旅游网(四)用户注册——mybatis的配置与使用以及Spring MVC重定向

个人博客:Spring MVCmybatis项目入门:旅游网(四)用户注册2-持久化 | iwtss blog 先看这个! 这是18年的文章,回收站里恢复的,现阶段看基本是没有参考意义的,技术老旧脱离时代(2024年…

qt-C++笔记之QThread使用

qt-C笔记之QThread使用 ——2024-05-26 下午 code review! 参考博文: qt-C笔记之使用QtConcurrent异步地执行槽函数中的内容,使其不阻塞主界面 qt-C笔记之QThread使用 文章目录 qt-C笔记之QThread使用一:Qt中几种多线程方法1.1. 使用 QThread 和 Lambda…

【二叉树】LeetCode.144:二叉树的前序遍历(小细节把握)

🎁个人主页:我们的五年 🔍系列专栏:初阶初阶结构刷题 🎉欢迎大家点赞👍评论📝收藏⭐文章 目录 1.题目描述:​编辑 2.问题分析: 🍔函数解读: …

功率电感的设计步骤

文章目录 1:高导磁气隙(铁氧体)1.1设计原理1.2 设计步骤 2 铁粉芯2.1:设计原理2.2:设计步骤 TI电感设计 学习视频原链接 截图 1 截图1 截图1 截图 2 截图2 截图2 1:高导磁气隙(铁氧体&#…

solidworks画螺栓学习笔记

螺栓 单位mm 六边形 直径16mm 水平约束 拉伸 选择厚度6mm 拉伸切除 画相切圆 切除厚度6mm,反向切除 ,拔模角度45 螺栓 直径9mm,长度30mm 倒角 直径1mm,角度45 异形孔向导 螺纹线 偏移打勾,距离为2mm&#…

【C语言】八进制、十六进制

前言 在我们日常生活中使用的数往往是十进制的,而当我们学习C语言后我们会接触到许多不同的进制并且时常需要去思考与使用这些不同的进制(尤其是2的幂相关的进制,因为这种计数系统比十进制更接近于计算机的二进制系统)&#xff0…

牛客网刷题 | BC100 直角三角形图案

目前主要分为三个专栏,后续还会添加: 专栏如下: C语言刷题解析 C语言系列文章 我的成长经历 感谢阅读! 初来乍到,如有错误请指出,感谢! 描述 KiKi学习了循环&am…

爽!AI手绘变插画,接单赚爆了!

我最近发现一款名叫Hyper-SD15-Scribble的AI项目,可以实现一键手绘变插画的功能,而且它搭载了字节出品的超快速生成图片的AI大模型Hyper-SD15,可以实现几乎实时生成图片,有了它,拿去接一些手绘商单分分钟出图&#xff…

java生产制造执行系统MES源码:系统环境:Java EE 8、Servlet 3.0、Apache Maven 3 2;

MES系统技术选型 系统环境:Java EE 8、Servlet 3.0、Apache Maven 3 2; 主框架:Spring Boot 2.2.x、Spring Framework 5.2.x、Spring Security 5.2.x 3 持久层:Apache MyBatis 3.5.x、Hibernate Validation 6.0.x、Alibaba Dru…

基于STM32实现智能气体检测报警系统

⬇帮大家整理了单片机的资料 包括stm32的项目合集【源码开发文档】 点击下方蓝字即可领取,感谢支持!⬇ 点击领取更多嵌入式详细资料 问题讨论,stm32的资料领取可以私信! 目录 引言环境准备智能气体检测报警系统基础代码示例&…

ZDH-智能营销-插件服务

目录 主题 项目源码 预览地址 安装包下载地址 插件服务 插件服务使用场景 插件服务日志 感谢支持 主题 本篇文章主要介绍ZDH-智能营销平台下的插件服务,包含插件的应用场景 项目源码 zdh_web: GitHub - zhaoyachao/zdh_web: 大数据采集,抽取平台 zdh_magic_mirror: …

AIGC002-LoRA让大模型微调更加轻盈方便!

AIGC002-LoRA让大模型微调更加轻盈方便! 文章目录 0 论文工作1 论文方法2 效果 0 论文工作 这篇论文名为 LORA: LOW-RANK ADAPTATION OF LARGE LANGUAGE MODELS,作者是 Edward Hu 等人。它提出了一种名为 低秩自适应 (Low-Rank Adaptation, LoRA) 的新方…

AI 谈“浔川AI翻译机”

在天工AI,天工AI在全网搜索“浔川AI翻译机”。 1 创作助手谈“浔川AI翻译机”: “浔川AI翻译机”是一个利用人工智能技术进行语言翻译的设备或应用程序。它可以将一种语言的文字或口语翻译成另一种语言,以实现不同语言之间的沟通和理解。浔…

网络布线与数制转换

信号与传输介质 信号概述 什么是信号 信息 人对现实世界事物存在方式或运动状态的某种认识 数据 用于描述事物的某些属性的具体量值 信号 信息传递的媒介 例如,描述某一件物体,它的长、宽、高、质地、颜色、气味等就是用以形容该物体的数据。通…