Linux 服務管理涉及啟動方式、端口對應、運行等級控制三大維度。本文系統梳理 Standalone(獨立守護進程)與 Super Daemon (xinetd) 兩大架構,提供端口追蹤、服務啟停、開機自啟的完整操作手冊。
| 特性 | Standalone | xinetd (Super Daemon) |
|---|---|---|
| 啟動方式 | 系統啟動時直接常駐記憶體 | 由 xinetd 主進程監聽,有請求才 fork 子進程 |
| 回應速度 | 極快(無 fork 開銷) | 稍慢(需 fork) |
| 資源佔用 | 常駐佔用記憶體 | 閒置時不佔用,適合低頻服務 |
| 管理腳本位置 | /etc/init.d/ 或 /etc/rc.d/init.d/ | /etc/xinetd.d/ 設定檔 |
| 控制指令 | systemctl start|stop|restart sshd | 修改 disable = yes/no 後 systemctl reload xinetd |
| 典型服務 | sshd, httpd, mysqld, named, ntpd | telnet, tftp, rsync, cvs, pop3, imap |
cat /etc/services | grep -E '^(ssh|http|ftp|telnet|smtp|dns|dhcp)'
# 顯示 PID、程式名、監聽狀態 ss -tlnp # 或 netstat -tlnp
# 找到進程執行檔路徑
which sshd
# 或
readlink -f /proc/$(ss -tlnp | grep :22 | awk '{print $NF}' | cut -d= -f2 | cut -d, -f1)/exe
# 查詢 RPM 套件
rpm -qf /usr/sbin/sshd
# 查詢該套件的啟動腳本
rpm -ql openssh-server | grep init.d
# 立即啟停 systemctl start|stop|restart|reload sshd # 開機自啟 systemctl enable|disable sshd # 查看狀態 systemctl status sshd systemctl is-enabled sshd # 列出所有單元 systemctl list-unit-files --type=service
service sshd start|stop|restart|status chkconfig sshd on|off chkconfig --list sshd
ss -tlnp | grep :25 → 找到 PID/程式名readlink -f /proc//exe rpm -qf /path/to/exesystemctl stop systemctl disable firewall-cmd --permanent --remove-port=25/tcp && firewall-cmd --reload# 1. 安裝
dnf install -y telnet-server xinetd
# 2. 編輯 xinetd 設定
cat > /etc/xinetd.d/telnet <<'EOF'
service telnet
{
flags = REUSE
socket_type = stream
wait = no
user = root
server = /usr/sbin/in.telnetd
log_on_failure += USERID
disable = no
}
EOF
# 3. 重載 xinetd
systemctl restart xinetd
# 4. 驗證
ss -tlnp | grep :23
| 服務 | 功能 | 必要性 |
|---|---|---|
| sshd | 遠端安全登入 | 必須 |
| network / NetworkManager | 網路連線 | 必須 |
| crond | 排程任務 | 必須 |
| rsyslog / systemd-journald | 日誌收集 | 必須 |
| firewalld / iptables | 防火牆 | 必須 |
| chronyd / ntpd | 時間同步 | 強烈建議 |
| irqbalance | 中斷平衡 | 多核心建議 |
| auditd | 安全審計 | 合規環境必須 |
其他服務依業務需求啟用,遵循最小權限原則:不需要的服務一律關閉。