server-management

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Server Management

服务器管理

Server management principles for production operations. Learn to THINK, not memorize commands.

面向生产运维的服务器管理原则。 学会思考,而非死记硬背命令。

1. Process Management Principles

1. 进程管理原则

Tool Selection

工具选择

ScenarioTool
Node.js appPM2 (clustering, reload)
Any appsystemd (Linux native)
ContainersDocker/Podman
OrchestrationKubernetes, Docker Swarm
场景工具
Node.js 应用PM2 (clustering, reload)
任意应用systemd(Linux 原生)
容器Docker/Podman
编排Kubernetes, Docker Swarm

Process Management Goals

进程管理目标

GoalWhat It Means
Restart on crashAuto-recovery
Zero-downtime reloadNo service interruption
ClusteringUse all CPU cores
PersistenceSurvive server reboot

目标含义
崩溃时自动重启自动恢复
零停机重载无服务中断
集群化利用所有 CPU 核心
持久性服务器重启后仍能运行

2. Monitoring Principles

2. 监控原则

What to Monitor

监控内容

CategoryKey Metrics
AvailabilityUptime, health checks
PerformanceResponse time, throughput
ErrorsError rate, types
ResourcesCPU, memory, disk
类别关键指标
可用性在线时长、健康检查
性能响应时间、吞吐量
错误错误率、错误类型
资源CPU、内存、磁盘

Alert Severity Strategy

告警严重程度策略

LevelResponse
CriticalImmediate action
WarningInvestigate soon
InfoReview daily
级别响应方式
严重立即处理
警告尽快排查
信息每日回顾

Monitoring Tool Selection

监控工具选择

NeedOptions
Simple/FreePM2 metrics, htop
Full observabilityGrafana, Datadog
Error trackingSentry
UptimeUptimeRobot, Pingdom

需求可选工具
简单/免费PM2 metrics, htop
全链路可观测Grafana, Datadog
错误追踪Sentry
在线状态监控UptimeRobot, Pingdom

3. Log Management Principles

3. 日志管理原则

Log Strategy

日志策略

Log TypePurpose
Application logsDebug, audit
Access logsTraffic analysis
Error logsIssue detection
日志类型用途
应用日志调试、审计
访问日志流量分析
错误日志问题检测

Log Principles

日志原则

  1. Rotate logs to prevent disk fill
  2. Structured logging (JSON) for parsing
  3. Appropriate levels (error/warn/info/debug)
  4. No sensitive data in logs

  1. 日志轮转,防止磁盘被占满
  2. 结构化日志(JSON 格式),便于解析
  3. 合理的日志级别(error/warn/info/debug)
  4. 日志中不包含敏感数据

4. Scaling Decisions

4. 扩容决策

When to Scale

何时扩容

SymptomSolution
High CPUAdd instances (horizontal)
High memoryIncrease RAM or fix leak
Slow responseProfile first, then scale
Traffic spikesAuto-scaling
症状解决方案
CPU 使用率高添加实例(水平扩容)
内存占用高增加内存或修复内存泄漏
响应缓慢先分析性能,再进行扩容
流量突增自动扩容

Scaling Strategy

扩容策略

TypeWhen to Use
VerticalQuick fix, single instance
HorizontalSustainable, distributed
AutoVariable traffic

类型使用场景
垂直扩容快速修复、单实例场景
水平扩容可持续、分布式场景
自动扩容流量波动大的场景

5. Health Check Principles

5. 健康检查原则

What Constitutes Healthy

健康状态判定标准

CheckMeaning
HTTP 200Service responding
Database connectedData accessible
Dependencies OKExternal services reachable
Resources OKCPU/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. 安全原则

AreaPrinciple
AccessSSH keys only, no passwords
FirewallOnly needed ports open
UpdatesRegular security patches
SecretsEnvironment vars, not files
AuditLog access and changes

领域原则
访问控制仅使用 SSH 密钥,禁止密码登录
防火墙仅开放必要端口
更新维护定期安装安全补丁
敏感信息管理使用环境变量,而非文件存储
审计记录访问与变更操作

7. Troubleshooting Priority

7. 故障排查优先级

When something's wrong:
  1. Check if running (process status)
  2. Check logs (error messages)
  3. Check resources (disk, memory, CPU)
  4. Check network (ports, DNS)
  5. Check dependencies (database, APIs)

出现问题时:
  1. 检查服务是否运行(进程状态)
  2. 查看日志(错误信息)
  3. 检查资源状态(磁盘、内存、CPU)
  4. 检查网络(端口、DNS)
  5. 检查依赖服务(数据库、API)

8. Anti-Patterns

8. 反模式

❌ Don't✅ Do
Run as rootUse non-root user
Ignore logsSet up log rotation
Skip monitoringMonitor from day one
Manual restartsAuto-restart config
No backupsRegular backup schedule

Remember: A well-managed server is boring. That's the goal.
❌ 禁止做法✅ 正确做法
以 root 用户运行使用非 root 用户
忽略日志配置日志轮转
跳过监控从项目初期就开启监控
手动重启服务配置自动重启
不做备份制定定期备份计划

记住: 管理良好的服务器是“无聊”的。这正是我们的目标。