萬盛學電腦網

您现在的位置: 萬盛學電腦網 >> 程式設計 >  >> 伺服器教學

Linux 系統資訊蒐集神器對決:sosreport (Python) vs supportconfig (Shell) 完整安裝與操作指南

前言

當系統發生嚴重故障需求廠商技術支援,或進行例行健康檢查時,完整的系統資訊快照 (配置、日誌、硬體、核心模組、效能指標...) 是診斷關鍵。Linux 生態系有兩大主流蒐集工具:sosreport (Python、Red Hat/CentOS/Ubuntu 預設整合) 與 supportconfig (Shell、SUSE/openSUSE 專用但可移植)。本文詳細記錄兩者安裝、參數、配置、報告解讀與優缺點比較。

第一部份:sosreport (Red Hat / CentOS / Ubuntu 通用)

一、安裝

發行版套件名稱安裝指令
RHEL / CentOS / Fedorasosyum -y install sos
Ubuntu / Debiansosreportapt-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 加速採集。

第二部份:supportconfig (SUSE / openSUSE 專用)

一、安裝

# 使用 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 等。可直接編輯此檔永久調整預設行為。

第三部份:兩者比較與選型建議

維度sosreportsupportconfig
開發語言PythonShell (Bash)
主要適用發行版RHEL, CentOS, Fedora, Ubuntu, Debian, ...SLES, openSUSE
擴充性極強 (Python 模組化插件機制)中等 (Shell 函式庫擴充)
相依性需 Python 解釋器 + 標準庫需核心工具 (ps, lsof, dmidecode, rpm 等)
跨平台移植容易 (Python 跨平台特性)需處理指令輸出格式差異
報告格式HTML (豐富互動) + 文字純文字 + 可選 HTML (較簡略)
壓縮格式xz (預設), gzip, bzip2bzip2 (預設), gzip
上傳整合FTP/HTTP/HTTPS (需配置)內建 FTP/SCP/HTTP/HTTPS 上傳參數

選型建議

  • Red Hat 系 / Ubuntu / 通用環境:首選 sosreport,生態完整、插件豐富、HTML 報告易讀、Red Hat 官方支援流程標準化。
  • SUSE 系:首選 supportconfig,深度整合 YaST、SMT、HA Cluster 等 SUSE 專有元件。
  • 極小嵌入式/無 Python 環境:supportconfig (Shell) 相依性更輕,甚至可手動修改腳本移植至其他發行版。
  • 自動化巡檢腳本整合:兩者皆支援 --batch/-Q 非互動模式,可納入 Ansible/SaltStack 定時採集流程。

總結

無論選擇 sosreport 或 supportconfig,核心價值在於一鍵生成完整、結構化、可驗證的系統快照。建議:

  1. 平時納入維運 SOP,定期 (如每週) 自動採集並歸檔備份。
  2. 故障發生前**立即**執行一次完整採集 (-A/-a),保留現場證據。
  3. 閱讀報告重點關注 Kernel Taint、硬體錯誤 (MCE/EDAC)、磁碟 SMART、服務異常啟動狀態、核心參數偏離預設 等關鍵指標。
  4. 提交廠商支援時,附上報告壓縮包與 md5sum 校驗碼,加速診斷流程。
copyright © 萬盛學電腦網 all rights reserved