# 一、后端打包 ## 服务 - 基础服务 - 网关服务procatch-gateway - 文件服务procatch-modules-file - 认证服务procatch-auth - 核心服务 - 用户服务procatch-modules-system - 资源服务procatch-resource - 业务服务 - 运维服务procatch-work-om ### 后端打包错误整理 - 2023-03-30 - 建项目的时候工程目录包结构顺序错误,导致打包找不到启动类。解决办法:把顺序调对。以后建项目要仔细。 - 通过端口可以访问服务,但通过网关不行,检查nacos网关配置,修改子系统路径前缀 ## 数据 ## 权限文件 # 二、前端打包 ```bash npm run build ``` # 三、服务器环境 ## 1. 系统Debian11 - 换源 ```bash echo "deb http://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb-src http://mirrors.aliyun.com/debian/ bullseye main non-free contrib deb http://mirrors.aliyun.com/debian-security/ bullseye-security main deb-src http://mirrors.aliyun.com/debian-security/ bullseye-security main deb http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb-src http://mirrors.aliyun.com/debian/ bullseye-updates main non-free contrib deb http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib deb-src http://mirrors.aliyun.com/debian/ bullseye-backports main non-free contrib" > sources.list apt-get update ``` ## 2. Docker ```bash sudo apt-get install docker-compose #查看Docker可用用户 sudo cat /etc/group |grep docker # docker:x:998:表示存在 sudo groupadd docker sudo usermod -aG docker $USER newgrp docker # 激活组更改,无效的话尝试重连ssh,退出登录,重启计算机等 ``` ## 3.Java8 ```bash # windows # 上传java文件到服务器 scp jdk-8u361-linux-x64.tar.gz snow@192.168.1.200:~/. # Linux sudo mv jdk-8u361-linux-x64.tar.gz /opt/. # 解压 cd /opt/ tar zxvf jdk-8u361-linux-x64.tar.gz # 配置环境变量 echo "export JAVA_HOME=/opt/jdk1.8.0_361 export PATH=$JAVA_HOME/bin:$PATH" >> /etc/profile # 即时生效配置 source /etc/profile ``` ## 4. MySQL5.7 ```bash # 创建Docker文件存储点 cd ~ mkdir DockerData cd DockerData mdkir mysql5.7 cd mysql5.7 mkdir log mkdir data mkdir conf nowpath=$(pwd) # 运行docker docker run -d --name mysql5.7 \ --restart=always \ -v $nowpath/data:/var/lib/mysql \ -v $nowpath/conf:/etc/mysql/conf.d \ -v $nowpath/log:/logs \ -e MYSQL_ROOT_PASSWORD=root \ -p 3306:3306 \ mysql:5.7 # 设置开机自启动 docker update --restart=always mysql5.7 docker cp /usr/share/zoneinfo/Asia/Shanghai mysql5.7:etc/localtime docker restart ``` ## 5. Nacos ```bash #docker版 cd ~/DockerData mdkir nacos cd nacos mkdir log mkdir data mkdir conf nowpath=$(pwd) # 写入配置文件 touch conf/application.properties echo " server.servlet.contextPath=/nacos server.error.include-message=ON_PARAM server.port=8848 db.pool.config.connectionTimeout=30000 db.pool.config.validationTimeout=10000 db.pool.config.maximumPoolSize=20 db.pool.config.minimumIdle=2 nacos.naming.empty-service.auto-clean=true nacos.naming.empty-service.clean.initial-delay-ms=50000 nacos.naming.empty-service.clean.period-time-ms=30000 management.endpoints.web.exposure.include=* management.metrics.export.elastic.enabled=false management.metrics.export.influx.enabled=false server.tomcat.accesslog.enabled=true server.tomcat.accesslog.pattern=%h %l %u %t "%r" %s %b %D %{User-Agent}i %{Request-Source}i server.tomcat.basedir=file:. nacos.security.ignore.urls=/,/error,/**/*.css,/**/*.js,/**/*.html,/**/*.map,/**/*.svg,/**/*.png,/**/*.ico,/console-ui/public/**,/v1/auth/**,/v1/console/health/**,/actuator/**,/v1/console/server/** nacos.core.auth.system.type=nacos nacos.core.auth.enabled=false nacos.core.auth.caching.enabled=true nacos.core.auth.enable.userAgentAuthWhite=false nacos.core.auth.server.identity.key=serverIdentity nacos.core.auth.server.identity.value=security nacos.core.auth.plugin.nacos.token.expire.seconds=18000 nacos.core.auth.plugin.nacos.token.secret.key=SecretKey012345678901234567890123456789012345678901234567890123456789 nacos.istio.mcp.server.enabled=false spring.datasource.platform=mysql db.num=1 db.url.0=jdbc:mysql://192.168.1.201:3306/procatch-config?characterEncoding=utf8&connectTimeout=1000&socketTimeout=3000&autoReconnect=true&useUnicode=true&useSSL=false&serverTimezone=UTC db.user=root db.password=root" > conf/application.properties # 运行docker docker run \ --name nacos -d \ -p 8848:8848 \ -p 9848:9848 \ --privileged=true \ --restart=always \ -e JVM_XMS=256m \ -e JVM_XMX=256m \ -e MODE=standalone \ -e PREFER_HOST_MODE=10.10.10.20 \ -v $nowpath/log:/home/nacos/logs \ -v $nowpath/conf/application.properties:/home/nacos/conf/application.properties \ -v $nowpath/data:/home/nacos/data \ nacos/nacos-server # 设置开机自启动 docker update --restart=always nacos ``` ## 6. redis ```bash mkdir redis cd redis/ mkdir log mkdir data mkdir conf echo "# Redis配置文件 # Redis默认不是以守护进程的方式运行,可以通过该配置项修改,使用yes启用守护进程 daemonize no # 指定Redis监听端口,默认端口为6379 port 6379 # 绑定的主机地址,不要绑定容器的本地127.0.0.1地址,因为这样就无法在容器外部访问 bind 0.0.0.0 #需要密码则打开 # requirepass mima # 持久化 # appendonly yes" > conf/redis.conf nowpath=$(pwd) docker run -d -p 6379:6379 \ --name redis \ -v $nowpath/conf/redis.conf:/etc/redis/redis.conf \ -v $nowpath/data:/data \ redis \ redis-server /etc/redis/redis.conf docker update --restart=always redis ``` ## 7. Nginx ```bash sudo apt-get install nginx sudo systemctl enable nginx sudo systemctl start nginx # 配置文件在/etc/nginx/nginxconf ``` # 四、部署和运行 1. 将各模块包上传至服务器 - 后端jar包放在latest文件夹下 - 前端文件直接放在项目根目录下 ```bash # 创建项目文件夹 mkdir ProCatch5_Test cd ProCatch5_Test mkdir latest mkdir log mkdir PID.d ``` 目录结构为 ```bash ├── latest ├── log ├── PID.d └── start.sh ``` - start.sh为最初后台服务启动文件 ```bash #! start.sh echo "等待网管启动 ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-gateway.jar > ./log/procatch-gateway.log 2>&1 & echo $! > ./PID.d/procatch-gateway.pid & sleep 15 echo "procatch-auth ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-auth.jar > ./log/procatch-auth.log 2>&1 & echo $! > ./PID.d/procatch-auth.pid & sleep 5 echo "procatch-modules-file ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-modules-file.jar > ./log/procatch-modules-file.log 2>&1 & echo $! > ./PID.d/procatch-modules-file.pid & sleep 5 echo "procatch-modules-system ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-modules-system.jar > ./log/procatch-modules-system.log 2>&1 & echo $! > ./PID.d/procatch-modules-system.pid & sleep 5 echo "procatch-resource ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-resource.jar > ./log/procatch-procatch-resource.log 2>&1 & echo $! > ./PID.d/procatch-resource.pid & sleep 5 echo "procatch-work-om ==>" nohup java -jar -Xms512m -Xmx512m ./latest/procatch-work-om.jar > ./log/procatch-work-om.log 2>&1 & echo $! > ./PID.d/procatch-work-om.pid & sleep 5 ``` dist.zip为前端包文件 - 解压 ```bash unzip dist.zip #生成 dist文件夹 ``` 2. 启动服务 ```bash chmod +x start.sh ./start.sh ``` - 生成的一些日志文件 ```bash . ├── dist # 前端文件夹 │   ├── assets ├── dist.zip # 前端文件包 ├── latest # 后端包存放文件夹 │   ├── procatch-auth.jar │   ├── procatch-gateway.jar │   ├── procatch-modules-file.jar │   ├── procatch-modules-system.jar │   ├── procatch-resource.jar │   └── procatch-work-om.jar ├── log # 启动时日志 │   ├── procatch-auth.log │   ├── procatch-gateway.log │   ├── procatch-modules-file.log │   ├── procatch-modules-system.log │   ├── procatch-procatch-resource.log │   ├── procatch-work-om-3.6.1.log │   └── procatch-work-om.log ├── logs # 运行时日志 │   ├── procatch-auth │   │   ├── error.2023-03-29.log │   │   ├── error.log │   │   └── info.log │   ├── procatch-file │   │   ├── error.log │   │   └── info.log │   ├── procatch-gateway │   │   ├── error.2023-03-29.log │   │   ├── error.log │   │   ├── info.2023-03-29.log │   │   └── info.log │   ├── procatch-source │   │   ├── error.2023-03-29.log │   │   ├── error.log │   │   └── info.log │   ├── procatch-system │   │   ├── error.2023-03-29.log │   │   ├── error.log │   │   └── info.log │   └── procatch-work-om │   ├── error.2023-03-29.log │   ├── error.log │   ├── info.2023-03-29.log │   ├── info.log │   ├── warn.2023-03-29.log │   └── warn.log ├── PID.d # 进程号文件夹 │   ├── procatch-auth.pid │   ├── procatch-gateway.pid │   ├── procatch-modules-file.pid │   ├── procatch-modules-system.pid │   ├── procatch-resource.pid │   └── procatch-work-om.pid └── start.sh ``` # 四、系统配置 - 需要在naos各个服务配置上进行改动,主要为更改数据库地址、密码,redis地址以及各个子系统的路径前缀和端口调整