1
2
3
4
5
6
7
作者:李晓辉

联系方式:

1. 微信:Lxh_Chat

2. 邮箱:939958092@qq.com
  1. Linux 性能调优系列(一) 建立科学的性能分析思路
  2. Linux 性能调优系列(二) 掌握基础性能监控命令
  3. Linux 性能调优系列(三) sysstat实现性能数据持久采集
  4. Linux 性能调优系列(四) 别只会用 sysstat,PCP 才是 Linux 性能监控的进阶玩法
  5. Linux 性能调优系列(五) 给你的服务器做一次全面体检
  6. Linux 性能调优系列(六) 想调内核参数?先搞懂 /proc、sysctl 和 sysfs
  7. Linux 性能调优系列(七) 还在手动改 sysctl?TuneD 智能性能调优实战来了
  8. Linux 性能调优系列(八) 进程太能吃资源怎么办?用 ulimit 和 systemd 给它加个"上限"
  9. Linux 性能调优系列(九) cgroup v2实战:防止一个烂进程干崩整台服务器
  10. Linux 性能调优系列(十) CPU 100% 到底是谁在忙?用 perf 把"元凶"揪出来
  11. Linux 性能调优系列(十一) 程序为什么卡住了?strace 和 ltrace 带你找到答案
  12. Linux 性能调优系列(十二) 服务器又卡了?SystemTap 带你杀到内核看看为啥
  13. Linux 性能调优系列(十三) 从 SystemTap 到 eBPF,Linux 性能追踪进入新时代
  14. Linux 性能调优系列(十四) CPU 这么忙,到底是谁决定“让谁先跑”?一文搞懂 Linux 调度器
  15. Linux 性能调优系列(十五) CPU 到底该先给谁?搞懂 Linux 实时调度
  16. Linux 性能调优系列(十六) Linux CPU 隔离实战,为什么实时线程绑核后延迟还会抖?
  17. Linux 性能调优系列(十七) CPU 占用不高却跑的慢?深挖 CPU 缓存性能瓶颈
  18. Linux 性能调优系列(十八) 程序申请了1GB内存,为什么系统却说它没用?
  19. Linux 性能调优系列(十九) 服务器硬盘慢得像蜗牛?先别急着换硬盘,这四招先把瓶颈找出来
  20. Linux 性能调优系列(二十) 磁盘 I/O 调度器怎么选?一文搞懂 mq-deadline、kyber、bfq 和 none
  21. Linux 性能调优系列(二十一) 磁盘为什么慢?从文件系统到 I/O 调优,一次讲透
  22. Linux 性能调优系列(二十二) Linux 网络调优别乱改 sysctl!先找瓶颈再调 TCP 缓冲区
  23. Linux 性能调优系列(二十三) MTU 从 1500 到 9000,巨帧真的能提升性能吗?
  24. Linux 性能调优系列(二十四) 从 CPU 省电到网卡卸载,聊聊 Linux 网络调优
  25. Linux 性能调优系列(二十五) 聊聊VirtIO、TuneD、virtio-mem 调优

承接上文:上一篇我们学习了手动修改Linux内核可调项,通过sysctl、modprobe调整系统参数。但是手动修改有不少痛点:需要自己记忆大量参数,不同业务场景要维护一堆conf文件,容易写错。Linux提供了 TuneD 调优守护进程,帮我们解决这个问题。

TuneD内置大量成熟调优模板,针对不同工作负载一键应用内核、磁盘、网络参数,不用到处复制网上零散的sysctl配置。

什么是 TuneD

TuneD 是Linux的调优工具,作为后台守护进程运行。它内置多套预定义调优配置集(profile),可以根据业务负载需求自动优化系统性能与功耗。

TuneD 分为两种工作模式:静态调优、动态调优。

静态调优(默认模式)

当 tuned 服务启动,或者切换配置集的时候,立刻把配置文件里面的参数全部应用到系统。参数一旦设置完成就固定不变,不会随系统负载变化自动改动。

优点:调优结果稳定、可预测,服务器生产环境默认使用静态模式。

动态调优(默认关闭)

