linux常用服務軟體搭建及使用技巧

狂師發表於2019-05-14

一、Webmin安裝:

Webmin 是一個基於瀏覽器的管理工具,可以應用於Linux 和其他一些平臺,提供了可以完成很多管理和操作任務的圖形化介面

•安裝完成後,root 使用者會被自動建立,密碼為系統的root密碼

(下載地址:URL:http://www.webmin.com/

 

安裝步驟: rpm -ivh webmin-1.250-1.noarch.rpm

 

使用步驟:Http://ip:10000/

 

 

———————————————————————————–

二、Linux防火牆相關命令:

1). 敲入 /etc/init.d/iptables stop,關閉之後再次檢視80.112.*.*:8080(即ip:8080),可以成功訪問。

          但是貌似安全隱患大大增加……

      2). 敲入 /etc/init.d/iptables status,檢視防火牆資訊,可以看到開啟的埠

      3).如果只需 把要使用的埠開啟,命令如下:

           /sbin/iptables -I INPUT -p tcp –dport 8080 -j ACCEPT #8080為指定埠

      4). /etc/rc.d/init.d/iptables save  #將更改進行儲存

      5). /etc/init.d/iptables restart      #重啟防火牆以便改動生效

          還有另外直接在 /etc/sysconfig/iptables中增加一行:

         -A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 8080 -j ACCEPT

停止防火牆  service iptables stop   (iptables –F 關閉防火牆)

啟動防火牆  service iptables start

檢視防火牆配置 iptables -L -n

 

chkconfig iptables on //永久性啟動防火牆

chkconfig iptables off //永久性關閉防火牆

 

—————————————————————————-

三、Gcc安裝方法(redhat 4):

一、安裝步驟

1、使用which gcc命令檢視gcc是否安裝安裝

2、如若沒有安裝則下載如下安裝包,所需安裝包如下

一共需要拷貝以下五個安裝包:

binutils-2.13.90.0.18-9.i386.rpm

glibc-devel-2.3.2-11.9.i386.rpm

cpp-3.2.2-5.i386.rpm

glibc-kernheaders-2.4-8.10.i386.rpm

gcc-3.2.2-5.i386.rpm

 

安裝順序如下:(如若在rpmp安裝過程中出現依賴關係,則增加—nodeps引數)

Rpm –ivh binutils-2.13.90.0.18-9.i386.rpm

Rpm -ivh cpp-3.2.2-5.i386.rpm

Rpm -ivh glibc-kernheaders-2.4-8.10.i386.rpm

Rpm -ivh glibc-devel-2.3.2-11.9.i386.rpm

Rpm -ivhgcc-3.2.2-5.i386.rpm

 

四、Apache服務安裝:

一、安裝apache(http服務)

1. 從apache.org下載原始碼安裝包

2. 解壓縮
# tar zxf httpd-2.2.4.tar.gz
# cd httpd-2.2.4

3. 安裝apache依賴包apr和apr-util,他們都在srclib目錄中

3.1 安裝apr
# cd srclib/apr
# ./configure –prefix=/usr/local/apr
# make
# make install

3.2 安裝apr-util
# cd ../apr-util
# ./configure –prefix=/usr/local/apr-util –with-apr=/usr/local/apr
# make
# make install

4.安裝httpd
# cd ../../
# ./configure –prefix=/usr/local/httpd –with-apr=/usr/local/apr –with-apr-util=/usr/local/apr-util –enable-so –enable-rewrite
# make
# make install

–enable-so 支援DSO模式(動態模組載入方式)
–enable-rewrite 支援rewrite(地址重定向)

等這些都裝完後,開啟瀏覽器,輸入你安裝apache所在的伺服器地址,看起來像這個樣子:
http://192.168.1.3/

如果頁面顯示如下:
It works!

恭喜你,apache安裝成功了~

 

