如何使用tuned-adm 优化Linux 系统性能|
作为系统管理员,您应该能够通过调整各种设置来优化 Linux 系统的性能,以适应您的用例工作负载。本指南旨在帮助您通过tuned优化 Linux 服务器性能。
tuned守护进程可用于动态或静态地应用系统调整调整。有一些预定义的调整配置文件可以反映特定的工作负载要求。
您可以调整的可用配置文件有:
那么我们来看看系统调优的两种模式。
静态调整
在此调整方法中,tuned 守护进程在服务启动或选择新的调整配置文件时应用系统设置。它在配置文件中配置预定义的内核参数,在运行时进行调整。内核参数是根据整体性能预期而设置的,并且不会随着活动级别的变化而调整。
动态调整
通过动态调整,调整后的守护进程可以监视系统活动并根据运行时行为变化调整设置。动态调优是从所选调优配置文件中声明的初始设置开始,不断调整调优以适应当前的工作负载。
安装调谐
在RHEL/CentOS 8/7 Linux系统中,默认安装并启用tuned包。如果您想在 CentOS/RHEL 计算机上手动安装并启用该软件包,请运行以下命令:
sudo yum install tuned
sudo systemctl enable --now tuned
Ubuntu/Debian:
sudo apt update
sudo apt install tuned tuned-utils tuned-utils-systemtap
启动后确认服务状态。
$ systemctl status tuned
● tuned.service - Dynamic System Tuning Daemon
Loaded: loaded (/usr/lib/systemd/system/tuned.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2020-02-04 04:10:52 UTC; 6 days ago
Docs: man:tuned(8)
man:tuned.conf(5)
man:tuned-adm(8)
Main PID: 936 (tuned)
CGroup: /system.slice/tuned.service
└─936 /usr/bin/python2 -Es /usr/sbin/tuned -l -P
.....
选择调谐配置文件
Tuned 配置文件分为以下几类:
- 提高性能的配置文件
- 省电配置文件
性能提升配置文件包括侧重于以下方面的配置文件:
- 存储和网络低延迟
- 存储和网络的高吞吐量
- 虚拟化主机性能
- 虚拟机性能
我们将使用 tuned-adm 命令来更改 tuned 守护进程的设置。
检查当前活动的调整配置文件:
$ tuned-adm active
Current active profile: virtual-guest
tuned-adm list命令用于列出所有可用的调整配置文件:
Available profiles:
- balanced - General non-specialized tuned profile
- desktop - Optimize for the desktop use-case
- 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
- 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
在 Ubuntu 上,有更多配置文件可用:
$ tuned-adm list
Available profiles:
- atomic-guest - Optimize virtual guests based on the Atomic variant
- atomic-host - Optimize bare metal systems running the Atomic variant
- balanced - General non-specialized tuned profile
- cpu-partitioning - Optimize for CPU partitioning
- default - Legacy default tuned profile
- desktop - Optimize for the desktop use-case
- desktop-powersave - Optmize for the desktop use-case with power saving
- enterprise-storage - Legacy profile for RHEL6, for RHEL7, please use throughput-performance profile
- laptop-ac-powersave - Optimize for laptop with power savings
- laptop-battery-powersave - Optimize laptop profile with more aggressive power saving
- 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
- oracle - Optimize for Oracle RDBMS
- powersave - Optimize for low power consumption
- realtime - Optimize for realtime workloads
- realtime-virtual-guest - Optimize for realtime workloads running within a KVM guest
- realtime-virtual-host - Optimize for KVM guests running realtime workloads
- sap-hana - Optimize for SAP HANA
- sap-hana-vmware - Optimize for SAP HANA running inside a VMware guest
- sap-netweaver - Optimize for SAP NetWeaver
- server-powersave - Optimize for server power savings
- spindown-disk - Optimize for power saving by spinning-down rotational disks
- 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
tuned-adm profile
sudo tuned-adm profile throughput-performance
确认当前的个人资料。
$ sudo tuned-adm active
Current active profile: throughput-performance
检查系统推荐的调整配置文件
tuned-adm 命令还可以推荐系统的调整配置文件。这是基于各种系统特征,包括系统是否是虚拟机以及系统安装期间选择的其他预定义类别。
$ tuned-adm recommend
virtual-guest
然后,您可以将您的配置文件设置为推荐值。
sudo tuned-adm profile virtual-guest
要查看配置文件详细信息,请运行:
$ tuned-adm profile_info virtual-guest
Profile name:
virtual-guest
Profile summary:
Optimize for running inside a virtual guest
Profile description:
关闭配置文件
要恢复当前配置文件所做的设置更改,请切换到另一个配置文件或停用tuned 守护程序。
使用tuned-adm off命令关闭tuned调整活动:
$ tuned-adm off
使用命令确认:
$ tuned-adm active
您还可以使用 Cockpit Web 控制台管理调优配置文件。
更多指南:
在 KVM/VirtualBox/VMWare/Parallels 上使用 Vagrant 运行 CentOS 8 VM
使用持久存储保留 Systemd 日志记录
在 Windows 10 上启用 Hyper-V 并安装 Vagrant