RHEL/CentOS 在 6.3 版本以后引入了一套新的系統(tǒng)調優(yōu)工具 tuned/tuned-adm,其中 tuned 是服務端程序,用來監(jiān)控和收集系統(tǒng)各個組件的數(shù)據(jù),并依據(jù)數(shù)據(jù)提供的信息動態(tài)調整系統(tǒng)設置,達到動態(tài)優(yōu)化系統(tǒng)的目的;tuned-adm 是客戶端程序,用來和 tuned 打交道,用命令行的方式管理和配置 tuned,tuned-adm 提供了一些預先配置的優(yōu)化方案可供直接使用,比如:筆記本、虛擬機、存儲服務器等。
如果你正在使用筆記本(電池電源),想優(yōu)化系統(tǒng)、節(jié)約電源又不想知道太多這方面的細節(jié),就可以用 tuned/tuned-adm 這套工具并應用 laptop-battery-powersave 方案來調整和優(yōu)化系統(tǒng)。當然不同的系統(tǒng)和應用場景有不同的優(yōu)化方案,tuned-adm 預先配置的優(yōu)化策略不是總能滿足要求,這時候就需要定制,tuned-adm 允許用戶自己創(chuàng)建和定制新的調優(yōu)方案。
安裝和啟動 tuned:
# yum update
# yum install tuned
# service tuned start
# chkconfig tuned on
# service ktune start
# chkconfig ktune on
查看當前優(yōu)化方案:
# tuned-adm active
Current active profile: default
Service tuned: enabled, running
Service ktune: enabled, running
查看預先配置好的優(yōu)化方案:
# 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 方案優(yōu)化。如果報錯 “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
如果是企業(yè)存儲服務器的話,可以用 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 ]
上面預定的方案不是總能滿足要求,如果有自己的需求可以定制自己的方案。自己定制很容易,切換到優(yōu)化方案的配置目錄,拷貝一個例子,然后編輯里面的相關參數(shù)就可以了,使用 tuned-adm list 命令會看到剛創(chuàng)建的新方案 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