GoOps 是一个基于 Go 语言开发的轻量级运维自动化工具,采用 Agent-Server 架构,支持批量执行命令、文件传输等运维操作。
- 🚀 零依赖 - 编译后的二进制文件无需任何运行时依赖
- 🔐 无需SSH - 基于HTTP API的Agent模式,更安全更灵活
- ⚡ 高性能 - Go原生并发,支持大规模批量操作
- 🎯 多种输出格式 - 支持text、json、raw、table等多种输出格式
- 🔄 自动注册 - Agent启动后自动注册到Server
- 📦 单文件部署 - 每个组件都是单个可执行文件
┌─────────────┐ HTTP API ┌─────────────┐
│ Client │ ──────────────────>│ Server │
│ (CLI) │ │ (中心管理) │
└─────────────┘ └──────┬──────┘
│
HTTP API
│
┌─────────────────────┼─────────────────────┐
│ │ │
┌─────▼─────┐ ┌─────▼─────┐ ┌─────▼─────┐
│ Agent │ │ Agent │ │ Agent │
│ (执行节点) │ │ (执行节点) │ │ (执行节点) │
└───────────┘ └───────────┘ └───────────┘
- Linux (Ubuntu 18.04+, CentOS 7+, Debian 9+)
- 2GB+ RAM
- Go 1.19+ (仅编译时需要)
# 克隆代码
git clone https://github.com/yourusername/goops.git
cd goops
# 编译
./build.sh
# 生成文件
# - dist/goops-server (服务端)
# - dist/goops-agent (Agent)
# - dist/goops (客户端CLI)
# 安装Server
cp dist/goops-server /usr/local/bin/
chmod +x /usr/local/bin/goops-server
# 创建systemd服务
cat > /etc/systemd/system/goops-server.service << EOF
[Unit]
Description=GoOps Server
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/goops-server -host 0.0.0.0 -port 8000
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 启动服务
systemctl daemon-reload
systemctl enable goops-server
systemctl start goops-server
# 安装Agent
cp dist/goops-agent /usr/local/bin/
chmod +x /usr/local/bin/goops-agent
# 创建systemd服务
cat > /etc/systemd/system/goops-agent.service << EOF
[Unit]
Description=GoOps Agent
After=network.target
[Service]
Type=simple
ExecStart=/usr/local/bin/goops-agent -port 9000 -name $(hostname) -server http://SERVER_IP:8000
Restart=always
[Install]
WantedBy=multi-user.target
EOF
# 启动服务
systemctl daemon-reload
systemctl enable goops-agent
systemctl start goops-agent
# 查看所有Agent
goops -s http://SERVER_IP:8000 agents list
# 执行命令(默认在所有Agent上执行)
goops -s http://SERVER_IP:8000 exec 'df -h'
# 不同输出格式
goops -s http://SERVER_IP:8000 exec -o raw 'ls /tmp' # 原始输出
goops -s http://SERVER_IP:8000 exec -o json 'uptime' # JSON格式
goops -s http://SERVER_IP:8000 exec -o table 'free -m' # 表格格式
# 指定Agent执行
goops -s http://SERVER_IP:8000 exec -a agent1,agent2 'ps aux'
# 使用标签执行
goops -s http://SERVER_IP:8000 exec -t production 'systemctl status nginx'
$ goops -s http://192.168.0.3:8000 exec 'df -h'
执行命令: df -h
============================================================
► vm-dev-es-automizely-01-asea1b-9000:
----------------------------------------
Filesystem Size Used Avail Use% Mounted on
/dev/root 20G 7.8G 12G 40% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 783M 1.1M 782M 1% /run
✓ 成功 (耗时: 8ms)
► vm-dev-es-automizely-02-asea1a-9000:
----------------------------------------
Filesystem Size Used Avail Use% Mounted on
/dev/root 20G 6.5G 14G 33% /
tmpfs 2.0G 0 2.0G 0% /dev/shm
tmpfs 783M 1.0M 782M 1% /run
✓ 成功 (耗时: 7ms)
============================================================
执行完成: 2 个Agent
$ goops -s http://192.168.0.3:8000 exec -o json 'uptime'
{
"success": true,
"results": {
"vm-dev-es-automizely-01-asea1b-9000": {
"Host": "",
"Output": " 10:45:23 up 5 days, 18:32, 1 user, load average: 0.15, 0.12, 0.09\n",
"Error": "",
"Success": true
}
}
}
$ goops -s http://192.168.0.3:8000 exec -o table 'free -m'
命令: free -m
+----------------------------------------+--------+----------------------+
| AGENT | STATUS | OUTPUT (前5行) |
+----------------------------------------+--------+----------------------+
| vm-dev-es-automizely-01-asea1b-9000 | ✓ | total used free |
| | | Mem: 3935 3050 |
| | | Swap: 0 0 |
+----------------------------------------+--------+----------------------+
Server通过命令行参数配置:
goops-server -host 0.0.0.0 -port 8000
Agent通过命令行参数配置:
goops-agent -port 9000 -name node1 -server http://192.168.0.3:8000 -token secret123
参数说明:
-port
: Agent监听端口(默认9000)-name
: Agent名称(默认为hostname)-server
: Server地址(可选,用于自动注册)-token
: 认证Token(可选)
GET /api/v1/agents
POST /api/v1/exec
Content-Type: application/json
{
"command": "df -h",
"agents": ["agent1", "agent2"], // 可选,默认所有
"tags": ["production"], // 可选,按标签选择
"timeout": 30 // 可选,超时秒数
}
POST /api/v1/agents/:id/heartbeat
GET /api/v1/agents/:id/metrics
goops/
├── cmd/
│ ├── server/ # Server入口
│ ├── agent/ # Agent入口
│ └── client/ # CLI客户端入口
├── internal/
│ ├── server/ # Server核心逻辑
│ ├── executor/ # 命令执行器
│ └── client/ # 客户端SDK
├── build.sh # 编译脚本
├── go.mod # Go模块定义
└── README.md # 本文件
# 安装依赖
go mod tidy
# 运行Server
go run cmd/server/main.go
# 运行Agent
go run cmd/agent/main.go -server http://localhost:8000
# 运行CLI
go run cmd/client/main.go exec 'ls'
# 运行单元测试
go test ./...
# 运行集成测试
go test -tags=integration ./...
-
安全配置
- 配置Token认证
- 使用HTTPS(可配合nginx反向代理)
- 限制Server端口访问(防火墙规则)
-
高可用
- Server可部署多实例,使用负载均衡
- Agent自动重连机制
-
监控
- 集成Prometheus监控
- 配置日志收集(journald/syslog)
-
性能优化
- 根据需求调整并发数
- 合理设置超时时间
- 初始版本发布
- 支持Agent-Server架构
- 支持批量命令执行
- 多种输出格式支持
欢迎提交Issue和Pull Request!
MIT License
- Gin - Web框架
- Cobra - CLI框架
- Tablewriter - 表格输出
- Color - 终端颜色
- Issue: GitHub Issues