添加 va_test 数据库
![[Pasted image 20250517105153.png]]

### 配置数据库权限

切换 root 账户权限
```bsh
sudo su
```

进入mysql 数据库容器中
```
docker exec -it fe8fde9961b2 /bin/bash
```

使用root账户登陆mysql
```bash
mysql -u root -p
# 输入密码
```

创建 va_test 数据库访问账户
```sql
CREATE USER 'va_test'@'%' IDENTIFIED BY 'PGsCkBBc7XBxtrhW';
```

分配数据库操作权限
```sql
GRANT ALL PRIVILEGES ON va_test.* TO 'va_test'@'%';

FLUSH PRIVILEGES; 刷新数据库权限表
```

## 初始化数据库

打开 /www/dk_project/dk_app/mysql/mysql_PfsC/data/ 路径；

上传初始化文件
![[va_test_2025-05-15_09-30-02_mysql_data.sql.gz]]

切换 root 账户权限
```bsh
sudo su
```

执行初始化命令
```bash
gunzip -c /www/dk_project/dk_app/mysql/mysql_PfsC/data/va_test_2025-05-15_09-30-02_mysql_data.sql.gz | docker exec -i fe8fde9961b2 mysql -uva_test -pPGsCkBBc7XBxtrhW va_test
```

## 部署

- 前端 /www/wwwroot/va_admin_frontend_diy
- 后端 /www/wwwroot/va_admin_server_diy

部署角色： root

创建node执行服务
![[Pasted image 20250517133251.png]]

编写nginx
```nginx
server
{
    listen 80;
		listen 443 ssl http2;
    server_name sand-va.fusionpay.one;
    index index.html index.htm default.htm default.html;
    root /www/wwwroot/va_admin_frontend_diy/dist/;
    location / {
      index  index.html index.htm;
	    try_files $uri $uri/ @router;
    }
    location @router {
        rewrite ^.*$ /index.html last;
    }
    
    #SSL-START SSL related configuration
    #error_page 404/404.html;
    ssl_certificate    /www/server/panel/vhost/cert/va_admin_server_test/fullchain.pem;
    ssl_certificate_key    /www/server/panel/vhost/cert/va_admin_server_test/privkey.pem;
    ssl_protocols TLSv1.1 TLSv1.2 TLSv1.3;
    ssl_ciphers EECDH+CHACHA20:EECDH+CHACHA20-draft:EECDH+AES128:RSA+AES128:EECDH+AES256:RSA+AES256:EECDH+3DES:RSA+3DES:!MD5;
    ssl_prefer_server_ciphers on;
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    add_header Strict-Transport-Security "max-age=31536000";
    error_page 497  https://$host$request_uri;
		#SSL-END
    
    #ERROR-PAGE-START  Error page related configuration
    #error_page 404 /404.html;
    #error_page 502 /502.html;
    #ERROR-PAGE-END
    
    
    #REWRITE-START Pseudo-static related configuration
    include /www/server/panel/vhost/rewrite/node_va_admin_server_test.conf;
    #REWRITE-END
    
    #Files or directories forbidden to access
    location ~ ^/(\.user.ini|\.htaccess|\.git|\.svn|\.project|LICENSE|README.md|package.json|package-lock.json|\.env|node_modules) {
        return 404;
    }
    
    #One-click application for SSL certificate verification directory related settings
    location /.well-known/ {
        root  /www/wwwroot/va_admin_server_diy/;
    }

    # HTTP reverse proxy related settings begin >>>
    location ~ /purge(/.*) {
        proxy_cache_purge cache_one $host$request_uri$is_args$args;
    }

    location /api/ {
        proxy_pass http://127.0.0.1:8009/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    location /openApi/ {
        proxy_pass http://127.0.0.1:8009/api/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }

    location /open-api/ {
        proxy_pass http://127.0.0.1:8009/api/open/;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    location /api-doc/ {
        proxy_pass http://127.0.0.1:8009/swagger-ui/index.html;
        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header REMOTE-HOST $remote_addr;
        add_header X-Cache $upstream_cache_status;

        proxy_connect_timeout 30s;
        proxy_read_timeout 86400s;
        proxy_send_timeout 30s;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
    # End of HTTP reverse proxy related settings <<<
    
    access_log  /www/wwwlogs/va_admin_server_test.log;
    error_log  /www/wwwlogs/va_admin_server_test.error.log;
}
```



## 补充
### 自动生成 zip

#### shell 脚本
```bash
#!/bin/bash

# 执行 yarn build
echo "正在执行 yarn build..."
yarn build

# 检查 dist 目录是否存在
if [ ! -d "dist" ]; then
  echo "错误：执行 yarn build 后未找到 dist 目录"
  exit 1
fi

# 获取当前时间并格式化为 YY_MM_DD_HH_MM_SS（增加秒）
current_time=$(date +"%y_%m_%d_%H_%M_%S")

# 定义压缩文件名
zip_filename="va_admin_server_diy_${current_time}.zip"

# 压缩 dist 文件夹
echo "正在压缩 dist 文件夹为 ${zip_filename}..."
zip -r "${zip_filename}" dist

# 检查压缩是否成功
if [ $? -eq 0 ]; then
  echo "压缩成功！文件已保存为 ${zip_filename}"
else
  echo "压缩失败"
  exit 1
fi

# 可选：删除 dist 文件夹（如果需要）
# read -p "是否删除 dist 文件夹？(y/n): " choice
# if [ "$choice" = "y" ]; then
#   rm -rf dist
#   echo "已删除 dist 文件夹"
# fi
```