开启之后,tuned守护进程会持续监控系统负载(CPU负载、磁盘IO、网络流量),运行时动态调整系统参数,适配实时业务压力。生产环境默认关闭动态调优,动态调优并不是随机修改参数,而是 TuneD 根据 CPU、磁盘、网络等运行状态进行动态调整。由于生产环境通常更关注性能表现的可预测性,因此是否开启动态调优需要结合具体业务和 Profile 进行评估。开启动态调优方法是修改主配置文件 /etc/tuned/tuned-main.conf,将0修改为1开启动态调优

1
2
3
dynamic_tuning = 1
# 动态检测更新间隔,单位秒
update_interval = 10

修改完成重启tuned服务生效:

1
systemctl restart tuned

安装与启动 TuneD

RHEL分支的系统一般预安装tuned,如果系统没有,则手动安装:

1
2
3
4
5
6
7
8
9
10
[root@localhost ~]# dnf install tuned -y
Installed:
hdparm-9.65-6.el10.x86_64 libbabeltrace-1.5.11-9.el10.x86_64
polkit-125-4.el10_2.1.x86_64 polkit-libs-125-4.el10_2.1.x86_64
polkit-pkla-compat-0.1-30.el10.x86_64 python3-inotify-0.9.6-36.el10.noarch
python3-linux-procfs-0.7.4-1.el10.noarch python3-perf-6.12.0-211.60.1.el10_2.x86_64
python3-pyudev-0.24.1-10.el10.noarch tuned-2.27.0-2.el10_2.noarch
virt-what-1.27-3.el10.x86_64

Complete!

启用并立刻启动服务,设置开机自启:

1
[root@localhost ~]# systemctl enable --now tuned

TuneD 内置调优配置集 profile

官方预置配置集存放路径:/usr/lib/tuned/profiles/

⚠️重要提醒:千万不要直接修改这个目录下面的文件! 软件包更新的时候会直接覆盖改动。自定义配置要放到 /etc/tuned/profiles/。

自带profile说明:

配置集名称适用业务场景
balanced通用均衡模式,无特殊业务要求服务器默认选择
balanced-battery兼顾性能与省电,多用于笔记本
throughput-performance通用高吞吐调优,绝大多数服务器场景通用
latency-performance追求确定性低延迟,代价会增加功耗
network-latency网络优先低延迟,对网络响应时间敏感业务
network-throughput网络追求大吞吐量,适合40G及以上高速网卡老CPU
virtual-guestKVM虚拟机内部客户机使用
virtual-hostKVM虚拟化宿主机,用来跑大量虚拟机
hpc-compute高性能计算HPC场景
powersave最大化省电,服务器一般不使用
desktop桌面工作站
awsAWS EC2云实例专用优化
accelerator-performance加速器硬件性能优化
intel-sstIntel Speed Select Technology频率配置
optimize-serial-console针对串口控制台做优化

tuned-adm:命令行管理调优配置集

tuned-adm 是操作tuned最主要的命令行工具。

  1. 查看系统全部可用配置集
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
[root@localhost ~]# tuned-adm list
Available profiles:
- accelerator-performance - Throughput performance based tuning with disabled higher latency STOP states
- aws - Optimize for aws ec2 instances
- balanced - General non-specialized tuned profile
- balanced-battery - Balanced profile biased towards power savings changes for battery
- desktop - Optimize for the desktop use-case
- hpc-compute - Optimize for HPC compute workloads
- intel-sst - Configure for Intel Speed Select Base Frequency
- latency-performance - Optimize for deterministic performance at the cost of increased power consumption
- network-latency - Optimize for deterministic performance at the cost of increased power consumption, focused on low latency network performance
- network-throughput - Optimize for streaming network throughput, generally only necessary on older CPUs or 40G+ networks
- optimize-serial-console - Optimize for serial console use.
- powersave - Optimize for low power consumption
- throughput-performance - Broadly applicable tuning that provides excellent performance across a variety of common server workloads
- virtual-guest - Optimize for running inside a virtual guest
- virtual-host - Optimize for running KVM guests
Current active profile: virtual-guest
  1. 查看当前正在生效的配置集
1
2
3
[root@localhost ~]# tuned-adm active
Current active profile: virtual-guest

  1. 查看某个配置集详细说明

不加参数查看当前活跃profile信息

1
2
3
4
5
6
7
8
[root@localhost ~]# tuned-adm profile_info
Profile name:
virtual-guest

Profile summary:
Optimize for running inside a virtual guest

Profile description:

指定查看virtual-guest配置集