# 當開啟apache服務時,提示錯誤資訊 httpd: apr_sockaddr_info_get() failed for bogon

     httpd: Could not reliably determine the server`s fully qualified domain name, using 127.0.0.1 for ServerName

    解決方法:

/etc/httpd/conf/httpd.conf 中設定 ServerName。所以apache會用主機上的名稱來取代,首先會去找 /etc/hosts 中有沒有主機的定義。

所以要解決這個問題可以設定httpd.conf檔案中的 ServerName,如下:

   (1)ServerName localhost:80                        

 

五、VSFTP安裝:

 

安裝之前的準備:

–mkdir /var/ftp

–useradd -d /var/ftp -s /sbin/nologin ftpuser

–passwd ftpuser

–chown ftpuser:root /var/ftp

•安裝

–以下步驟需要在vsftpd-2.0.3.tar.gz所在的資料夾操作

–gzip -d vsftpd-2.0.3.tar.gz

–tar xvf vsftpd-2.0.3.tar

–cd vsftpd-2.0.3

–make

–make install

 

–cp RedHat/vsftpd.pam /etc/pam.d/ftp

–cp vsftpd.conf /etc/

–vi /etc/vsftpd.conf

刪除下面三行中的#

# local_enable =YES

# write_enable=YES

# local_umask=022

增加:listen=YES (vsftpd獨立啟動,需要刪除在系統服務中啟動)

 

•服務啟動

–vsftpd &

•服務停止

–ps –A | grep vsftpd

–kill -9 id

 

測試

–在windows開啟IE輸入:ftp://ip/

–從windows中拷貝檔案到ftp中

–使用CuteFTP 7 Professional,FTP客戶端工具

•錯誤以及處理:

–錯誤:vsftpd啟動時顯示:500 OOPS: could not bind listening IPv4 socket

–原因:vsftpd已經啟動

–處理:

如果vsftpd獨立啟動,則使用kill殺掉程式,再次啟動

如果vsftpd在xinetd中啟動,則從其xinetd服務

/etc/rc.d/init.d/xinetd restart

 

 

六、LoadRunner如何監控Linux下的系統資源:

條件一:

前一時間在研究LoadRunner過程中,在進行壓力場景測試中通過LoadRunner來實時監控windows的系統資源,在前幾節中我已經總結了相關過程,近段時間發現群裡有朋友問如何監控Linux下的系統資源,所以我也就此問題搭建了一些的Linux環境,並在Linux下部署了一個web應用程式,來進行壓力測試例項的講解,在此就總結了如何設定LoadRuner來實時監控Linux系統資源。

關於LoadRunner監控Linux系統資源,大致分為以下步驟:

1、在監控Linux之前我想闡述的觀點是,Liunx系統機制與windows大致相同,要監控並得到他的相關引數必須需要得到它的同意,這就是作業系統,所以你必須有足夠的許可權和方法才能獲得,關於Linux在LR中也相關新增區域,與windows享有同等的地位。在windows中需要開啟許多許多許可權,以及一些遠端訪問的程式,當前在Linux中也不例外,在Linux下有一個程式是必須的,那就是系統守護程式rpc.restat,相信守護程式大家並不陌生,通常在Linux系統的引導的時候啟動的很多服務,這些服務就是守護程式,而且它脫離於終端在後臺執行的。

所以首先要檢視系統是否開啟了rpc服務,通過命令rpcinfo -p來檢視

 

如上圖可以看到,如果開啟了四個rstatd服務就說明,該rpc守護程式服務啟動是成功的。如果沒有該服務,就需要手動安裝了

下載地址:http://heanet.dl.sourceforge.net/sourceforge/rstatd/

安裝:一次執行–tar -xzvf rpc.rstatd-4.0.1.tar.gz //解壓安裝包

cd rpc.rstatd-4.0.1        //進入到rpc.rstatd目錄中

./configure    //配置rc.rstatd安裝

make //編輯rc.rstatd

make install //安裝

2、重啟埠對映服務portmap

/etc/rc.d/init.d/portmap start   //啟動portmap

找到portmap服務就ok

3、通過命令rpcinfo -p來檢測即可,如1中圖所示證明,服務安裝和啟動是成功的。

4、在LoadRunner場景中新增linux系統資源項

這裡需要注意的一點是,當我們第一次新增linux資源服務時,可能會提示錯誤資訊,提示為rpc服務在客戶端新增失敗,如果遇到這種情況,可能大家又覺得又要失望,不要擔心,分析錯誤的原因,基本可以確定遠端沒有獲取到rpc服務,應該是被什麼被劫持了,來看看系統防火牆,cat /etc/sysconfig/iptables的配置,果然需要加入rpc訪問策略,為此我關閉了防火牆服務,所以就不需要設定防火牆策略了,命令為:

chkconfig iptables on //永久性啟動防火牆

chkconfig iptables off //永久性關閉防火牆

關閉防火牆之後再在LoadRunner場景中新增Linux資源,如下圖所示:

 

看到如上的圖表和曲線圖就表示配置ok了,攻破LoadRunner我們取得一些進步。

 

 

條件二:

一 簡述:LoadRunner監控Linux資源時彈出如下錯誤:

  Monitor name :UNIX Resources. Cannot initialize the monitoring on 192.168.52.189. Error while creating the RPC client. Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility for this verification). Detailed error: RPC: Failed to create RPC client.

  RPC-TCP: Failed to establish RPC server address.

  上述問題的實質是Linux系統中未安裝rpc.rstatd,服務未開啟的原因造成。

  於是接下來就驗證我們的推測:

  首先檢視rpc.rstatd是否安裝

  以下是程式碼片段:

  [root@localhost bin]# whereis rpc.rstatd

  發現系統未安裝rpc.rstatd

  備註:rstatd Rstat協議允許網路上的使用者獲得同一網路上各機器的效能引數。

  二 準備下載包:下載rpc.rstatd-4.0.1.tar.gz安裝包

  下載地址:http://sourceforge.net/projects/rstatd

  利用ssh客戶端上傳rpc.rstatd-4.0.1.tar.gz包至Linux下/home/Michael/tool/目錄下

  三 執行安裝程式包:

  以下是程式碼片段:

  tar -xzvf rpc.rstatd-4.0.1.tar.gz //解壓rcp.rstatd

  cd rpc.rstatd-4.0.1 //進入到rpc.rstatd目錄中

  ./configure //配置rc.rstatd的安裝,以下我的是按照預設方式的

  make //編譯rc.rstatd

  make install // 安裝

  四 重啟xinetd

  以下是程式碼片段:

  /etc/init.d/xinetd restart

  五 修改etc/xinetd.d目錄下面的3個conf (rlogin, rsh, rexec)中的disable置均設定為no

  以下是程式碼片段:

  cd /etc/xinetd.d //進入到etc/xinetd.conf目錄中

  Vi rlogin //編輯disable=no,儲存

  Vi rsh // 編輯disable=no,儲存

  Vi rexec //編輯disable=no,儲存

  六 啟動rpc.rstatd和檢測

  以下是程式碼片段:

  rpc.rstatd //啟動rpc.rstatd程式

  rpcinfo –p // 執行此命令檢查rpc服務的狀態

  [root@localhost xinetd.d]# rpcinfo -p

  程式版本協議 埠

  100000 2 tcp 111 portmapper

  100000 2 udp 111 portmapper

  100024 1 udp 32768 status

  100024 1 tcp 32769 status

  100001 5 udp 867 rstatd

  100001 3 udp 867 rstatd

  100001 2 udp 867 rstatd

  100001 1 udp 867 rstatd

  七 利用Loadunner中的Controller監控Linux資源

  1 在controller中,將Systeme Resourece Graphs中的UNIX resources拖到右鍵的資源監控區域

2 滑鼠右鍵選擇Add Measurements,新增被監控linux的IP地址192.168.52.189,選擇需監控的效能指標,確認後,如下圖所示即表示成功^_^

 

條件三:

LR監控UNIX/Linux系統方法 

一、準備工作: 

1.可以通過兩種方法驗證伺服器上是否配置rstatd守護程式: 

①使用rup命令,它用於報告計算機的各種統計資訊,其中就包括rstatd的配置資訊。使用命令rup 10.130.61.203,此處10.130.61.203是要監視的linux/Unix伺服器的IP,如果該命令返回相關的統計資訊。則表示已經配置並且啟用了rstatd守護程式;若未返回有意義的統計資訊,或者出現一條錯誤報告,則表示rstatd守護程式尚未被配置或有問題。 

②使用find命令 

#find / -name rpc.rstatd,該命令用於查詢系統中是否存在rpc.rstatd檔案,如果沒有,說明系統沒有安裝rstatd守護程式。 

2.linux需要下載3個包: (1)rpc.rstatd-4.0.1.tar.gz (2)rsh-0.17-14.i386.rpm  (3)rsh-server-0.17-14.i386.rpm  3.下載並安裝rstatd  

如果伺服器上沒有安裝rstatd程式(一般來說LINUX都沒有安裝),需要下載一個包才有這個服務,包名字是rpc.rstatd-4.0.1.tar.gz. 這是一個原始碼,需要編譯,下載並安裝rstatd(可以在http://sourceforge.net/projects/rstatd這個地址下載)下載後,開始安裝,安裝步驟如下: 

tar -xzvf rpc.rstatd-4.0.1.tar.gz cd rpc.rstatd-4.0.1/ ./configure —配置操作 make —進行編譯 make install —開始安裝 rpc.rstatd —啟動rstatd程式 

“rpcinfo -p”命令來檢視當前系統是否已經啟動了rstatd守護程式 

只要保證Linux機器上的程式裡有rstatd和xinetd這二個服務就可以用LR去監視了,通過以下 兩點可以檢查是否啟動: 

1)檢查是否啟動: rsh server 監聽的TCP 是514。 

 

 

 [root@mg04 root]# netstat -an |grep 514 tcp 0 0 0.0.0.0:514 0.0.0.0:* LISTEN 

如果能看到514在監聽說明rsh伺服器已經啟動。 2)檢查是否啟動: rstatd 輸入命令: rpcinfo -p 如果能看到類似如下資訊: 程式版本協議埠 

100001    5   udp    937  rstatd 100001    4   udp    937  rstatd 100001    3   udp    937  rstatd 100001    2   udp    937  rstatd 100001    1   udp    937  rstatd 

那就說明rstatd服務啟動了,(當然這裡也可以用ps ax代替) 4.安裝rsh和rsh-server兩個服務包方法 a. 解除安裝rsh  

# rpm –q  rsh———-檢視版本號 # rpm  -e 版本號———解除安裝該版本。 b.安裝 

# rpm –ivh rsh-0.17-14.i386.rpm rsh-server-0.17-14.i386.rpm  

在啟動rpc.rstatd時,會報錯“Cannot register service: RPC: Unable to receive; errno = Ction refused”。 解決方法如下: 

# /etc/init.d/portmap start  # /etc/init.d/nfs start  

然後再次啟動rpc.rstatd就好了。 5.安裝xinetd方法: 

①檢視xinetd服務:[root@localhost ~]# rpm -q xinetd        

xinetd-2.3.14-10.el5 

②安裝xinetd服務:[root@localhost ~]# yum install xinetd 

如果安裝不起xinetd服務,執行下列操作命令後再次執行yum install xinetd命令進行安裝: yum clean packages清除快取目錄下的軟體包 

 

 

 

 

 

 

yum clean headers清除快取目錄下的 headers yum clean oldheaders清除快取目錄下舊的 headers 

yum clean, yum clean all (= yum clean packages; yum clean oldheaders) 清除快取目錄下的軟體包及舊的headers。 6.啟動xinetd服務: 

在有的系統中,通過如下命令重啟: # service xinetd reload # /sbin/service xinetd rstart 在suse linux 中如下操作: cd /etc/init.d/xinetd restart 

2)安裝完成後配置rstatd 目標守護程式xinetd,它的主配置檔案是/etc/xinetd.conf ,它裡面內容是一些如下的基本資訊: 

# xinetd.conf # 

# Copyright (c) 1998-2001 SuSE GmbH Nuernberg, Germany. # Copyright (c) 2002 SuSE Linux AG, Nuernberg, Germany. # defaults { 

        log_type     = FILE /var/log/xinetd.log         log_on_success = HOST EXIT DURATION         log_on_failure = HOST ATTEMPT #        only_from      = localhost         instances       = 30         cps            = 50 10 # 

# The specification of an interface is interesting, if we are on a firewall. # For example, if you only want to provide services from an internal # network interface, you may specify your internal interfaces IP-Address. 

 

 

 

 

 

 

#       interface       = 127.0.0.1 } 

includedir /etc/xinetd.d 

我們這裡需要修改的是/etc/xinetd.d/下的三個conf檔案 rlogin ,rsh,rexec 這三個配置檔案,打這三個檔案裡的disable = yes都改成 disable = no ( disabled 用在預設的 {} 中禁止服務)或是把# default: off都設定成 on 這個的意思就是在xinetd啟動的時候預設都啟動上面的三個服務! 

說明:我自己在配置時,沒有disable = yes這項,我就將# default: off改為:default: on,重啟後(cd /etc/init.d/./xinetd restart)通過netstat -an |grep 514檢視,沒有返回。然後,我就手動在三個檔案中最後一行加入disable = no,再重啟xinetd,再使用netstat -an |grep 514檢視,得到tcp 0 0 0.0.0.0:514 0.0.0.0:* LISTEN結果,表明rsh伺服器已經啟動。 

看到網上有的地方說使用如下命令: # service xinetd reload # /sbin/service xinetd rstart  不知道是在什麼系統用的。 二、監控linux資源: 

在controller中,將System resource Graphs中的Unix resources拖到右側的監控區域中,並單擊滑鼠右鍵選擇“Add Measurements”,在彈出的對話方塊中輸入被監控的linux系統的IP地址,然後選擇需要監控的效能指標,並點選“確定”,出現如下結果: 

Monitor name :UNIX Resources. Cannot initialize the monitoring on 10.10.15.62.  

Error while creating the RPC client. Ensure that the machine can be connected and that it runs the rstat daemon (use rpcinfo utility for this verification). 

Detailed error: RPC: Failed to create RPC client. RPC-TCP: Failed to establish RPC server address. 

RPC-TCP: Failed to communicate with the portmapper on host `10.10.15.62`. RPC: RPC call failed. 

RPC-TCP: recv()/recvfrom() failed. 

RPC-TCP: Timeout reached. (entry point: CFactory::Initialize). [MsgId: MMSG-47190] 

檢查原因,發現是Linux系統中的防火牆開啟了並且阻擋了LoadRunner監控Linux系統的資源,因此要將防火牆關閉。 

 

 

 

 

 

 

關閉防火牆: [root@localhost ~]# /etc/init.d/iptables stop; 三、監控UNIX 

lr監控UNIX ,UNIX先啟動一rstatd服務 以下是在IBM AIX系統中啟動rstatd服務的方法: 1.使用telnet以root使用者的身份登入入AIX系統 2.在命令列提示符下輸入:vi /etc/inetd.conf 3.查詢rstatd,找到 

#rstatd   sunrpc_udp    udp    wait   root /usr/sbin/rpc.rstatd rstatd 100001 1-3 4、將#去掉 

5、:wq儲存修改結果 

6、命令提示符下輸入:refresh –s inetd 重新啟動服務。 這樣使用loadrunner就可以監視AIX系統的效能情況了。 

注:在HP UNIX系統上編輯完inetd.conf後,重啟inetd服務需要輸入inetd -c UNIX上也可以用rup命令檢視rstatd程式是否被配置並啟用 

若rstatd程式已經執行,重啟時,先檢視程式ps -ef |grep inet,然後殺掉程式,再refresh –s inetd進行重啟。

  

七、監控linux系統資源(Dstat):

你可以使用Dstat可以檢視實時系統的所有資源,將你的磁碟利用率同你的智慧磁碟裝置控制器的中斷情況進行比對,或比較與磁碟吞吐量的網路頻寬,都是數字比較直觀。

Dstat 監測結果帶顏色,看著更直觀,方便。
官方網站:http://packages.sw.be/dstat/

 

Usage: dstat [-afv] [options..] [delay [count]]
Versatile tool for generating system resource statistics
 
常用引數用法(Dstat options):
  -c, --cpu              enable cpu stats
     -C 0,3,total           include cpu0, cpu3 and total
  -d, --disk             enable disk stats
     -D total,hda           include hda and total
  -g, --page             enable page stats
  -i, --int              enable interrupt stats
     -I 5,eth2              include int5 and interrupt used by eth2
  -l, --load             enable load stats
  -m, --mem              enable memory stats
  -n, --net              enable network stats
     -N eth1,total          include eth1 and total
  -p, --proc             enable process stats
  -r, --io               enable io stats (I/O requests completed)
  -s, --swap             enable swap stats
     -S swap1,total         include swap1 and total
  -t, --time             enable time/date output
  -T, --epoch            enable time counter (seconds since epoch)
  -y, --sys              enable system stats
  --aio                  enable aio stats
  --fs, --filesystem     enable fs stats
  --ipc                  enable ipc stats
  --lock                 enable lock stats
  --raw                  enable raw stats
  --socket               enable socket stats
  --tcp                  enable tcp stats
  --udp                  enable udp stats
  --unix                 enable unix stats
  --vm                   enable vm stats
 
  --plugin-name          enable plugins by plugin name (see manual)
  --list                 list all available plugins
 
  -a, --all              equals -cdngy (default)
  -f, --full             automatically expand -C, -D, -I, -N and -S lists
  -v, --vmstat           equals -pmgdsc -D total
 
  --float                force float values on screen
  --integer              force integer values on screen
 
  --bw, --blackonwhite   change colors for white background terminal
  --nocolor              disable colors (implies --noupdate)
  --noheaders            disable repetitive headers
  --noupdate             disable intermediate updates
  --output file          write CSV output to file
 
delay is the delay in seconds between each update (default: 1)
count is the number of updates to display before exiting (default: unlimited)
nginx $> dstat
You did not select any stats, using -cdngy by default.
----total-cpu-usage---- -dsk/total- -net/total- ---paging-- ---system--
usr sys idl wai hiq siq| read  writ| recv  send|  in   out | int   csw
  0   2  97   1   0   0|  57k  167k|   0     0 |   0     0 |  40    74
  0   0 100   0   0   0|   0     0 | 152B  826B|   0     0 |   8    10
  0   0 100   0   0   0|   0     0 | 152B  346B|   0     0 |   9    13
  0   0 100   0   0   0|   0     0 | 152B  346B|   0     0 |   8     8
  0   0 100   0   0   0|   0     0 | 244B  346B|   0     0 |   9     8
  0   1  99   0   0   0|   0     0 | 152B  346B|   0     0 |   8     8
  0   0 100   0   0   0|   0     0 | 120B  346B|   0     0 |   8     8
  0   1  99   0   0   0|   0     0 |  60B  346B|   0     0 |   9    12
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |   7     8
  0   1  99   0   0   0|   0     0 |  60B  346B|   0     0 |   8     8
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |   6     8
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |   7     8
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |   8    13
  0   0 100   0   0   0|   0     0 |  60B  346B|   0     0 |   6     9

常用引數:

nginx $> dstat -c --top-cpu -d --top-bio --top-latency

 

 nginx $>dstat -cdlmnpsy

 

 

八、Linux系統維護常用工具sysstat:

Linux系統維護常用工具sysstat:sysstat這個工具,可以說是linux &Unix; 以及Freebsd最常用的工具。它的主要用途就是觀察服務負載,比如CPU和記憶體的佔用率、網路的使用率以及磁碟寫入和讀取速度等

 

一、sar的最後兩個引數一般是interval count

1sar -u 1 5
輸出CPU使用情況的統計資訊,每秒輸出一次,一共輸出5

[root@stage1-new9 sysstat-10.0.5]# sar -u 1 5
Linux 2.6.9-67.ELsmp (stage1-new9.intra99bill.com)      06/12/2012      _x86_64_        (8 CPU)

11:34:43 AM     CPU     %user     %nice    %system         %iowait    %steal     %idle
11:34:44 AM     all          0.00           0.00      0.00              0.00          0.00    100.00
11:34:45 AM     all          0.00           0.00      0.12              0.00          0.00     99.88
11:34:46 AM     all          0.00           0.00      0.00              0.00          0.00    100.00
11:34:47 AM     all          0.00           0.00      0.12              0.00          0.00     99.88
11:34:48 AM     all          0.00           0.00      0.00              0.00          0.00    100.00
Average:            all          0.00           0.00      0.05             0.00           0.00     99.95

CPU      all 表示統計資訊為所有 CPU 的平均值。                                       
%user    顯示在使用者級別(application)執行使用CPU 總時間的百分比。                   
%nice    顯示在使用者級別,用於nice操作,所佔用CPU 總時間的百分比。             
%system 在核心級別(kernel)執行所使用CPU 總時間的百分比。       
%iowait 顯示用於等待I/O操作佔用CPU 總時間的百分比。
%steal   管理程式(hypervisor)為另一個虛擬程式提供服務而等待虛擬 CPU 的百分比。
%idle    顯示 CPU 空閒時間佔用CPU 總時間的百分比。

Tips:
若 %iowait 的值過高,表示硬碟存在I/O瓶頸
若 %idle 的值高但系統響應慢時,有可能是CPU 等待分配記憶體,此時應加大記憶體容量
若 %idle 的值持續低於10,則系統的CPU 處理能力相對較低,表明系統中最需要解決的資源是CPU。

2sar -b 1 5
顯示I/O和傳送速率的統計資訊
17時09分07秒       tps        rtps      wtps   bread/s   bwrtn/s
17時09分08秒      3.12      3.12      0.00     25.00      0.00
17時09分09秒     89.58      6.25     83.33    141.67    733.33
17時09分10秒     42.71      9.38     33.33    141.67    600.00
17時09分11秒      2.11      2.11      0.00     16.84      0.00
17時09分12秒      1.04      0.00      1.04      0.00    175.00
Average:        27.77      4.18     23.59     65.14    302.30

tps     每秒鐘物理裝置的 I/O 傳輸總量                   
rtps    每秒鐘從物理裝置讀入的資料總量                  
wtps    每秒鐘向物理裝置寫入的資料總量                  
bread/s 每秒鐘從物理裝置讀入的資料量,單位為 塊/s    
bwrtn/s 每秒鐘向物理裝置寫入的資料量,單位為 塊/s

二、iostat

    # iostat -x 1 10    //每隔1秒統計一次,共顯示10

[root@stage1-new9 sysstat-10.0.5]# iostat -x 1 10
Linux 2.6.9-67.ELsmp (stage1-new9.intra99bill.com)      06/12/2012      _x86_64_        (8 CPU)

avg-cpu:           %user   %nice  %system %iowait  %steal   %idle
                      0.24        0.00      0.20          0.00       0.00     99.56

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda              0.00         0.59      0.01    0.71   0.13     5.28    15.07     0.00          4.51   3.81      4.51      0.52   0.04

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
                0.00        0.00    0.00        0.00    0.00       100.00

Device:         rrqm/s   wrqm/s     r/s     w/s    rkB/s    wkB/s avgrq-sz avgqu-sz   await r_await w_await  svctm  %util
sda                0.00     8.00       0.00    2.00    0.00    40.00    40.00       0.00        0.00   0.00     0.00       0.00   0.00

avg-cpu:  %user   %nice %system %iowait  %steal   %idle
               0.00       0.00     0.00        0.00      0.00  100.00

rrqm/s:   每秒進行 merge 的讀運算元目。即 delta(rmerge)/s

wrqm/s: 每秒進行 merge 的寫運算元目。即 delta(wmerge)/s

r/s:           每秒完成的讀 I/O 裝置次數。即 delta(rio)/s

w/s:         每秒完成的寫 I/O 裝置次數。即 delta(wio)/s

rsec/s:    每秒讀扇區數。即 delta(rsect)/s

wsec/s: 每秒寫扇區數。即 delta(wsect)/s

rkB/s:      每秒讀K位元組數。是 rsect/s 的一半,因為每扇區大小為512位元組。(需要計算)

wkB/s:    每秒寫K位元組數。是 wsect/s 的一半。(需要計算)

avgrq-sz: 平均每次裝置I/O操作的資料大小 (扇區)。delta(rsect+wsect)/delta(rio+wio)

avgqu-sz: 平均I/O佇列長度。即 delta(aveq)/s/1000 (因為aveq的單位為毫秒)。
await:    平均每次裝置I/O操作的等待時間 (毫秒)。即 delta(ruse+wuse)/delta(rio+wio)

svctm:   平均每次裝置I/O操作的服務時間 (毫秒)。即 delta(use)/delta(rio+wio)

%util:      一秒中有百分之多少的時間用於 I/O 操作,或者說一秒中有多少時間 I/O 佇列是非空的。即 delta(use)/s/1000 (因為use的單位為毫秒)

如果 %util 接近 100%,說明產生的I/O請求太多,I/O系統已經滿負荷,該磁碟可能存在瓶頸。

idle小於70% IO壓力就較大了,一般讀取速度有較多的wait。 同時可以結合vmstat 檢視檢視b引數(等待資源的程式數)和wa引數(IO等待所佔用的CPU時間的百分比,高過30%時IO壓力高)

另外還可以參考:
        svctm 一般要小於 await (因為同時等待的請求的等待時間被重複計算了),svctm 的大小一般和磁碟效能有關,CPU/記憶體的負荷也會對其有影響,請求過多也會間接導致 svctm 的增加。await 的大小一般取決於服務時間(svctm) 以及 I/O 佇列的長度和 I/O 請求的發出模式。如果 svctm 比較接近 await,說明 I/O 幾乎沒有等待時間;如果 await 遠大於 svctm,說明 I/O 佇列太長,應用得到的響應時間變慢,如果響應時間超過了使用者可以容許的範圍,這時可以考慮更換更快的磁碟,調整核心 elevator 演算法,優化應用,或者升級 CPU。

        佇列長度(avgqu-sz)也可作為衡量系統 I/O 負荷的指標,但由於 avgqu-sz 是按照單位時間的平均值,所以不能反映瞬間的 I/O 問題。
 

 

 

 

技術改變世界!
–狂詩絕劍


相關文章