當系統發生嚴重故障需求廠商技術支援,或進行例行健康檢查時,完整的系統資訊快照 (配置、日誌、硬體、核心模組、效能指標...) 是診斷關鍵。Linux 生態系有兩大主流蒐集工具:sosreport (Python、Red Hat/CentOS/Ubuntu 預設整合) 與 supportconfig (Shell、SUSE/openSUSE 專用但可移植)。本文詳細記錄兩者安裝、參數、配置、報告解讀與優缺點比較。
| 發行版 | 套件名稱 | 安裝指令 |
|---|---|---|
| RHEL / CentOS / Fedora | sos | yum -y install sos |
| Ubuntu / Debian | sosreport | apt-get install sosreport |
舊版 RHEL 4.5 以前稱為 sysreport。專案託管於 GitHub。
sosreport --help # 完整參數列表
| 參數 | 說明 |
|---|---|
-l, --list-plugins | 列出所有可用/啟用/停用插件 |
-n, --skip-plugins | 停用指定插件 (如 -n memory,samba) |
-e, --enable-plugins | 啟用指定插件 |
-o, --only-plugins | **僅**啟用指定插件 (如 -o cluster -k cluster.lockdump) |
-k, --plugin-option | 傳遞插件選項 (插件.選項=值) |
-a, --alloptions | 啟用所有載入插件的所有選項 |
--batch | 非互動模式 (不提示輸入姓名/案件號) |
--report | 產生 HTML/XML 綜合報告 |
-z, --compression-type | 壓縮格式:auto/gzip/bzip2/xz (預設 auto → xz) |
--ticket-number | 指定支援案件號 |
--name | 指定報告名稱 |
[root@361way ~]# sosreport -a --report
sosreport (version 3.0)
This command will collect diagnostic and configuration information from
this CentOS Linux system and installed applications.
An archive containing the collected information will be generated in
/var/tmp and may be provided to a CentOS support representative.
...
Please enter your first initial and last name [361way.com]:
Please enter the case number that you are generating this report for:
Running plugins. Please wait ...
Running 68/68: yum...
Creating compressed archive...
Your sosreport has been generated and saved in:
/var/tmp/sosreport-361way.com-20140912204339.tar.xz
The checksum is: eaf5b2cbb1e9be68d41be5e5a60a61b6
# 解壓 (xz 格式)
tar xvJf sosreport-361way.com-20140912204339.tar.xz
# 或分兩步
xz -d *.tar.xz
tar -xvf *.tar
解壓後目錄結構:
sos.html:HTML 綜合報告 (含所有插件摘要、警示、配置樹)sos.txt:執行過程日誌、複製檔案清單、指令輸出plugins/:各插件原始輸出 (如 plugins/ps, plugins/rpm, plugins/network...)/etc/sos.conf[general]
#ftp_upload_url = ftp://example.com/incoming
#gpg_keyring = /usr/share/sos/rhsupport.pub
#gpg_recipient = support@redhat.com
smtp_server = None
[plugins]
#disable = rpm, selinux, dovecot # 預設停用插件
[tunables]
#rpm.rpmva = off # 關閉 rpm -Va 驗證 (耗時)
#general.syslogsize = 15 # 系統日誌擷取行數 (MB)
可預先設定 disable 排除耗時插件,或調整 tunables 加速採集。
# 使用 zypper (推薦)
zypper install supportutils
# 或下載 rpm 後用 yast 安裝
yast install supportutils-xxx.rpm
套件名稱視版本可能為 supportconfig 或 supportutils。
rpm -ql supportutils
/etc/schealth.conf
/etc/supportconfig.conf
/sbin/chkbin
/sbin/supportconfig
/usr/bin/schealth
/usr/share/man/man5/supportconfig.conf.5.gz
/usr/share/man/man8/chkbin.8.gz
/usr/share/man/man8/supportconfig.8.gz
supportconfig -h # 完整幫助
| 參數 | 說明 |
|---|---|
-A | 啟用所有功能 + 完整 rpm 驗證 (最完整但最慢) |
-m | 最小採集 (基本環境、健康、硬體、rpm、messages、y2logs) |
-i <keywords> | **僅**採集指定功能關鍵字 (用 -F 查看清單) |
-x <keywords> | **排除**指定功能關鍵字 |
-F | 顯示所有可用功能關鍵字 |
-E <email>, -N <name>, -O <company>, -P <phone> | 嵌入聯絡資訊 |
-U <url> | 自動上傳至 FTP/SCP/HTTP/HTTPS |
-r <srnum> | 附加 Novell 11 碼服務請求號 |
-g | 使用 gzip 而非預設 bzip2 |
-Q | 靜默模式 |
-L | 建立根目錄完整檔案清單 |
# 1. 完整採集 (預設輸出 /var/log/nts_主機名_日期.tbz)
supportconfig -A
# 2. 僅採集 LVM 相關
supportconfig -i LVM
# 3. 排除 LVM
supportconfig -x LVM
# 4. 嵌入聯絡資訊並上傳
supportconfig -A -E "tux@example.org" -N "Tux Penguin" -O "Penguin Inc." -U "https://www.361way.com/files/"
# 5. 最小採集
supportconfig -m
supportconfig -A
cd /var/log
tar jxvf nts_361way.com_140825_1504.tbz
more basic-health-report.txt
######################################################################
Supportconfig Health Check Report Tool v1.00-5
Date Checked: 09/12/14 04:40:37
######################################################################
Health Check Files [ Green ]
Processes Waiting for Run Queue [ Green ]
Kernel Taint Status [ Red ]
Kernel Tainted: 64 > 0
CPU Utilization [ Green ]
...
Status: Red Flag
Checked: /var/log/.../basic-health-check.txt
Report: /var/log/.../basic-health-report.txt
######################################################################
Kernel Tainted: 64 表示載入了非官方/非開源模組 (Unsupported modules loaded),參考 /usr/src/linux/Documentation/sysctl/kernel 解碼 tainted 值。
/etc/supportconfig.conf預設啟用上百個 OPTION_* 模組 (如 OPTION_LVM=1, OPTION_SMART=0),並定義上傳目標 VAR_OPTION_UPLOAD_TARGET='ftp://ftp.novell.com/incoming'、日誌目錄 VAR_OPTION_LOG_DIRS="/var/log /tmp"、最大行數 VAR_OPTION_LINE_COUNT=500 等。可直接編輯此檔永久調整預設行為。
| 維度 | sosreport | supportconfig |
|---|---|---|
| 開發語言 | Python | Shell (Bash) |
| 主要適用發行版 | RHEL, CentOS, Fedora, Ubuntu, Debian, ... | SLES, openSUSE |
| 擴充性 | 極強 (Python 模組化插件機制) | 中等 (Shell 函式庫擴充) |
| 相依性 | 需 Python 解釋器 + 標準庫 | 需核心工具 (ps, lsof, dmidecode, rpm 等) |
| 跨平台移植 | 容易 (Python 跨平台特性) | 需處理指令輸出格式差異 |
| 報告格式 | HTML (豐富互動) + 文字 | 純文字 + 可選 HTML (較簡略) |
| 壓縮格式 | xz (預設), gzip, bzip2 | bzip2 (預設), gzip |
| 上傳整合 | FTP/HTTP/HTTPS (需配置) | 內建 FTP/SCP/HTTP/HTTPS 上傳參數 |
--batch/-Q 非互動模式,可納入 Ansible/SaltStack 定時採集流程。無論選擇 sosreport 或 supportconfig,核心價值在於一鍵生成完整、結構化、可驗證的系統快照。建議:
-A/-a),保留現場證據。md5sum 校驗碼,加速診斷流程。