1
2
3
4
5
6
7
8
[root@localhost ~]# tuned-adm profile_info virtual-guest
Profile name:
virtual-guest

Profile summary:
Optimize for running inside a virtual guest

Profile description:
  1. 切换调优配置集(永久生效,重启依旧保持)
1
[root@localhost ~]# tuned-adm profile virtual-guest
  1. tuned自动推荐适合本机的配置集
    tuned会读取硬件信息,判断是否虚拟机、硬件平台,给出推荐profile
1
2
[root@localhost ~]# tuned-adm recommend
virtual-guest

虚拟机环境一般输出:virtual-guest

  1. 校验当前系统参数是否和活跃profile匹配>

    修改完profile后建议执行,校验有没有参数应用失败

1
2
3
4
5
6
7
8
[root@localhost ~]# tuned-adm verify
Verification failed, current system settings differ from the preset profile.
You can mostly fix this by restarting the TuneD daemon, e.g.:
systemctl restart tuned
or
service tuned restart
Sometimes (if some plugins like bootloader are used) a reboot may be required.
See TuneD log file ('/var/log/tuned/tuned.log') for details.

如果校验失败,查看日志文件 /var/log/tuned/tuned.log 排查报错。

1
2
3
4
5
6
7
8
9
10
11
[root@localhost ~]# tail /var/log/tuned/tuned.log
2026-09-29 22:43:46,881 ERROR tuned.plugins.base: verify: failed: device cpu3: 'boost' = 'None', expected '1'
2026-09-29 22:43:46,881 ERROR tuned.plugins.base: verify: failed: device cpu1: 'boost' = 'None', expected '1'
2026-09-29 22:43:46,881 ERROR tuned.plugins.base: verify: failed: device cpu2: 'boost' = 'None', expected '1'
2026-09-29 22:43:46,882 ERROR tuned.plugins.base: verify: failed: 'vm.swappiness' = '10', expected '30'
2026-09-29 22:44:34,014 INFO tuned.daemon.daemon: verifying profile(s): virtual-guest
2026-09-29 22:44:34,015 ERROR tuned.plugins.base: verify: failed: device cpu0: 'boost' = 'None', expected '1'
2026-09-29 22:44:34,015 ERROR tuned.plugins.base: verify: failed: device cpu3: 'boost' = 'None', expected '1'
2026-09-29 22:44:34,015 ERROR tuned.plugins.base: verify: failed: device cpu1: 'boost' = 'None', expected '1'
2026-09-29 22:44:34,015 ERROR tuned.plugins.base: verify: failed: device cpu2: 'boost' = 'None', expected '1'
2026-09-29 22:44:34,015 ERROR tuned.plugins.base: verify: failed: 'vm.swappiness' = '10', expected '30'
  1. 关闭全部tuned调优,恢复系统默认参数
1
tuned-adm off

通过Cockpit Web控制台图形化管理TuneD

除了命令行,也可以通过Cockpit网页控制台可视化切换性能配置集,不需要敲命令。

  1. 安装cockpit组件
1
[root@localhost ~]# dnf install cockpit -y
  1. 启动socket服务,设置开机自启
1
[root@localhost ~]# systemctl enable --now cockpit.socket
  1. 防火墙放行cockpit服务
1
2
3
4
5
[root@localhost ~]# firewall-cmd --add-service=cockpit --permanent
Warning: ALREADY_ENABLED: cockpit
success
[root@localhost ~]# firewall-cmd --reload
success
  1. 浏览器访问:https://服务器IP:9090

如果root用户无法登录,那就是在禁止登陆的用户列表里,直接从下面的文件里删除root几个字就行

1
2
3
[root@localhost ~]# cat /etc/cockpit/disallowed-users
# List of users which are not allowed to login to Cockpit
root

重启服务

1
[root@localhost ~]# systemctl restart cockpit.socket

使用系统账号密码登录,需要点击开启管理权限(administrative access)。

cockpit-login

在左侧菜单 Overview 页面,找到 Performance profile,点击就可以切换调优配置集。

tuned-profile-1

点击后,直接就能看见所有的配置文件,还有推荐的标识,选好了点变更配置就行

tuned-profile-2

创建自定义 TuneD 调优配置集

官方内置profile不一定完全贴合业务,TuneD支持创建自定义profile。自定义配置存放目录:/etc/tuned/profiles/,当和系统内置profile重名,/etc/tuned/profiles/优先级更高。

