server-management
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseServer Management
服务器管理
Server management principles for production operations. Learn to THINK, not memorize commands.
面向生产运维的服务器管理原则。 学会思考,而非死记硬背命令。
1. Process Management Principles
1. 进程管理原则
Tool Selection
工具选择
| Scenario | Tool |
|---|---|
| Node.js app | PM2 (clustering, reload) |
| Any app | systemd (Linux native) |
| Containers | Docker/Podman |
| Orchestration | Kubernetes, Docker Swarm |
| 场景 | 工具 |
|---|---|
| Node.js 应用 | PM2 (clustering, reload) |
| 任意应用 | systemd(Linux 原生) |
| 容器 | Docker/Podman |
| 编排 | Kubernetes, Docker Swarm |
Process Management Goals
进程管理目标
| Goal | What It Means |
|---|---|
| Restart on crash | Auto-recovery |
| Zero-downtime reload | No service interruption |
| Clustering | Use all CPU cores |
| Persistence | Survive server reboot |
| 目标 | 含义 |
|---|---|
| 崩溃时自动重启 | 自动恢复 |
| 零停机重载 | 无服务中断 |
| 集群化 | 利用所有 CPU 核心 |
| 持久性 | 服务器重启后仍能运行 |
2. Monitoring Principles
2. 监控原则
What to Monitor
监控内容
| Category | Key Metrics |
|---|---|
| Availability | Uptime, health checks |
| Performance | Response time, throughput |
| Errors | Error rate, types |
| Resources | CPU, memory, disk |
| 类别 | 关键指标 |
|---|---|
| 可用性 | 在线时长、健康检查 |
| 性能 | 响应时间、吞吐量 |
| 错误 | 错误率、错误类型 |
| 资源 | CPU、内存、磁盘 |
Alert Severity Strategy
告警严重程度策略
| Level | Response |
|---|---|
| Critical | Immediate action |
| Warning | Investigate soon |
| Info | Review daily |
| 级别 | 响应方式 |
|---|---|
| 严重 | 立即处理 |
| 警告 | 尽快排查 |
| 信息 | 每日回顾 |
Monitoring Tool Selection
监控工具选择
| Need | Options |
|---|---|
| Simple/Free | PM2 metrics, htop |
| Full observability | Grafana, Datadog |
| Error tracking | Sentry |
| Uptime | UptimeRobot, Pingdom |
| 需求 | 可选工具 |
|---|---|
| 简单/免费 | PM2 metrics, htop |
| 全链路可观测 | Grafana, Datadog |
| 错误追踪 | Sentry |
| 在线状态监控 | UptimeRobot, Pingdom |
3. Log Management Principles
3. 日志管理原则
Log Strategy
日志策略
| Log Type | Purpose |
|---|---|
| Application logs | Debug, audit |
| Access logs | Traffic analysis |
| Error logs | Issue detection |
| 日志类型 | 用途 |
|---|---|
| 应用日志 | 调试、审计 |
| 访问日志 | 流量分析 |
| 错误日志 | 问题检测 |
Log Principles
日志原则
- Rotate logs to prevent disk fill
- Structured logging (JSON) for parsing
- Appropriate levels (error/warn/info/debug)
- No sensitive data in logs
- 日志轮转,防止磁盘被占满
- 结构化日志(JSON 格式),便于解析
- 合理的日志级别(error/warn/info/debug)
- 日志中不包含敏感数据
4. Scaling Decisions
4. 扩容决策
When to Scale
何时扩容
| Symptom | Solution |
|---|---|
| High CPU | Add instances (horizontal) |
| High memory | Increase RAM or fix leak |
| Slow response | Profile first, then scale |
| Traffic spikes | Auto-scaling |
| 症状 | 解决方案 |
|---|---|
| CPU 使用率高 | 添加实例(水平扩容) |
| 内存占用高 | 增加内存或修复内存泄漏 |
| 响应缓慢 | 先分析性能,再进行扩容 |
| 流量突增 | 自动扩容 |
Scaling Strategy
扩容策略
| Type | When to Use |
|---|---|
| Vertical | Quick fix, single instance |
| Horizontal | Sustainable, distributed |
| Auto | Variable traffic |
| 类型 | 使用场景 |
|---|---|
| 垂直扩容 | 快速修复、单实例场景 |
| 水平扩容 | 可持续、分布式场景 |
| 自动扩容 | 流量波动大的场景 |
5. Health Check Principles
5. 健康检查原则
What Constitutes Healthy
健康状态判定标准
| Check | Meaning |
|---|---|
| HTTP 200 | Service responding |
| Database connected | Data accessible |
| Dependencies OK | External services reachable |
| Resources OK | CPU/memory not exhausted |
| 检查项 | 含义 |
|---|---|
| HTTP 200 响应 | 服务正常响应 |
| 数据库已连接 | 数据可访问 |
| 依赖服务正常 | 外部服务可达 |
| 资源状态正常 | CPU/内存未耗尽 |
Health Check Implementation
健康检查实现方式
- Simple: Just return 200
- Deep: Check all dependencies
- Choose based on load balancer needs
- 简单版:仅返回 200 状态码
- 深度版:检查所有依赖服务
- 根据负载均衡器需求选择合适的方式
6. Security Principles
6. 安全原则
| Area | Principle |
|---|---|
| Access | SSH keys only, no passwords |
| Firewall | Only needed ports open |
| Updates | Regular security patches |
| Secrets | Environment vars, not files |
| Audit | Log access and changes |
| 领域 | 原则 |
|---|---|
| 访问控制 | 仅使用 SSH 密钥,禁止密码登录 |
| 防火墙 | 仅开放必要端口 |
| 更新维护 | 定期安装安全补丁 |
| 敏感信息管理 | 使用环境变量,而非文件存储 |
| 审计 | 记录访问与变更操作 |
7. Troubleshooting Priority
7. 故障排查优先级
When something's wrong:
- Check if running (process status)
- Check logs (error messages)
- Check resources (disk, memory, CPU)
- Check network (ports, DNS)
- Check dependencies (database, APIs)
出现问题时:
- 检查服务是否运行(进程状态)
- 查看日志(错误信息)
- 检查资源状态(磁盘、内存、CPU)
- 检查网络(端口、DNS)
- 检查依赖服务(数据库、API)
8. Anti-Patterns
8. 反模式
| ❌ Don't | ✅ Do |
|---|---|
| Run as root | Use non-root user |
| Ignore logs | Set up log rotation |
| Skip monitoring | Monitor from day one |
| Manual restarts | Auto-restart config |
| No backups | Regular backup schedule |
Remember: A well-managed server is boring. That's the goal.
| ❌ 禁止做法 | ✅ 正确做法 |
|---|---|
| 以 root 用户运行 | 使用非 root 用户 |
| 忽略日志 | 配置日志轮转 |
| 跳过监控 | 从项目初期就开启监控 |
| 手动重启服务 | 配置自动重启 |
| 不做备份 | 制定定期备份计划 |
记住: 管理良好的服务器是“无聊”的。这正是我们的目标。