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-nacosimage: nacos/nacos-server:v2.3.0build:context: ./nacosenvironment:- MODE=standalonevolumes:- ./nacos/logs:/home/nacos/logs- ./nacos/conf/application.properties:/home/nacos/conf/application.propertiesports:- "8848:8848"- "9848:9848"- "9849:9849"depends_on:- yizhanshi-mysqlmem_limit: 1000myizhanshi-mysql:container_name: yizhanshi-mysqlimage: mysql:8.0.30build:context: ./mysqlports:- "13306:3306"volumes:- ./mysql/conf/my.cnf:/etc/mysql/my.cnf- ./mysql/logs:/var/logs/mysql- ./mysql/data:/var/lib/mysqlcommand: ['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_176012mem_limit: 700myizhanshi-redis:container_name: yizhanshi-redisimage: redis:7.2build:context: ./redisports:- "16379:6379"volumes:- ./redis/redis.conf:/etc/redis/redis.conf- ./redis/data:/datamem_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-gatewayyizhanshi-gateway:container_name: yizhanshi-gatewaybuild:context: ./yizhanshi/gatewaydockerfile: dockerfileports:- "18080:8080"depends_on:- yizhanshi-redislinks:- yizhanshi-redismem_limit: 500myizhanshi-auth:container_name: yizhanshi-authbuild:context: ./yizhanshi/authdockerfile: dockerfileports:- "9200:9200"depends_on:- yizhanshi-redislinks:- yizhanshi-redismem_limit: 500myizhanshi-modules-system:container_name: yizhanshi-modules-systembuild:context: ./yizhanshi/modules/systemdockerfile: dockerfileports:- "9201:9201"depends_on:- yizhanshi-redis- yizhanshi-mysqllinks:- yizhanshi-redis- yizhanshi-mysqlmem_limit: 500myizhanshi-place:container_name: yizhanshi-placebuild:context: ./yizhanshi/modules/placedockerfile: dockerfileports:- "9202:9202"depends_on:- yizhanshi-mysqllinks:- yizhanshi-mysqlmem_limit: 500myizhanshi-course:container_name: yizhanshi-coursebuild:context: ./yizhanshi/modules/coursedockerfile: dockerfileports:- "9203:9203"depends_on:- yizhanshi-mysqllinks:- yizhanshi-mysqlmem_limit: 500myizhanshi-talent:container_name: yizhanshi-talentbuild:context: ./yizhanshi/modules/talentdockerfile: dockerfileports:- "9204:9204"depends_on:- yizhanshi-mysql- yizhanshi-redislinks:- yizhanshi-mysql- yizhanshi-redismem_limit: 500myizhanshi-lost:container_name: yizhanshi-lostbuild:context: ./yizhanshi/modules/lostdockerfile: dockerfileports:- "9205:9205"depends_on:- yizhanshi-mysqllinks:- yizhanshi-mysqlmem_limit: 500myizhanshi-modules-file:container_name: yizhanshi-modules-filebuild:context: ./yizhanshi/modules/filedockerfile: dockerfileports:- "9300:9300"mem_limit: 400mvolumes:- /usr/local/YiZhanShi/FileData:/usr/local/YiZhanShi/FileDatayizhanshi-visual-monitor:container_name: yizhanshi-visual-monitorbuild:context: ./yizhanshi/visual/monitordockerfile: dockerfileports:- "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/jarecho "begin copy bishe-auth "
cp ../target/bishe-auth.jar ./yizhanshi/auth/jarecho "begin copy yizhanshi-visual "
cp ../target/bishe-visual-monitor.jar ./yizhanshi/visual/monitor/jarecho "begin copy bishe-modules-system "
cp ../target/bishe-modules-system.jar ./yizhanshi/modules/system/jarecho "begin copy yizhanshi-place "
cp ../target/yizhanshi-place.jar ./yizhanshi/modules/place/jarecho "begin copy yizhanshi-course "
cp ../target/yizhanshi-course.jar ./yizhanshi/modules/course/jarecho "begin copy yizhanshi-talent "
cp ../target/yizhanshi-talent.jar ./yizhanshi/modules/talent/jarecho "begin copy yizhanshi-lost "
cp ../target/yizhanshi-lost.jar ./yizhanshi/modules/lost/jarecho "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 --permanentfirewall-cmd --add-port=8080/tcp --permanentfirewall-cmd --add-port=8848/tcp --permanentfirewall-cmd --add-port=9848/tcp --permanentfirewall-cmd --add-port=9849/tcp --permanentfirewall-cmd --add-port=6379/tcp --permanentfirewall-cmd --add-port=3306/tcp --permanentfirewall-cmd --add-port=9100/tcp --permanentfirewall-cmd --add-port=9200/tcp --permanentfirewall-cmd --add-port=9201/tcp --permanentfirewall-cmd --add-port=9202/tcp --permanentfirewall-cmd --add-port=9203/tcp --permanentfirewall-cmd --add-port=9300/tcp --permanentservice 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之类的命令,重新打镜像。