核心特性:include继承机制,不需要从零写全套调优参数。可以继承官方profile,只覆盖需要改动的少数参数。

可以看到desktop这个配置文件,就include了balanced

1
2
3
4
5
6
7
8
9
10
11
12
13
[root@localhost desktop]# pwd
/usr/lib/tuned/profiles/desktop
[root@localhost desktop]# cat tuned.conf
#
# tuned configuration
#

[main]
summary=Optimize for the desktop use-case
include=balanced

[sysctl]
kernel.sched_autogroup_enabled=1

TuneD配置文件 tuned.conf 常用插件

tuned.conf使用不同插件来修改系统各个子系统:

插件段作用
[main]配置集元信息,支持include继承其他profile
[sysctl]设置sysctl内核可调项
[vm]内存虚拟内存调优参数
[cpu]CPU调频、电源策略
[disk]磁盘调度、预读等磁盘参数
[net]网络接口相关调优
[modules]设置内核模块参数
[script]加载/卸载profile时执行自定义脚本

实操案例:继承官方profile,制作数据库业务自定义配置集

需求:基于throughput-performance高吞吐模板,只修改vm.swappiness=5适配数据库业务。

  1. 创建自定义profile目录
1
[root@localhost ~]# mkdir -p /etc/tuned/profiles/my-db-profile
  1. 创建 tuned.conf 配置文件
1
2
3
4
5
6
7
8
9
cat > /etc/tuned/profiles/my-db-profile/tuned.conf <<EOF
[main]
# 继承官方 throughput-performance 全部设置
include=throughput-performance
summary=Custom profile for database workload

[sysctl]
vm.swappiness = 5
EOF
  1. 激活我们自定义的配置集
1
[root@localhost ~]# tuned-adm profile my-db-profile
  1. 校验是否生效
1
2
[root@localhost ~]# tuned-adm active
Current active profile: my-db-profile

如果出现异常,查看tuned运行日志排查错误:/var/log/tuned/tuned.log

实战案例:完全不继承,从零编写简单自定义配置集

一般不推荐,大部分场景优先使用include继承官方配置。

1
mkdir -p /etc/tuned/profiles/my-simple-profile

编辑 /etc/tuned/profiles/my-simple-profile/tuned.conf

1
2
3
4
5
6
7
8
9
10
11
cat > /etc/tuned/profiles/my-simple-profile/tuned.conf <<-EOF
[main]
summary=Simple custom profile demo

[cpu]
governor=conservative
energy_perf_bias=normal

[sysctl]
vm.swappiness=10
EOF

激活与校验:

1
2
3
4
5
6
[root@localhost ~]# tuned-adm profile my-simple-profile
[root@localhost ~]# tuned-adm active
Current active profile: my-simple-profile
[root@localhost ~]# tuned-adm verify
Verification succeeded, current system settings match the preset profile.
See TuneD log file ('/var/log/tuned/tuned.log') for details.

devices属性:对部分设备单独调优

在磁盘、net这类硬件插件中,可以使用devices指定匹配设备,支持通配符*,使用!排除设备。

示例:给nvme0n1磁盘设置预读4096,排除sdc这块盘

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
cat > /etc/tuned/profiles/my-simple-profile/tuned.conf <<-EOF
[main]
summary=Simple custom profile demo

[cpu]
governor=conservative
energy_perf_bias=normal

[sysctl]
vm.swappiness=10

[my_disk_cfg]
type=disk
devices=nvme0n1,!sdc
readahead=4096
EOF

验证看看

1
2
[root@localhost ~]# cat /sys/block/nvme0n1/queue/read_ahead_kb
4096

生产环境最佳实践小结

  1. 优先使用官方自带profile,不要一上来就手写全套参数;
  2. 需要修改少量参数,一定用include继承官方配置,只覆盖改动项;
  3. 自定义profile全部写在 /etc/tuned/profiles/,绝不修改 /usr/lib/tuned/profiles;
  4. 切换profile之后,务必执行 tuned-adm verify校验;
  5. 排错看日志文件 /var/log/tuned/tuned.log;
  6. 生产服务器默认使用静态调优,不建议开启dynamic_tuning动态调优。

参考手册

1
2
3
4
man tuned
man tuned-conf
man tuned-adm
man tuned-profiles