Debian 进程管理最佳实践
一 进程生命周期与守护化
二 稳定性与自愈
三 性能与资源效率
四 安全与运维
五 快速检查清单
| 实践 | 关键动作 | 常用命令或配置 |
|---|---|---|
| 服务托管 | systemd 单元、自动重启、标准日志 | systemctl enable --now myapp;journalctl -u myapp -f |
| 资源限额 | ulimit/cgroups 设定上限 | ulimit -n 65535;cgexec -g memory:/mygroup … |
| 自愈重启 | Restart 策略与 RestartSec | Restart=always;RestartSec=5 |
| 僵尸治理 | 回收子进程或信号处理 | wait/waitpid;SIGCHLD + waitpid(WNOHANG) |
| 日志轮转 | logrotate 按大小/时间切割 | /etc/logrotate.d/myapp |
| 性能调优 | nice/ionice、taskset、noatime、swappiness、somaxconn、BBR | nice -n -10;ionice -c 2 -n 7;taskset 0x1 …;mount -o noatime;sysctl -w vm.swappiness=10;sysctl -w net.core.somaxconn=65535;sysctl -w net.ipv4.tcp_congestion_control=bbr |
| 监控剖析 | 资源观测与瓶颈定位 | top/htop、vmstat、iostat、sar;perf、strace、gprof |
| 安全加固 | 最小权限、防火墙、容器化 | sudo、ufw/firewalld、Docker |
| 系统维护 | 更新、清理、内核 | apt update && apt full-upgrade;apt autoremove/clean;apt install linux-image-amd64 |