監控對象:
1. 監控對象的理解:CPU是怎麼工做的,原理
2. 監控對象的指標:CPU使用率 CPU負載 CPU個數 上下文切換
3. 肯定性能基準線:怎麼樣纔算故障?CPU負載多上纔算高
監控範圍:
1.硬件監控服務器的硬件故障
2.操做系統監控 CPU、內存、硬盤、IO、進程
3.應用服務監控 nginx、MySQL、等服務
4.業務監控php
硬件監控:
1.使用IPMI
2.機房巡檢
遠程控制卡:
DELL服務器:iDRAC
HP服務器:ILO ————-Linux就可使用IPMI(依賴於BMC控制器)
IBM服務器:IMM |
Linux是管理IPMI工具
‘ipmitool’(監控和控制)html
1.硬件要支持
2.操做系統 ‘Linux IPMI’
ipmitool安裝:linux
[root@localhost ~]# yum install OpenIPMI ipmitool -y [root@localhost ~]# rpm -qa OpenIPMI ipmitool ipmitool-1.8.13-8.el7_1.x86_64 OpenIPMI-2.0.19-11.el7.x86_64
使用IPMI有兩種方式
一、本地進行調用
二、遠程調用 (IP地址 用戶名和密碼)ios
[root@localhost ~]# systemctl start ipmi #啓動 本次以Centos7進行演示 IPMI相關命令 [root@localhost ~]# ipmitool --help ipmitool: invalid option -- '-' ipmitool version 1.8.13 usage: ipmitool [options...] <command> -h This help -V Show version information -v Verbose (can use multiple times) -c Display output in comma separated format -d N Specify a /dev/ipmiN device to use (default=0) -I intf Interface to use -H hostname Remote host name for LAN interface -p port Remote RMCP port [default=623] -U username Remote session username -f file Read remote session password from file -z size Change Size of Communication Channel (OEM) -S sdr Use local file for remote SDR cache -D tty:b[:s] Specify the serial device, baud rate to use and, optionally, specify that interface is the system one -a Prompt for remote password -Y Prompt for the Kg key for IPMIv2 authentication -e char Set SOL escape character -C ciphersuite Cipher suite to be used by lanplus interface -k key Use Kg key for IPMIv2 authentication -y hex_key Use hexadecimal-encoded Kg key for IPMIv2 authentication -L level Remote session privilege level [default=ADMINISTRATOR] Append a '+' to use name/privilege lookup in RAKP1 -A authtype Force use of auth type NONE, PASSWORD, MD2, MD5 or OEM -P password Remote session password -E Read password from IPMI_PASSWORD environment variable -K Read kgkey from IPMI_KGKEY environment variable -m address Set local IPMB address -b channel Set destination channel for bridged request -t address Bridge request to remote target address -B channel Set transit channel for bridged request (dual bridge) -T address Set transit address for bridge request (dual bridge) -l lun Set destination lun for raw commands -o oemtype Setup for OEM (use 'list' to see available OEM types) -O seloem Use file for OEM SEL event descriptions -N seconds Specify timeout for lan [default=2] / lanplus [default=1] interface -R retry Set the number of retries for lan/lanplus interface [default=4] Interfaces: open Linux OpenIPMI Interface [default] imb Intel IMB Interface lan IPMI v1.5 LAN Interface lanplus IPMI v2.0 RMCP+ LAN Interface serial-terminal Serial Interface, Terminal Mode serial-basic Serial Interface, Basic Mode Commands: raw Send a RAW IPMI request and print response i2c Send an I2C Master Write-Read command and print response spd Print SPD info from remote I2C device lan Configure LAN Channels chassis Get chassis status and set power state power Shortcut to chassis power commands event Send pre-defined events to MC mc Management Controller status and global enables sdr Print Sensor Data Repository entries and readings sensor Print detailed sensor information fru Print built-in FRU and scan SDR for FRU locators gendev Read/Write Device associated with Generic Device locators sdr sel Print System Event Log (SEL) pef Configure Platform Event Filtering (PEF) sol Configure and connect IPMIv2.0 Serial-over-LAN tsol Configure and connect with Tyan IPMIv1.5 Serial-over-LAN isol Configure IPMIv1.5 Serial-over-LAN user Configure Management Controller users channel Configure Management Controller channels session Print session information dcmi Data Center Management Interface sunoem OEM Commands for Sun servers kontronoem OEM Commands for Kontron devices picmg Run a PICMG/ATCA extended cmd fwum Update IPMC using Kontron OEM Firmware Update Manager firewall Configure Firmware Firewall delloem OEM Commands for Dell systems shell Launch interactive IPMI shell exec Run list of commands from file set Set runtime variable for shell and exec hpm Update HPM components using PICMG HPM.1 file ekanalyzer run FRU-Ekeying analyzer using FRU files ime Update Intel Manageability Engine Firmware
IPMI配置網絡,有兩種方式:
ipmi over lan(大致意思是經過網卡來進行鏈接)
獨立 (給服務器單獨插一個網線) DELL服務器能夠在小面板中設置ipmi 雲主機咱們不須要考慮IPMInginx
對於路由器和交換機:SNMP
對於這些設備,就不作具體描述了,畢竟沒有接觸過c++
系統監控
作爲系統運維來講系統監控是重點git
IO Input/Ouput(網絡、磁盤)
CPU三個重要的概念:
1.上下文切換:CPU調度器實施的進程的切換過程,上下文切換
2.運行隊列(負載):運行隊列,排隊 能夠參考我是一個進程文章
3.使用率
監控CPU須要肯定服務類型:
(1) IO密集型 (數據庫)
(2) CPU密集型(Web/mail)github
肯定性能的基準線
運行隊列:1-3個線程 1CPU 4核 負載不超過12
CPU使用:65%-70%用戶態利用率
30%-35%內核態利用率
0%-5% 空閒
上下文切換: 越少越好
全部的監控都要根據業務來考慮shell
常見的系統監控工具
Top、sysstat、mpstat數據庫
工具的使用方法
TOP參數解釋
top的詳細能夠參考我在51cto的top詳解這篇文章
其實對於Top,如今我更喜歡htop和gtop,gtop雖然色彩和功能更強大,可是由於gtop不在epel源裏,致使gtop的使用沒有htop用的普遍
固然gtop這麼好用,固然要用一下,這是個人另外一片關於gtop的文章 https://tigerfivegit.github.io/2018/12/14/Linux%E6%80%A7%E8%83%BD%E7%9B%91%E6%8E%A7%E5%B7%A5%E5%85%B7-gtop/
第一行 分別顯示:系統當前時間 系統運行時間 當前用戶登錄數 系統負載。 系統負載(load average),這裏有三個數值,分別是系統最近1分鐘,5分鐘,15分鐘的平均負載。通常對於單個處理器來講,負載在0 — 1.00 之間是正常的,超過1.00就要引發注意了。在多核處理器中,你的系統均值不該該高於處理器核心的總數。 第二行 分別顯示:total進程總數、 running正在運行的進程數、 sleeping睡眠的進程數、stopped中止的進程數、 zombie殭屍進程數。 第三行 分別顯示: %us用戶空間佔用CPU百分比、 %sy內核空間佔用CPU百分比、 %ni用戶進程空間內改變過優先級的進程佔用CPU百分比、 %id空閒CPU百分比、 %wa等待輸入輸出(I/O)的CPU時間百分比 、 %hi指的是cpu處理硬件中斷的時間、%si指的是cpu處理軟中斷的時間 、 %st用於有虛擬cpu的狀況,用來指示被虛擬機偷掉的cpu時間。 一般id%值能夠反映一個系統cpu的閒忙程度。 第四行 MEM :total 物理內存總量、 used 使用的物理內存總量、free 空閒內存總量、 buffers 用做內核緩存的內存量。 第五行 SWAP:total 交換區總量、 used使用的交換區總量、free 空閒交換區總量、 cached緩衝的交換區總量。 buffers和cached的區別須要說明一下,buffers指的是塊設備的讀寫緩衝區,cached指的是文件系統自己的頁面緩存。它們都是linux操做系統底層的機制,目的就是爲了加速對磁盤的訪問。 第六行 PID(進程號)、 USER(運行用戶)、PR(優先級)、NI(任務nice值)、VIRT(虛擬內存用量)VIRT=SWAP+RES 、RES(物理內存用量)、SHR(共享內存用量)、S(進程狀態)、%CPU(CPU佔用比)、%MEM(物理內存佔用比)、TIME+(累計CPU佔 用時間)、 COMMAND 命令名/命令行。 下面簡單介紹top命令的使用方法: top [-] [d] [q] [c] [C] [S] [n] 運維必會! 參數說明 d指定每兩次屏幕信息刷新之間的時間間隔。固然用戶可使用s交互命令來改變之。 p經過指定監控進程ID來僅僅監控某個進程的狀態。 q該選項將使top沒有任何延遲的進行刷新。若是調用程序有超級用戶權限,那麼top將以儘量高的優先級運行。 S指定累計模式。 s使top命令在安全模式中運行。這將去除交互命令所帶來的潛在危險。 i使top不顯示任何閒置或者僵死進程。 c顯示整個命令行而不僅是顯示命令名。 下面介紹在top命令執行過程當中可使用的一些交互命令 從使用角度來看,熟練的掌握這些命令比掌握選項還重要一些。 這些命令都是單字母的,若是在命令行選項中使用了s選項,則可能其中一些命令會被屏蔽掉。 Ctrl+L 擦除而且重寫屏幕。 h或者? 顯示幫助畫面,給出一些簡短的命令總結說明。 k 終止一個進程。系統將提示用戶輸入須要終止的進程PID,以及須要發送給該進程什麼樣的信號。通常的終止進程可使用15信號;若是不能正常結束那就使用信號9強制結束該進程。默認值是信號15。在安全模式中此命令被屏蔽。 i 忽略閒置和僵死進程。這是一個開關式命令。 q 退出程序。 r 從新安排一個進程的優先級別。系統提示用戶輸入須要改變的進程PID以及須要設置的進程優先級值。輸入一個正值將使優先級下降,反之則可使該進程擁有更高的優先權。默認值是10。 s 改變兩次刷新之間的延遲時間。系統將提示用戶輸入新的時間,單位爲s。若是有小數,就換算成m s。輸入0值則系統將不斷刷新,默認值是5 s。須要注意的是若是設置過小的時間,極可能會引發不斷刷新,從而根原本不及看清顯示的狀況,並且系統負載也會大大增長。 f或者F 從當前顯示中添加或者刪除項目。 o或者O 改變顯示項目的順序。 l 切換顯示平均負載和啓動時間信息。 m 切換顯示內存信息。 t 切換顯示進程和CPU狀態信息。 c 切換顯示命令名稱和完整命令行。 M 根據駐留內存大小進行排序。 P 根據CPU使用百分比大小進行排序。 T 根據時間/累計時間進行排序。 W 將當前設置寫入~/.toprc文件中。這是寫top配置文件的推薦方法。 Shift+M 可按內存佔用狀況進行排序。
sysstat 說明
yum install sysstat -y vmstat --help usage: vmstat [-V] [-n] [delay [count]] -V prints version. -n causes the headers not to be reprinted regularly. -a print inactive/active page stats. -d prints disk statistics -D prints disk table -p prints disk partition statistics -s prints vm table -m prints slabinfo -t add timestamp to output -S unit size delay is the delay between updates in seconds. unit size k:1000 K:1024 m:1000000 M:1048576 (default is K) count is the number of updates. 例子:每隔1秒獲取1次,次數不限
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 0 0 0 547332 177544 535336 0 0 1 6 5 41 1 0 98 0 0 0 0 0 547324 177544 535336 0 0 0 0 210 445 1 0 99 0 0 0 0 0 547324 177544 535336 0 0 0 0 195 435 0 0 100 0 0 0 0 0 547324 177544 535336 0 0 0 0 208 440 1 0 99 0 0 0 0 0 547332 177544 535336 0 0 0 0 209 446 0 0 100 0 0 0 0 0 547332 177544 535336 0 0 0 0 207 442 1 1 98 0 0 0 0 0 547332 177544 535336 0 0 0 0 201 438 0 0 100 0 0 #r表示CPU排隊的狀況,b表明 進程堵塞,等待io 每隔1秒獲取1次,次數10次
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu----- r b swpd free buff cache si so bi bo in cs us sy id wa st 1 0 0 547340 177544 535344 0 0 1 6 5 41 1 0 98 0 0 0 0 0 547332 177544 535344 0 0 0 28 210 453 1 1 97 1 0 0 0 0 547332 177544 535344 0 0 0 0 200 433 0 0 100 0 0 0 0 0 547332 177544 535344 0 0 0 0 211 445 1 0 99 0 0 0 0 0 547332 177544 535344 0 0 0 0 201 439 0 1 99 0 0 0 0 0 547332 177544 535344 0 0 0 0 197 436 0 0 100 0 0 0 0 0 547332 177544 535344 0 0 0 0 201 442 1 0 99 0 0 0 0 0 547324 177544 535348 0 0 0 0 240 484 2 1 97 0 0 0 0 0 547324 177544 535348 0 0 0 0 203 438 0 0 100 0 0 0 0 0 547324 177544 535348 0 0 0 0 197 430 1 0 99 0 0 mpstat 查看全部CPU的平均值 mpstat 1 Linux 2.6.32-431.23.3.el6.x86_64 (www) 08/30/2016 _x86_64_ (1 CPU) 05:13:22 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:13:23 PM all 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.00 105:13:24 PM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00 05:13:25 PM all 2.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 97.00 05:13:26 PM all 1.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.00 mpstat 1 10 Linux 2.6.32-431.23.3.el6.x86_64 (www) 08/30/2016 _x86_64_ (1 CPU) 05:13:38 PM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %idle 05:13:39 PM all 2.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.00 05:13:40 PM all 0.00 0.00 1.00 0.00 0.00 0.00 0.00 0.00 99.00 05:13:41 PM all 1.01 0.00 0.00 0.00 0.00 0.00 0.00 0.00 98.99 上述是CPU監控,CPU監控主要靠經驗。由於業務不一樣指標不一樣,指標越低越好是不變的道理
sar命令也有相似的功能,可是sar命令更能看到歷史的信息,對於問題排查有更好的做用
固然對於我這種喜歡騷操做的人,sar命令不可能不搞啊,這裏放個連接 https://tigerfivegit.github.io/2018/11/21/sar/
內存硬盤監控:
硬盤格式化後分紅塊(blog)
內存默認是頁(大小4kb)讀取按照頁來進行讀取
內存:free vmstat
free -m
total used free shared buffers cached
Mem: 1875 1338 537 0 173 523
-/+ buffers/cache: 640 1234
Swap: 0 0 0
total 總內存
used 已使用內存
free 空閒內存
shared 共享內存(進程間相互通訊使用共享內存)
buffers 緩衝
cached 緩存
Centos7 會有一個available,活動內存
#雲服務器通常不分配swap分區,物理機能不使用交換分區就不使用交換分區
vmstat 1
procs -----------memory---------- ---swap-- -----io---- --system-- -----cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
0 0 0 550628 177684 536324 0 0 1 6 7 46 1 0 98 0 0
0 0 0 550620 177684 536324 0 0 0 40 187 429 0 0 100 0 0
0 0 0 550620 177684 536324 0 0 0 0 183 427 1 0 99 0 0
0 0 0 550620 177684 536324 0 0 0 0 197 436 0 1 99 0 0
swpd交換分區的大小
free可用的物理內存大小
buff 緩衝區的大小
cache 緩存區的大小
si 數據從交換分區讀取到內存的大小
so 數據從內存到交換分區
bi 從交換分區讀到內存(block)
bo 內存寫到硬盤的
內存達到多少報警呢? 80%
硬盤:IOPS IO’s Per Second iotop df -h iostat
順序IO(快)
隨機IO(慢)
查看磁盤剩餘空間
df -h Filesystem Size Used Avail Use% Mounted on /dev/xvda1 40G 4.1G 34G 11% / tmpfs 938M 0 938M 0% /dev/shm 監控磁盤IO iotop yum install iotop -y htop
可使用dd命令生成一個文件夾進行測試
生成命令以下:
1000+0 records in 1000+0 records out 1048576000 bytes (1.0 GB) copied, 20.509 s, 51.1 MB/s [root@www ~]# ls -lh /tmp/1.txt -rw-r--r-- 1 root root 1000M Aug 30 19:48 /tmp/1.txt 此時IO寫入以下圖 IO寫如圖 iostat命令,能夠看到那塊磁盤,比iotop更加細緻
Linux 2.6.32-431.23.3.el6.x86_64 (www) 08/30/2016 _x86_64_ (1 CPU) avg-cpu: %user %nice %system %iowait %steal %idle 1.10 0.00 0.27 0.16 0.00 98.46 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn xvda 1.51 2.26 17.09 986748 7467560 avg-cpu: %user %nice %system %iowait %steal %idle 1.02 0.00 0.00 0.00 0.00 98.98 Device: tps Blk_read/s Blk_wrtn/s Blk_read Blk_wrtn xvda 0.00 0.00 0.00 0 0 tps 設備每秒的傳輸次數(每秒多少的io請求) Blk_read/s 每秒從設備讀取的數據量 Blk_wrtn/s 每秒像設備寫入的數據量 Blk_read 寫入數據的總數 Blk_wrtn 讀取數據的總數 網絡監控:iftop
iftop
正常監控只須要監控網卡帶寬便可
其中網絡監控是最複雜的,ping監控網絡延遲網絡丟包等。可是此類的網絡監控只是監控本身到客戶端是否丟包,並不能保證客戶端到服務器這邊不丟包
其中就產生了如:阿里測、奇雲測、站長工具等一系列多節點的監控工具
性能測試經常使用工具:IBM nmon (nmon analyser—生成AIX性能報告的免費工具)
http://nmon.sourceforge.net/pmwiki.php #下載地址(須要×××工具)
因此咱們提供了百度雲下載
連接:http://pan.baidu.com/s/1boXV6R9 密碼:sblf
只須要下載對應的版本,給執行權限。執行便可
1
2
nmon
咱們能夠直接輸入一個c 一個m一個d。這個是實時的一個狀態
nmon1 ./nmon16e_x86_rhel72 --help ./nmon16e_x86_rhel72: invalid option -- '-' Hint for nmon16e_x86_rhel72 version 16e Full Help Info : nmon16e_x86_rhel72 -h On-screen Stats: nmon16e_x86_rhel72 Data Collection: nmon16e_x86_rhel72 -f [-s <seconds>] [-c <count>] [-t|-T] Capacity Plan : nmon16e_x86_rhel72 -x Interactive-Mode: Read the Welcome screen & at any time type: "h" for more help Type "q" to exit nmon For Data-Collect-Mode -f Must be the first option on the line (switches off interactive mode) Saves data to a CSV Spreadsheet format .nmon file in then local directory Note: -f sets a defaults -s300 -c288 which you can then modify Further Data Collection Options: -s <seconds> time between data snapshots -c <count> of snapshots before exiting -t Includes Top Processes stats (-T also collects command arguments) -x Capacity Planning=15 min snapshots for 1 day. (nmon -ft -s 900 -c 96) ---- End of Hints -c 採集的次數 -s 採集的間隔時間 -f 生成一個文件 -m 指定生成文件位置 採集10次 間隔10秒
localhost_160831_0435.nmon nmon16e_x86_rhel72
前面爲主機名後面是日期(年月日時分)
由於測試可能須要,咱們要製做成表格,因此如今將文件上傳到桌面上
sz localhost_160831_0435.nmon
咱們打開下載的工具
解壓文件夾,打開nmon analyser v34a.xls
點擊Analyse nmon data找到咱們剛剛複製出來的文件,就能夠看到了。
應用服務監控:
舉例:Nginx
安裝nginx
1
提示:nginx可使用穩定版的最新版,由於安全性會不斷的提升。若是是特別老的版本會有一些漏洞和功能
要想監控nginx須要在編譯時添加以下參數
1
--with-http_stub_status_module
下載Nginx
wget http://nginx.org/download/nginx-1.10.1.tar.gz
解壓,後面步驟太簡單不說了
安裝
[root@localhost nginx-1.10.1]# useradd -s /sbin/nologin www [root@localhost nginx-1.10.1]# ./configure --prefix=/usr/local/nginx-1.10.1 --user=www --group=www --with-http_ssl_module --with-http_stub_status_module #configure 是一個shell腳本,執行它的做用是生成MAKEFILE(編譯make須要) [root@localhost nginx-1.10.1]# make && make install [root@localhost nginx-1.10.1]# ll total 676 drwxr-xr-x 6 1001 1001 4096 Aug 31 06:02 auto -rw-r--r-- 1 1001 1001 262898 May 31 09:47 CHANGES -rw-r--r-- 1 1001 1001 400701 May 31 09:47 CHANGES.ru drwxr-xr-x 2 1001 1001 4096 Aug 31 06:02 conf -rwxr-xr-x 1 1001 1001 2481 May 31 09:47 configure drwxr-xr-x 4 1001 1001 68 Aug 31 06:02 contrib drwxr-xr-x 2 1001 1001 38 Aug 31 06:02 html -rw-r--r-- 1 1001 1001 1397 May 31 09:47 LICENSE -rw-r--r-- 1 root root 404 Aug 31 07:46 Makefile drwxr-xr-x 2 1001 1001 20 Aug 31 06:02 man drwxr-xr-x 3 root root 119 Aug 31 07:46 objs -rw-r--r-- 1 1001 1001 49 May 31 09:47 README drwxr-xr-x 9 1001 1001 84 Aug 31 06:02 src #make是生成文件,make install是將生成的文件拷貝到不一樣的地方 make install 完成以後能夠直接將當前目錄拷貝到其餘服務器上,安裝相同的依賴就能夠進行使用。 [root@localhost nginx-1.10.1]# ln -s /usr/local/nginx-1.10.1/ /usr/local/nginx [root@localhost nginx-1.10.1]# netstat -lntp|grep nginx tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 7058/nginx: master 修改nginx.conf配置文件 location /status { stub_status on; access_log off; allow 192.168.56.0/24; deny all; }
設置只容許56網段訪問,並開啓日誌和狀態模塊
#這個比較基礎,若是不知道怎麼添加。能夠參考www.nginx.org 狀態模塊
瀏覽器訪問:http://192.168.56.11/status
Active connections: 1 server accepts handled requests 3 3 163 Reading: 0 Writing: 1 Waiting: 0 Active connections: 當前活躍的鏈接數 3—-> 一共處理了多少個連接(請求) 3—-> 成功建立多少次握手 163–> 總共建立了多少個請求 Reading:當前讀取客戶端heardr的數量 Writing:當前返回給客戶端heardr的數量 #若是這個指標飆升,說明是後面的節點掛掉了,例如數據庫等。 Waiting:大致意思是已經處理完,等待下次請求的數量 提示:咱們只須要關注活動連接便可
監控最基礎的功能
採集 存儲 展現 告警
幾款監控軟件說明:幾款監控軟件你們都知道應該是zabbix,這個入門和部署比較簡單,對於中小企業都是友好的,可是難以細化和深刻化。後來因業務需求從zabbix逐漸轉用小米的開源監控open-falcon,這個對於新手不太友好,可是後期的添加和細化都是特別友好的,模塊化、分支化