https://wiki.mikejung.biz/OS_Tuning
RHEL/CentOS 在 6.3 版本以后引入了一套新的系统调优工具 tuned/tuned-adm,其中 tuned<span style="background-color: inherit;">&nbsp;</span>是服务端程序,用来监控和收集系统各个组件的数据,并依据数据提供的信息动态调整系统设置,达到动态优化系统的目的;tuned-adm<span style="background-color: inherit;">&nbsp;</span>是客户端程序,用来和 tuned 打交道,用命令行的方式管理和配置 tuned,tuned-adm<span style="background-color: inherit;">&nbsp;</span>提供了一些预先配置的优化方案可供直接使用,比如:笔记本、虚拟机、存储服务器等。

如果你正在使用笔记本(电池电源),想优化系统、节约电源又不想知道太多这方面的细节,就可以用 tuned/tuned-adm 这套工具并应用laptop-battery-powersave 方案来调整和优化系统。

当然不同的系统和应用场景有不同的优化方案,tuned-adm<span style="background-color: inherit;">&nbsp;</span>

预先配置的优化策略不是总能满足要求,这时候就需要定制,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
查看预先配置好的优化方案:(不同版本的系统,内容不一样)

<span style="color: rgb(255, 0, 0); line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;"># tuned-adm list &nbsp;-----centos6</span>

 

Available profiles:

- default

- throughput-performance

- laptop-ac-powersave

- latency-performance

- laptop-battery-powersave

- desktop-powersave

- virtual-guest

- enterprise-storage

- server-powersave

- virtual-host

- spindown-disk
<span style="color: rgb(85, 85, 85); background-color: inherit;">Current active profile: default</span>
# tuned-adm list  -----centos7

 

Available profiles:

- balanced

- desktop

- latency-performance

- network-latency

- network-throughput

- powersave

- throughput-performance

- virtual-guest

- virtual-host

Current active profile: virtual-guest

 

 
tuned-adm has the ability to set the following profiles on CentOS 6 or CentOS 7:

<span style="line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;">&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;</span><span style="line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;">default</span><span style="line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;">&nbsp;-&nbsp;</span>

<span style="line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;">Default power saving profile, this is the most basic. It enables only the disk and cpu pligins. This is not the same as turning tuned-adm off.</span>

 

 
**Latency-performance(延迟性能)**


 
<div style="background-color: inherit;">
    &nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="background-color: inherit;">- This turns off power saving features, cpuspeed mode is turned to performance. I/O elevator is changed to </span><span style="background-color: inherit;">deadline</span><span style="background-color: inherit;">. cpu_dma_latency requirement value 0 is registered.</span>
</div>

<div style="background-color: inherit;">
    &nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="background-color: inherit;">典型延迟性能调试的服务器配置。它禁用 tuned 和 ktune 节能机制。cpuspeed 模式改为 performance。每个设备的 I/O 提升程序改为 deadline。对于服务的电源管理质量,将 cpu_dma_latency 设定为 0。</span>
</div>


此配置会禁用动态调优机制及transparent_hugepages。其通过cpuspeed对p-states进行性能治理,同时将I/O调度程序设置为deadline.network-latency。”

 

 


Throughput-performance(通量性能)
<div style="background-color: inherit;">
    &nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="background-color: inherit;"><span style="background-color: inherit;"><span style="background-color: inherit;">&ldquo;此服务器配置适用于典型的通量性能调优。其禁用tuned与ktune power saving机制,启用sysctl设置以优化磁盘与网络I/O的通量性能,同时切换至deadline调度程序。CPU调整器将被设置为performance。&rdquo;</span></span></span>
</div>

<div style="background-color: inherit;">
    &nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;&nbsp;- Recommended if the system is not using &quot;enterprise class&quot; storage. Same as &quot;latency-performance&quot; except:
</div>

kernel.sched_min_granularity_ns is set to 10 ms
kernel.sched_wakeup_granularity_ns is set to 15 ms
vm.dirty_ratio is set to 40% and transparent huge pages are enabled.

 

用于典型吞吐性能调整的服务器配置。如果系统没有企业级存储则建议使用这个侧写。它与 latency-performance 相同,只是:

          将 kernel.sched_min_granularity_ns(调度程序最小优先占用时间间隔)设定为 10 毫秒,

          将kernel.sched_wakeup_granularity_ns(调度程序唤醒间隔时间)设定为 15 毫秒。

          将 vm.dirty_ratio(虚拟机脏数据比例)设定为 40%,并启用透明超大页面。
