打包平台:部署记录

1. 后端服务部署

1.1 部署步骤

1
2
3
4
5
6
7
8
9
10
11
# 进入部署目录
cd /data/705

# 替换新版 jar 包
cp /path/to/new/docServer.jar ./

# 停止当前服务
ps -ef | grep docServer.jar | grep -v grep | awk '{print $2}' | xargs kill -9

# 启动新服务
nohup java -jar docServer.jar > docServer.log 2>&1 &

1.2 常见问题解决

问题

1
2
3
4
Error creating bean with name 'nettyServer':
Injection of autowired dependencies failed;
nested exception is java.lang.IllegalArgumentException:
Could not resolve placeholder 'aes.password' in value "${aes.password}"

解决方案

  1. 检查配置文件中的属性设置

  2. 确保 application.propertiesapplication.yml 中包含:

    1
    aes.password=your_secure_password_here
  3. 如果使用环境变量:

    1
    2
    export AES_PASSWORD="your_secure_password"
    nohup java -jar -Daes.password=${AES_PASSWORD} docServer.jar > docServer.log 2>&1 &

2. 前端服务部署

2.1 部署步骤

1
2
3
4
5
6
7
8
9
10
11
12
# 进入前端目录
cd /data/packplate

# 从远程服务器获取最新前端包
scp centos@192.168.211.113:/root/dist.zip ./

# 解压并覆盖现有 dist 目录
unzip -o dist.zip

# 重启前端服务(根据实际部署方式)
# 如果是 Nginx:
systemctl restart nginx

3. Docker 容器部署

3.1 镜像部署示例

1
2
3
4
5
6
7
8
9
# 拉取镜像
docker pull alpha-harbor.51iwifi.com/cloud-switch/cloud-switch-order:1.0.0.73371.2224

# 运行容器
docker run -d \
--name cloud-switch-order \
-p 8080:8080 \
-e AES_PASSWORD="your_password" \
alpha-harbor.51iwifi.com/cloud-switch/cloud-switch-order:1.0.0.73371.2224

3.2 版本更新说明

cloud-switch-switch-parent-dedai-v1.20-20211011-dev

  • 修复停复机工单死锁问题
  • 优化 SQL 更新语句
  • 解决拆机用户停复机工单失败问题
  • 优化日志打印

4. 服务验证

4.1 后端验证

1
2
3
4
5
6
7
8
# 检查日志
tail -f /data/705/docServer.log

# 检查进程
ps -ef | grep docServer.jar

# 接口测试
curl http://localhost:8080/api/health

4.2 前端验证

  1. 访问前端页面
  2. 检查控制台错误(F12)
  3. 验证关键功能点

5. 部署脚本模板

5.1 自动化部署脚本

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/bin/bash
# deploy.sh

# 后端部署函数
deploy_backend() {
local target_dir="/data/705"
local jar_file="docServer.jar"

echo "停止当前服务..."
pkill -f $jar_file

echo "备份旧版本..."
cp $target_dir/$jar_file $target_dir/${jar_file}.bak.$(date +%F)

echo "部署新版本..."
cp /tmp/$jar_file $target_dir/

echo "启动服务..."
cd $target_dir
nohup java -jar $jar_file > docServer.log 2>&1 &

echo "后端部署完成"
}

# 前端部署函数
deploy_frontend() {
local target_dir="/data/packplate"
local dist_zip="dist.zip"

echo "获取前端包..."
scp centos@192.168.211.113:/root/$dist_zip /tmp/

echo "解压前端包..."
unzip -o /tmp/$dist_zip -d $target_dir

echo "重启前端服务..."
systemctl restart nginx

echo "前端部署完成"
}

# 主程序
case $1 in
backend)
deploy_backend;;
frontend)
deploy_frontend;;
all)
deploy_backend
deploy_frontend;;
*)
echo "用法: $0 [backend|frontend|all]"
exit 1;;
esac

6. 最佳实践

6.1 配置管理

  1. 使用环境变量管理敏感信息
  2. 配置文件与代码分离
  3. 使用配置中心(如 Spring Cloud Config)

6.2 安全加固

1
2
3
4
5
6
7
8
9
# 创建专用用户
useradd appuser -s /sbin/nologin

# 设置文件权限
chown -R appuser:appuser /data/705
chmod 700 /data/705

# 使用安全传输
scp -i ~/.ssh/deploy_key.pem user@host:/path/to/file /local/path

6.3 监控设置

1
2
3
4
5
6
7
8
9
10
11
# 监控日志文件
tail -f /data/705/docServer.log | grep -i error

# 监控服务状态
while true; do
if ! pgrep -f docServer.jar > /dev/null; then
echo "服务已停止,正在重启..."
nohup java -jar /data/705/docServer.jar >> /data/705/docServer.log 2>&1 &
fi
sleep 30
done

7. 版本回滚

7.1 后端回滚

1
2
3
4
5
6
7
8
9
# 停止当前服务
pkill -f docServer.jar

# 恢复备份版本
cp /data/705/docServer.jar.bak.2023-06-01 /data/705/docServer.jar

# 启动服务
cd /data/705
nohup java -jar docServer.jar > docServer.log 2>&1 &

7.2 前端回滚

1
2
3
4
5
# 恢复备份
cp -r /data/packplate/dist.bak /data/packplate/dist

# 重启服务
systemctl restart nginx

8. 维护建议

  1. 定期备份

    1
    2
    # 每日备份
    tar -czvf /backup/packplatform_$(date +%F).tar.gz /data/705 /data/packplate
  2. 日志轮转

    1
    2
    3
    4
    5
    6
    7
    8
    9
    # 使用 logrotate
    /etc/logrotate.d/packplatform:
    /data/705/docServer.log {
    daily
    rotate 7
    compress
    missingok
    notifempty
    }
  3. 性能监控

    1
    2
    # 监控 JVM 状态
    jstat -gcutil <pid> 1000