Files
wecom_it_smart_desk/docs/09-部署运维/11-堡垒机运维工具.md
T

89 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 堡垒机运维工具 (jumpserver-ops)
## 概述
通过 JumpServer 堡垒机自动化执行远程命令、文件上传下载。统一入口为 `jms_ops.py`,支持 4 种操作模式。
## 连接方式决策
| 场景 | 连接方式 |
|------|----------|
| **默认** | 通过堡垒机跳转(大多数内网服务器) |
| **例外** | 直连(NAS、开发机等)需单独配置 |
> **规则**:默认都需要通过堡垒机,除非明确告知某台服务器是直连。
## 使用方法
### 1. 远程命令执行(推荐)
```bash
# 单命令(纯文本输出)
python scripts/jms_ops.py exec -c "docker ps"
# 多命令串行(一次登录,5x 提速)
python scripts/jms_ops.py exec -c "hostname" -c "uptime" -c "docker ps"
# 并行模式(不冲突的长命令)
python scripts/jms_ops.py exec -c "docker logs nginx --tail 100" -c "df -h" --parallel
```
### 2. 批量命令
```bash
python scripts/jms_ops.py batch -f commands.txt
```
### 3. 文件上传
```bash
# 通过 elFinder Web UI 上传到目标服务器
python scripts/jms_ops.py upload 本地文件.conf /tmp/远程路径.conf
```
### 4. 文件下载
```bash
# 通过 base64 通道从目标服务器下载
python scripts/jms_ops.py download /远程路径.conf ./本地文件.conf
```
## 方案选择依据
| 需求 | 推荐方案 | 速度 |
|------|----------|------|
| 执行命令获取文本结果 | v16 REST API + plink PTY | 首次 ~13s,复用 ~2-3s |
| 执行命令看界面效果 | v10 Web CLI(截图) | ~60s |
| 文件上传 (< 100KB) | base64 通道 | 快 |
| 文件上传 (>= 100KB 或 > 15s) | elFinder Web UI | 稳定 |
| 文件下载 | base64 通道 | - |
## 目标服务器配置
当前预设目标:`hz-oa-ai-g-dataquery-90-5-110` (10.90.5.110)
新增直连服务器时,需提供:
- IP 地址
- 端口(默认 22
- 用户名
- 认证方式(密码或 SSH 密钥)
## 故障排除
| 问题 | 解决方法 |
|------|----------|
| 登录失败 | 检查 `config/jumpserver_config.json` 密码是否正确(Base64 编码) |
| MFA 失败 | 确认 `scripts/otp_secret.key` 存在且系统时间准确 |
| 资产未找到 | 确认目标名称与 JumpServer 中显示一致 |
## 脚本位置
```
C:\Users\simon\.workbuddy\skills\jumpserver-ops\scripts\jms_ops.py
```
## 相关文档
- [服务器部署手册](./服务器部署手册.md)
- [版本更新说明](./05-版本更新说明-v1.1.0-20260614.md)