Files
proxmox-task/proxmox_task/README.md

64 lines
1.7 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.
# Proxmox任务控制器
一个用于监控命令文件、启动Proxmox虚拟机、执行任务、汇报结果并关闭虚拟机的Python脚本。
## 功能特性
- 监控指定目录中的JSON命令文件
- 通过Proxmox API启动和关闭虚拟机
- 在虚拟机内执行指定命令支持QEMU Guest Agent
- 汇报执行结果到结果目录
- 支持凭证传递(用于需要认证的命令)
- 日志记录到文件和控制台
## 使用方法
### 1. 配置环境变量
```bash
export PROXMOX_HOST="https://your-proxmox-host:8006"
export PROXMOX_TOKEN_ID="your-token-id@pam"
export PROXMOX_TOKEN_SECRET="your-token-secret"
export PROXMOX_VERIFY_SSL="false" # 如果使用自签名证书
```
### 2. 准备命令文件
`/var/task-commands/` 目录中放置JSON格式的命令文件
```json
{
"node": "pve-node-1",
"vmid": 100,
"command": "ls -la /tmp && echo 'Hello World'",
"task_id": "my-task-001",
"username": "root",
"password": "your-vm-password",
"keep_running": false
}
```
### 3. 运行控制器
```bash
python3 controller.py
```
### 4. 查看结果
任务执行结果将保存为JSON文件在 `/var/task-results/` 目录中。
## 部署建议
1. 将脚本部署到小主机上
2. 确保小主机能够访问Proxmox服务器的API端口默认8006
3. 为小主机创建系统服务以实现开机自启动
4. 定期清理旧的结果文件
5. 考虑使用更安全的凭证管理方式如HashiCorp Vault或AWS Secrets Manager
## 注意事项
- 确保目标虚拟机已安装并运行QEMU Guest Agent为了使用agent/exec API
- 或者修改脚本使用SSH方式在VM内执行命令
- 生产环境中应使用更安全的方式处理凭证
- 建议在测试环境中先验证功能