RHEL/CentOS 在 6.3 版本以後引入了一套新的系統調優工具 tuned/tuned-adm,其中 tuned 是服務端程序,用來監控和收集系統各個組件的數據,並依據數據提供的信息動態調整系統設置,達到動態優化系統的目的;tuned-adm 是客戶端程序,用來和 tuned 打交道,用命令行的方式管理和配置 tuned,tuned-adm 提供了一些預先配置的優化方案可供直接使用,比如:筆記本、虛擬機、存儲服務器等。
如果你正在使用筆記本(電池電源),想優化系統、節約電源又不想知道太多這方面的細節,就可以用 tuned/tuned-adm 這套工具並應用 laptop-battery-powersave 方案來調整和優化系統。當然不同的系統和應用場景有不同的優化方案,tuned-adm 預先配置的優化策略不是總能滿足要求,這時候就需要定制,tuned-adm 允許用戶自己創建和定制新的調優方案。
安裝和啟動 tuned:
代碼如下:
# yum update
# yum install tuned
# service tuned start
# chkconfig tuned on
# service ktune start
# chkconfig ktune on
查看當前優化方案:
代碼如下:
# tuned-adm active
Current active profile: default
Service tuned: enabled, running
Service ktune: enabled, running
查看預先配置好的優化方案:
代碼如下:
# tuned-adm list
Available profiles:
- laptop-battery-powersave
- virtual-guest
- desktop-powersave
- sap
- server-powersave
- virtual-host
- throughput-performance
- enterprise-storage
- laptop-ac-powersave
- latency-performance
- spindown-disk
- default
Current active profile: default
如果服務器是虛擬機母機的話,可以選用 virtual-host 方案優化。如果報錯 “kernel.sched_migration_cost” is an unknown key 可以通過編輯 sysctl.ktune 這個文件解決。
代碼如下:
# tuned-adm profile virtual-host
Reverting to saved sysctl settings: [ OK ]
Calling '/etc/ktune.d/tunedadm.sh stop': [ OK ]
Reverting to cfq elevator: sda sdb sdc sdd sde sdf sdg [ OK ]
Stopping tuned: [ OK ]
Switching to profile 'virtual-host'
Applying deadline elevator: sda sdb sdc sdd sde sdf sdg [ OK ]
Applying ktune sysctl settings:
/etc/ktune.d/tunedadm.conf: [FAILED]
error: "kernel.sched_migration_cost" is an unknown key
Calling '/etc/ktune.d/tunedadm.sh start': [ OK ]
Applying sysctl settings from /etc/sysctl.conf
Starting tuned: [ OK ]
# vi /etc/tune-profiles/virtual-host/sysctl.ktune
...
#kernel.sched_migration_cost = 5000000
...
# tuned-adm profile virtual-host
如果是企業存儲服務器的話,可以用 enterprise-storage 方案:
代碼如下:
# tuned-adm profile enterprise-storage
Stopping tuned: [ OK ]
Switching to profile 'enterprise-storage'
Applying deadline elevator: dm-0 sda sdb sdc sdd [ OK ]
Applying ktune sysctl settings:
/etc/ktune.d/tunedadm.conf: [ OK ]
Calling '/etc/ktune.d/tunedadm.sh start': [ OK ]
Applying sysctl settings from /etc/sysctl.conf
Starting tuned: [ OK ]
上面預定的方案不是總能滿足要求,如果有自己的需求可以定制自己的方案。自己定制很容易,切換到優化方案的配置目錄,拷貝一個例子,然後編輯裡面的相關參數就可以了,使用 tuned-adm list 命令會看到剛創建的新方案 my-virtual-host:
代碼如下:
# cd /etc/tune-profiles/
# cp -r virtual-host my-virtual-host
# vi my-virtual-host/*
# tuned-adm list
Available profiles:
- laptop-battery-powersave
- virtual-guest
- desktop-powersave
- sap
- server-powersave
- virtual-host
- throughput-performance
- enterprise-storage
- laptop-ac-powersave
- latency-performance
- spindown-disk
- default
- my-virtual-host
Current active profile: virtual-host