1. 程式人生 > >linux信息收集篇之sosreport

linux信息收集篇之sosreport

creat share root 發行版本 oot ini inux end 相對

sosreport是一個類型於supportconfig 的工具,sosreport是python編寫的一個工具,適用於centos(和redhat一樣,包名為sos)、ubuntu(其下包名為sosreport)等大多數版本的linux 。sosreport在github上的托管頁面為:https://github.com/sosreport/sos ,而且默認在很多系統的源裏都已經集成有。如果使用的是正版redhat,在出現系統問題,尋求官方支持時,官方一般也會通過sosreport將收集的信息進行分析查看。需要註意的是在一些老的redhat發行版中叫sysreport ------ 如redhat4.5之前的版本中。

一、sosreport的安裝

在默認使用linux發行版的源進行安裝時,由於在不同的系統上包名稱也會有差異,所以使用的命令也不同,如redhat和ubuntu平臺的安裝如下:

  1. // redhat/centos下的安裝
  2. # yum -y insatll sos
  3. // ubuntu下的安裝
  4. # sudo apt-get install sosreport

二、sosreport用法

可以使用sosreport --help或man sosreport 獲取使用幫助手冊,如下:

  1. [root@361way ~]# sosreport --help
  2. Usage: sosreport [options]
  3. Options:
  4. -h, --help show this help message and exit
  5. -l, --list-plugins list plugins and available plugin options
  6. -n NOPLUGINS, --skip-plugins=NOPLUGINS
  7. disable these plugins
  8. -e ENABLEPLUGINS, --enable-plugins=ENABLEPLUGINS
  9. enable these plugins
  10. -o ONLYPLUGINS, --only-plugins=ONLYPLUGINS
  11. enable these plugins only
  12. -k PLUGOPTS, --plugin-option=PLUGOPTS
  13. plugin options in plugname.option=value format (see
  14. -l)
  15. -a, --alloptions enable all options for loaded plugins
  16. --batch batch mode - do not prompt interactively
  17. --build keep sos tree available and dont package results
  18. -v, --verbose increase verbosity
  19. --quiet only print fatal errors
  20. --debug enable interactive debugging using the python debugger
  21. --ticket-number=TICKET_NUMBER
  22. specify ticket number
  23. --name=CUSTOMER_NAME specify report name
  24. --config-file=CONFIG_FILE
  25. specify alternate configuration file
  26. --tmp-dir=TMP_DIR specify alternate temporary directory
  27. --report Enable HTML/XML reporting
  28. --profile turn on profiling
  29. -z COMPRESSION_TYPE, --compression-type=COMPRESSION_TYPE
  30. compression technology to use [auto, zip, gzip, bzip2,
  31. xz] (default=auto)
  32. Some examples:
  33. enable cluster plugin only and collect dlm lockdumps:
  34. # sosreport -o cluster -k cluster.lockdump
  35. disable memory and samba plugins, turn off rpm -Va collection:
  36. # sosreport -n memory,samba -k rpm.rpmva=off

上面也列出了具體操作的示例。其中-l 參數會列出當前enable和disable的所有服務插件及當前available的所有插件。

  1. [root@361way log]# sosreport -a --report
  2. sosreport (version 3.0)
  3. This command will collect diagnostic and configuration information from
  4. this CentOS Linux system and installed applications.
  5. An archive containing the collected information will be generated in
  6. /var/tmp and may be provided to a CentOS support representative.
  7. Any information provided to CentOS will be treated in accordance with
  8. the published support policies at:
  9. https://www.centos.org/
  10. The generated archive may contain data considered sensitive and its
  11. content should be reviewed by the originating organization before being
  12. passed to any third party.
  13. No changes will be made to system configuration.
  14. Press ENTER to continue, or CTRL-C to quit.
  15. Please enter your first initial and last name [361way.com]:
  16. Please enter the case number that you are generating this report for:
  17. Running plugins. Please wait ...
  18. Running 68/68: yum...
  19. Creating compressed archive...
  20. Your sosreport has been generated and saved in:
  21. /var/tmp/sosreport-361way.com-20140912204339.tar.xz
  22. The checksum is: eaf5b2cbb1e9be68d41be5e5a60a61b6
  23. Please send this file to your support representative.

如上所示,我使用-A 啟用所有的模塊,--report是開啟所有的結果以html /xml 的格式一個總的報告。生成的包需要通過下面的命令進行解包。

  1. # xz -d ***.tar.xz
  2. # tar -xvf ***.tar
  3. 或直接使用下面的命令一步完成解壓
  4. tar xvJf ***.tar.xz

在解包後的sos_reports 目錄會有report的結果sos.html文件生成,同時會有sos.txt文件生成,該文件內列出了具體執行的命令及copy 文件的一些信息。html 打開的內容如下:

技術分享圖片

由於頁面較大,這裏只截出了最上面的部分,列出了所有的收集模塊,下面alerts 給出了報警模塊的信息。再往下就是具體到每一個模塊的信息。

三、sosreport配置文件

sosreport的配置文件是/etc/sos.conf ,默認內容如下:

  1. [root@361way ~]# cat /etc/sos.conf
  2. [general]
  3. #ftp_upload_url = ftp://example.com/incoming
  4. #gpg_keyring = /usr/share/sos/rhsupport.pub
  5. #gpg_recipient = [email protected]
  6. smtp_server = None
  7. [plugins] //此處可以設置默認enabledisable的模塊
  8. #disable = rpm, selinux, dovecot
  9. [tunables] //可調參數
  10. #rpm.rpmva = off
  11. #general.syslogsize = 15

從配置文件上可以看出,sosreport同樣將收集的結果上傳到server 上,可以通過man sos.conf 查看配置文件的幫助信息,不過man給出的並沒有太多信息,想在了解更多的信息可以查看 sosreport在github上的wiki頁 。

四、sosreport總結

相於supportconfig,由於sosreport是由python語言進行編寫的,所以其在功能擴展上更有優勢,但由於在不同的發行版本上的python版本不同,在進行功能擴展時,對不同版本間的異常處理相對麻煩。而supportconfig由於是shell 語言編寫的一個工具,對版本的依賴相對少些 ,但對一些工具的依賴相對多些 ,如在獲取進程相關的信息時,shell 需要將ps 工具或處理proc的結果,而sosreport則可以直接import psutil 模塊,兩者之間的區別,歸根到底就是shell 和python的區別。

linux信息收集篇之sosreport