&nbsp;
**Network-latency(网络延迟):**
包括latency-performance,禁用transparent_hugepages,禁用NUMA均衡并启用部分基于延迟的网络调优选项。

 
**Network-throughput(网络通量):** 包括throughput-performance并提升网络栈缓冲区大小。

 


 

**<font color="#333333" face="Microsoft Yahei" size="3" style="background-color: rgb(255, 255, 255);">&nbsp;&nbsp;<span style="background-color: inherit;">enterprise-storage</span>&nbsp;</font>**

 


 
<div style="background-color: inherit;">
    Recommended for enterprise class storage servers that have BBU raid controller cache protection and management of on-disk cache. Same as &quot;throughput-performance except:
</div>

file systems are re-mounted with barrier=0
 建议最企业级服务器配置中使用这个配置,其中包括电池备份控制程序缓存保护以及管理磁盘缓存。它与 throughput-performance 配置类似,只是文件系统要使用 barrier=0 重新挂载。 


 

**<font color="#333333" face="Microsoft Yahei" size="3" style="background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="background-color: inherit;">virtual-guest</span></font>**

 


 
<div style="background-color: inherit;">
    Same as &quot;enterprise storage&quot; but it sets readahead value to x 4 of what it normally is. Non boot / root FS are remounted with barrier=0
</div>



建议最企业级服务器配置中使用这个配置,其中包括电池备份控制程序缓存保护以及管理磁盘缓存。它与 throughput-performance 类似,只是:
<div style="background-color: inherit;">
    <span style="background-color: inherit;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 将 readahead 值设定为 4x,同时不使用 barrier=0 重新挂载的 root/boot 文件系统。&nbsp;</span>
</div>



 

**<font color="#333333" face="Microsoft Yahei" size="3" style="background-color: rgb(255, 255, 255);">&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;<span style="background-color: inherit;">virtual-host</span>&nbsp;</font>**

 


 
<div style="background-color: inherit;">
    Based on &quot;enterprise storage&quot;. This reduces swappiness of virtual memory and enables more aggressive writeback of dirty pages. Recommended for KVM hosts.
</div>

根据 enterprise-storage 配置,virtual-host 还可减少可置换的虚拟内存,并启用更多集合脏页写回。推荐在虚拟化主机中使用这个配置,包括 KVM 和红帽企业版 Linux 虚拟化主机。

 
########################

 
如果服务器是虚拟机母机的话,可以选用 virtual-host 方案优化。如果报错 &ldquo;kernel.sched_migration_cost&rdquo; is an unknown key 可以通过编辑 sysctl.ktune 这个文件解决。
# tuned-adm profile virtual-host
如果服务器是虚拟机,可以选用 virtual-guest 方案优化
<font color="#555555" face="Roboto Condensed, Arial, sans-serif" size="4" style="background-color: rgb(255, 255, 255);"># tuned-adm profile&nbsp;</font><font color="#555555" style="line-height: 1.5; font-family: Monaco, Consolas, Courier, &quot;Lucida Console&quot;, monospace; background-color: inherit;">&nbsp;</font><span style="color: rgb(85, 85, 85); line-height: 1.5; font-family: &quot;Roboto Condensed&quot;, Arial, sans-serif; font-size: 18px; background-color: rgb(255, 255, 255);">virtual-guest &nbsp; ---centos7虚拟机安装后默认是<span style="text-align: left; color: rgb(85, 85, 85); font-family: &quot;Roboto Condensed&quot;, Arial, sans-serif; font-size: 18px; font-style: normal; font-weight: normal; background-color: rgb(255, 255, 255);">virtual-guest</span></span>



 


如果是企业存储服务器的话,可以用 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/ —centos6



#cd /usr/lib/tuned/ —centos7 /etc/tuned

# 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



###################




 



Mongodb有优化的tuned




 


*Tuned-Percona-Mongodb: 安装

此配置文件的安装过程非常简单,只需要使用Git命令检查该库,而后运行sudo make enable即可。完整的输出结果如下:

 



 


可以看到percona-mongodb目前已经在系统上成为活跃tuned配置文件(输出结果的最后一行中可以看到)。

各tuned配置文件被安装至/etc/tuned/percona-mongodb, 如下可见:

Tuned-Percona-Mongodb: 卸载


,在github checkout目录中运行Sudo Make Uninstall: