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之类的命令,重新打镜像。