#### **`bat`** 脚本
```batch
@echo off
setlocal enabledelayedexpansion

:: 执行 yarn build
echo 正在执行 yarn build...
call yarn build

:: 检查 dist 目录是否存在
if not exist dist (
    echo 错误：执行 yarn build 后未找到 dist 目录
    exit /b 1
)

:: 获取当前时间并格式化为 YY_MM_DD_HH_MM_SS
for /f "tokens=1-6 delims=/: " %%a in ('time /t ^| find ":"') do (
    set hour=%%a
    set minute=%%b
)
for /f "tokens=1-3 delims=/" %%a in ('date /t') do (
    set day=%%a
    set month=%%b
    set year=%%c
)
:: 处理 12 小时制时间（如果 time /t 返回 12 小时制）
if "!hour!" lss "10" (
    if "!hour!"==" " (
        set hour=00
    ) else (
        set hour=!hour:~1,1!
    )
)
if "!hour!" lss "12" (
    if "!hour!"=="0" (
        set hour=12
    )
)
:: 转换为 24 小时制（如果 time /t 返回 12 小时制）
if "!hour!" gtr "12" (
    set /a hour=!hour!-12
)
:: 补零
if !hour! lss 10 set hour=0!hour!
if !minute! lss 10 set minute=0!minute!
if !day! lss 10 set day=0!day!
if !month! lss 10 set month=0!month!

:: 获取完整年份（YYYY）
for /f "tokens=2 delims==" %%a in ('"wmic os get LocalDateTime /value | findstr LocalDateTime"') do set datetime=%%a
set year=%datetime:~0,4%

:: 格式化时间（YY_MM_DD_HH_MM_SS）
set current_time=%year:~-2%_%month%_%day%_%hour%_%minute%_%time:~6,2%

:: 如果 time /t 返回 12 小时制，可能需要调整秒数
:: 这里直接使用 WMIC 获取更准确的时间
for /f "tokens=1-3 delims=:.," %%a in ('"wmic os get LocalDateTime /value | findstr LocalDateTime"') do set datetime=%%a
set current_time=%datetime:~2,2%_%datetime:~4,2%_%datetime:~6,2%_%datetime:~8,2%_%datetime:~10,2%_%datetime:~12,2%

:: 修正格式（WMIC 返回 YYYYMMDDHHMMSS.ssssss±UUU）
set current_time=%current_time:~2,2%_%current_time:~4,2%_%current_time:~6,2%_%current_time:~8,2%_%current_time:~10,2%_%current_time:~12,2%

:: 去掉可能的空格或特殊字符
set current_time=%current_time::=-%
set current_time=%current_time:.=-%
set current_time=%current_time: =%

:: 重新获取时间（更可靠的方式）
for /f "tokens=1-6 delims=/: " %%a in ('"wmic os get LocalDateTime /value | findstr LocalDateTime"') do (
    set year=%%a
    set month=%%b
    set day=%%c
    set hour=%%d
    set minute=%%e
    set second=%%f
)
set current_time=%year:~-2%_%month%_%day%_%hour%_%minute%_%second%

:: 定义压缩文件名
set zip_filename=va_admin_server_diy_%current_time%.zip

:: 检查 7-Zip 是否安装（如果使用 7-Zip）
:: 如果没有 7-Zip，可以改用 PowerShell 的 Compress-Archive
:: 这里假设使用 7-Zip
where 7z >nul 2>&1
if %errorlevel% equ 0 (
    echo 正在压缩 dist 文件夹为 %zip_filename%...
    7z a -tzip "%zip_filename%" dist\* >nul
) else (
    echo 7-Zip 未安装，尝试使用 PowerShell 压缩...
    powershell -Command "Compress-Archive -Path dist\* -DestinationPath '%zip_filename%' -Force"
)

:: 检查压缩是否成功
if exist "%zip_filename%" (
    echo 压缩成功！文件已保存为 %zip_filename%
) else (
    echo 压缩失败
    exit /b 1
)

:: 可选：删除 dist 文件夹（如果需要）
:: set /p choice=是否删除 dist 文件夹？(y/n): 
:: if /i "!choice!"=="y" (
::     rmdir /s /q dist
::     echo 已删除 dist 文件夹
:: )

endlocal
pause
```


#### **PowerShell**脚本
```powershell
# build_and_compress.ps1
yarn build

if (-Not (Test-Path "dist")) {
    Write-Host "错误：执行 yarn build 后未找到 dist 目录"
    exit 1
}

$current_time = Get-Date -Format "yy_MM_dd_HH_mm_ss"
$zip_filename = "va_admin_server_diy_$current_time.zip"

Compress-Archive -Path "dist\*" -DestinationPath $zip_filename -Force

if (Test-Path $zip_filename) {
    Write-Host "压缩成功！文件已保存为 $zip_filename"
} else {
    Write-Host "压缩失败"
    exit 1
}

# 可选：删除 dist 文件夹
# $choice = Read-Host "是否删除 dist 文件夹？(y/n)"
# if ($choice -eq 'y') {
#     Remove-Item -Recurse -Force "dist"
#     Write-Host "已删除 dist 文件夹"
# }
```