准备工作 - 确认端口
后端
data-project 项目后端 8007
data-web 项目前端 8010
xxxx-job-admin 定时任务 8026~9029
前端
Nginx 监听端口 8010
后端代码
环境变量参数设置
spring.datasource.url= $ {URL:jdbc:mysql://xxxx:xxxx/xxxxx?serverTimezone=GMT %2B8&useUnicode=true&characterEncoding=utf-8}
spring.datasource.username= $ {USERNAME:root}
spring.datasource.password= $ {PASSWORD:xxxxx}
spring.datasource.driverClassName= $ {DRIVER_CLASSNAME:com.mysql.cj.jdbc.Driver}
重点:$ {URL: xxxx } 设置值为 先引用环境变量,没有环境变量默认为 xxxx
脚本
项目打包后(assembly),在压缩包的bin目录下有五个sh文件,主要修改start.sh和env.sh
start.sh
#!/bin/sh
cd `dirname $0`
BIN_DIR=`pwd`
cd ..
DEPLOY_DIR=`pwd`
## 项目名称
APP_NAME=data-assets-server-2.1.0-SNAPSHOT
## 文件位置
APP_DIR="${DEPLOY_DIR}/lib"
rm -f tpid
## 环境变量
source ${DEPLOY_DIR}/bin/env.sh
nohup java -Djava.awt.headless=true -Dnacos.logging.default.config.enabled=false -Dloader.path=/opt/data-asset/data-assets-server-2.1.0-SNAPSHOT/lib/ -Djava.security.egd=file:/dev/./urandom --add-opens java.base/java.lang=ALL-UNNAMED --add-opens java.base/java.lang.reflect=ALL-UNNAMED --add-opens java.base/java.lang.invoke=ALL-UNNAMED --add-opens java.base/java.math=ALL-UNNAMED --add-opens java.base/sun.net.util=ALL-UNNAMED --add-opens java.base/java.io=ALL-UNNAMED --add-opens java.base/java.net=ALL-UNNAMED --add-opens java.base/java.nio=ALL-UNNAMED --add-opens java.base/java.security=ALL-UNNAMED --add-opens java.base/java.text=ALL-UNNAMED --add-opens java.base/java.time=ALL-UNNAMED --add-opens java.base/java.util=ALL-UNNAMED --add-opens java.base/jdk.internal.misc=ALL-UNNAMED --add-opens java.base/java.util.concurrent=ALL-UNNAMED --add-opens java.desktop/java.awt.font=ALL-UNNAMED -Dio.netty.tryReflectionSetAccessible=true -DIIP_HOME=/opt/data-asset/iip-ide-1.0.0-develop/ -jar /opt/data-asset/data-assets-server-2.1.0-SNAPSHOT/lib/data-assets-server-2.1.0-SNAPSHOT.jar --spring.config.additional-location=classpath:props/local/def.properties --server.tomcat.uri-encoding=ISO-8859-1 --server.tomcat.max-threads=400 --server.tomcat.max-http-header-size=8192 >/opt/data-asset/logs/data-asset-server/dasLog.log 2>&1 &
echo $! > tpid
echo Start Success!
解释:
nohup 后台自动运行
–add-opens java.base/java.lang=ALL-UNNAMED
使用JDK17时可能出现不兼容,因此启动时需要设置参数,例如JDK8后数据映射可能报错
2>&1是将标准错误(2)重定向到标准输出(&1),标准输出(&1)再被重定向输入到xxx.log文件中
重点:
source ${DEPLOY_DIR}/bin/env.sh 设置本文件下的env.sh为环境变量文件
-Dloader.path=xxxxxxxxxxx**
设置执行环境
-jar **/opt/data-asset/data-assets-server-2.1.0-SNAPSHOT/lib/data-assets-server-2.1.0-SNAPSHOT.jar
执行jar包位置
/opt/data-asset/logs/data-asset-server/dasLog.log
输出日志位置
env.sh
## 业务应用相关配置参数
## 应用名称
export APPLICATION_NAME='data-assets-server'
#应用编码
export APP_CODE=DAMP
#应用程序运行模式(dev or product)
export APP_MODE=dev
#应用端口
export SERVER_PORT=xxxx
#应用上下文路径
export CONTEXT_PATH=/xxx
## 数据库配置
## 业务数据源
export URL='jdbc:mysql://xxxxxx:xxxx/xxxx?serverTimezone=GMT%2B8&useUnicode=true&characterEncoding=utf-8'
export USERNAME='root'
export PASSWORD='xxxxx'
export DRIVER_CLASSNAME='com.mysql.cj.jdbc.Driver'
重点: 此处设置环境变量,USERNAME PASSWORD等
前端 Nginx.conf
server {
listen xxxx;
server_name xxxxx;
location /main {
alias /etc/nginx/html/main;
try_files $uri $uri/ /etc/nginx/html/main/index.html;
}
location /main/xxxx{
alias /etc/nginx/html/main;
}
location /main/login {
alias /etc/nginx/html/main;
}
location /xxxx-system {
alias /etc/nginx/html/xxxx;
try_files $uri $uri/ /etc/nginx/html/xxxx/index.html;
}
location /das {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers: content-type;
proxy_set_header Host $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_ignore_client_abort on;
proxy_pass http://10.105.52.61:9007/xxx;
client_max_body_size 1000m;
proxy_cookie_path /api /;
}
location /xxxx-app {
add_header Access-Control-Allow-Origin *;
add_header Access-Control-Allow-Headers: content-type;
proxy_set_header Host $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_ignore_client_abort on;
proxy_pass http://10.105.52.61:9013/xxxx-app;
client_max_body_size 1000m;
proxy_cookie_path /api /;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
解释:
location /main
检测网址中的关键字(例如:http://10.105.52.61:9013/main/xxxx/…)
alias /etc/nginx/html/xxxx;
访问资源路径
try_files $uri $uri/ /etc/nginx/html/xxxx/index.html;
资源路径不存在时默认访问
proxy_pass
内网穿透,访问 http://10.105.52.61:9013/xxxx-app;
前端App.js
const list = [
{
"name": "xxxx",
"url": "http://10.105.52.62:9010/xxxx-system/",
"container": "#xxxx",
"label": "系统功能",
"id": "xxxx-system-element-plus"
},
{
"name": "web",
"url": "http://10.105.52.62:9010/web/",
"container": "#web",
"label": "测试低代码子应用",
"id": "xxx-lowcode-app"
}
]
window.microAppList = list
解释:
name为xxxx的网址,真实完整url为 http://10.105.52.62:9010/xxxx-system/
可以看出name是声明,主体以xxxx-system为主
Linux服务器操作
查看端口对应服务
netstat -ntulp | grep 9013
解压压缩包
tar -xzvf xxx.tar.gz