Hadoop2.7實戰v1.0之Linux引數調優

hackeruncle發表於2016-04-30

 Hadoop2.7實戰v1.0之Linux引數調優 

1.增大檔案描述符nofile(檢視當前的lsof |wc -l) 和 使用者最大程式nproc
a>.調整Linux的最大檔案開啟數和程式數。
        vi /etc/security/limits.conf
          * soft nofile 65535
          * hard nofile 65535
          * soft nproc 65535
          * hard nproc 65535
         
b>.RHEL6下引入了配置檔案
vi /etc/security/limits.d/90-nproc.conf
  * soft nproc 65535

c>.pam_limits.so 檔案被加入到啟動檔案
        vi /etc/pam.d/login
           session    required     /lib/security/pam_limits.so
           session    required     pam_limits.so
          
d>.重啟
reboot

#######只針對當前session會話,快速設定
[testuser@xxx-01 root]$  ulimit -u
1024
[testuser@xxx-01 root]$  ulimit -u 65535
[testuser@xxx-01 root]$  ulimit -u
65535
-n <檔案數目>  指定同一時間最多可開啟的檔案數。  
-u <程式數目>  使用者最多可啟動的程式數目。 


2.網路(兩個網路相關的引數可以影響Hadoop的效能。net.core.somaxconn Linux核心設定能夠支援NameNode和JobTracker的大量爆發性的HTTP請求)
a>.net.core.somaxconn是listen()的預設引數,掛起請求的最大數量.預設是128.對繁忙的伺服器,增加該值有助於網路效能,當前已經被調整到32768
more /etc/sysctl.conf |grep net.core.somaxconn
sysctl -w net.core.somaxconn=32768 
echo net.core.somaxconn=32768 >> /etc/sysctl.conf


b>.設定txqueuelen到4096及以上能夠更好地適應在Hadoop叢集中的突發流量, txqueuelen代表用來傳輸資料的緩衝區的儲存長度,
透過下面的命令可以對該引數進行設定為4096。
[testuser@xxx-01 conf]# ifconfig
eth0      Link encap:Ethernet  HWaddr 00:16:3E:02:00:2B  
 inet addr:xx.xxx.xx.x  Bcast:xx.xxx.xx.xxx  Mask:255.255.255.0
 UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
 RX packets:55072078 errors:0 dropped:0 overruns:0 frame:0
 TX packets:33328184 errors:0 dropped:0 overruns:0 carrier:0
 collisions:0 txqueuelen:1000 
 RX bytes:23381014283 (21.7 GiB)  TX bytes:4464530654 (4.1 GiB)
   
  ###發現當前的eth0的txqueuelen值為1000,設定為4096
 [testuser@xxx-01 conf]# ifconfig eth0 txqueuelen 4096

3.關閉swap分割槽
        more /etc/sysctl.conf | vm.swappiness
        echo vm.swappiness = 0 >> /etc/sysctl.conf

4.設定合理的預讀取緩衝區(readahead buffer)大小
調整linux檔案系統中預讀緩衝區地大小,可以明顯提高順序讀檔案的效能。預設buffer大小為256 sectors,可以增大為1024或者2408 sectors(注意,並不是越大越好)。可使用blockdev命令進行調整。

[testuser@xxx-01 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/vda1        40G  7.1G   31G  19% /
tmpfs           3.9G     0  3.9G   0% /dev/shm
/dev/vdb1       197G   36G  152G  19% /data/01
[testuser@xxx-01 ~]# 
[testuser@xxx-01 ~]# blockdev --report
RO    RA   SSZ   BSZ   StartSec            Size   Device
rw   256   512  4096          0     42949672960   /dev/vda
rw   256   512  4096       2048     42947575808   /dev/vda1
rw   256   512  4096          0    214748364800   /dev/vdb
rw   256   512  4096         63    214748029440   /dev/vdb1

### 修改/dev/vdb1的readahead buffer,因為hadoop的dfs nn等等資料夾是在這個目錄下
   [testuser@xxx-01 ~]# blockdev --setra 1024 /dev/vdb1
     
5.I/O排程器選擇(一般不調整,只會在mapreduce中調整)
主流的Linux發行版自帶了很多可供選擇的I/O排程器。在資料密集型應用中,不同的I/O排程器效能表現差別較大,
管理員可根據自己的應用特點啟用最合適的I/O排程器

6.vm.overcommit_memory設定
程式通常呼叫malloc()函式來分配記憶體,記憶體決定是否有足夠的可用記憶體,並允許或拒絕記憶體分配的請求。Linux支援超量分配記憶體,以允許分配比可用RAM加上交換記憶體的請求。
    vm.overcommit_memory引數有三種可能的配置:
      0 表示檢查是否有足夠的記憶體可用,如果是,允許分配;如果記憶體不夠,拒絕該請求,並返回一個錯誤給應用程式。
      1 表示根據vm.overcommit_ratio定義的值,允許分配超出實體記憶體加上交換記憶體的請求。vm.overcommit_ratio引數是一個百分比,加上記憶體量決定記憶體可以超量分配多少記憶體。
     例如,vm.overcommit_ratio值為50,而記憶體有1GB,那麼這意味著在記憶體分配請求失敗前,加上交換記憶體,記憶體將允許高達1.5GB的記憶體分配請求。
      2 表示核心總是返回true。
     除了以上幾個常見的Linux核心調優方法外,還有一些其他的方法,管理員可根據需要進行適當調整。
         
       【檢視當前值】
# sysctl -n vm.overcommit_memory
       【永久性修改核心引數】
在/etc/sysctl.conf檔案裡面加入或者直接刪除也可以,因為它預設值就是0
vm.overcommit_memory = 0
執行使之生效
#sysctl -p


7.Transparent Huge Page
已啟用“透明大頁面”,它可能會導致重大的效能問題。版本為“CentOS release 6.3 (Final)”且版本為“2.6.32-279.el6.x86_64”的 Kernel 已將 enabled 設定為“[always] never”,並將 d
efrag 設定為“[always] never”。請執行“echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag”以禁用此設定,然後將同一命令新增到一個 init 指令碼中,
如 /etc/rc.local,這樣當系統重啟時就會設定它。或者,升級到 RHEL 6.4 或更新版本,它們不存在此錯誤。將會影響到以下主機。
      [testuser@xxx-01 ~]# cat /sys/kernel/mm/redhat_transparent_hugepage/defrag
      [always] madvise never
      [testuser@xxx-01 ~]# echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag 
      [testuser@xxx-01 ~]# echo 'echo never > /sys/kernel/mm/redhat_transparent_hugepage/defrag' >> /etc/rc.local 
 

來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/30089851/viewspace-2091185/,如需轉載,請註明出處,否則將追究法律責任。

相關文章