随着开放式平台的推广应用,以Linux为代表的开放式操作系统平台越来越成为系统架构选择的优选。作为一款成熟的操作系统,系统监控调优是Linux平台必不可少的工具组件。历经多个版本的Linux,已经发展出很成熟的操作系统优化配置策略。
本篇主要介绍红帽Linux环境中的Automatic System Tuning组件包。针对Linux系统不同的实际场景,采用不同的应用配置文件Profile策略。
1、环境介绍
笔者操作系统环境为Red Hate 6.4。目前的Linux操作系统,已经可以支撑小到个人版本桌面服务器,大到大型系统集群环境的多种类型系统。例如:企业存储服务器、高网络吞吐量服务器等等。
[root@SICS-MIGPC-DB ~]# cat /etc/RedHat-release
Red Hat Enterprise Linux Server release 6.4 (Santiago)
2、Tuned安装
首先可以利用yum安装Automatic System Tuning包的程序。Yum可以自动帮助我们解决诸如包依赖、版本选择等诸多问题,是进行安装配置的有限选项。
对Linux的不同发行版本来说,yum是有不同选项的。Red Hat Linux要求的比较严格,只有注册了官方服务支持之后才能得到从网站下载最新rpm包的服务。对CentOS等开源版本来说,yum工具限制比较少。笔者通常的做法,是建立本地的yum资源库,将Linux安装盘中的rpm包放在资源库中,根据需要进行安装。
[root@SICS-MIGPC-DB ~]# yum install tuned
Loaded plugins: product-id, refresh-packagekit, security, subscription-manager
This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register.
localyum | 2.9 kB 00:00 ...
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package tuned.noarch 0:0.2.19-13.el6 will be installed
--> Finished Dependency Resolution
Dependencies Resolved
================================================================================
Package Arch Version Repository Size
================================================================================
Installing:
tuned noarch 0.2.19-13.el6 localyum 94 k
Transaction Summary
================================================================================
Install 1 Package(s)
Total download size: 94 k
Installed size: 222 k
Is this ok [y/N]: yes
Downloading Packages:
Running rpm_check_debug
Running Transaction Test
Transaction Test Succeeded
Running Transaction
Installing : tuned-0.2.19-13.el6.noarch 1/1
Verifying : tuned-0.2.19-13.el6.noarch 1/1
Installed:
tuned.noarch 0:0.2.19-13.el6
Complete!
安装之后,tuned以系统服务的形式被配置入系统。
[root@SICS-MIGPC-DB ~]# chkconfig --list | grep tuned
tuned 0:off 1:off 2:off 3:off 4:off 5:off 6:off
[root@SICS-MIGPC-DB ~]# chkconfig tuned on
[root@SICS-MIGPC-DB ~]# chkconfig --list | grep tuned
tuned 0:off 1:off 2:on 3:on 4:on 5:on 6:off
3、tuned配置使用
通过service命令,可以查看tuned服务的状态和启动关闭。
[root@SICS-MIGPC-DB ~]# service tuned status
tuned is stopped
[root@SICS-MIGPC-DB ~]# service tuned start
Starting tuned: [ OK ]
在/etc/tune-profiles目录中,我们可以找到各种预设的Profile文件。
[root@SICS-MIGPC-DB tune-profiles]# cd /etc/tune-profiles/
[root@SICS-MIGPC-DB tune-profiles]# ls -l
total 64
-rw-r--r-- 1 root root 7 Jul 24 2013 active-profile
drwxr-xr-x 2 root root 4096 Apr 3 13:11 default
drwxr-xr-x 2 root root 4096 Apr 3 13:11 desktop-powersave
drwxr-xr-x 2 root root 4096 Apr 3 13:11 enterprise-storage
-rw-r--r-- 1 root root 9779 Jul 24 2013 functions
drwxr-xr-x 2 root root 4096 Apr 3 13:11 laptop-ac-powersave
drwxr-xr-x 2 root root 4096 Apr 3 13:11 laptop-battery-powersave
drwxr-xr-x 2 root root 4096 Apr 3 13:11 latency-performance
drwxr-xr-x 2 root root 4096 Apr 3 13:11 sap
drwxr-xr-x 2 root root 4096 Apr 3 13:11 server-powersave
drwxr-xr-x 2 root root 4096 Apr 3 13:11 spindown-disk
drwxr-xr-x 2 root root 4096 Apr 3 13:11 throughput-performance
drwxr-xr-x 2 root root 4096 Apr 3 13:11 virtual-guest
drwxr-xr-x 2 root root 4096 Apr 3 13:11 virtual-host
其中包括诸如节能笔记本、SAP系统、虚拟主机等内容,都是Linux提供的预定义模板。
下面可以依据现有的配置模板,修改成实际需要的版本。笔者准备配置出不使用Linux Huge Page特性的配置文件Profile。
[root@SICS-MIGPC-DB tune-profiles]# ls -l | grep enter
drwxr-xr-x 2 root root 4096 Apr 3 13:11 enterprise-storage
drwxr-xr-x 2 root root 4096 Apr 3 13:37 enterprise-storage-no-thp
进入目录:
[root@SICS-MIGPC-DB tune-profiles]# cd enterprise-storage-no-thp/
[root@SICS-MIGPC-DB enterprise-storage-no-thp]# ls -l
total 16
-rwxr-xr-x 1 root root 314 Apr 3 13:37 ktune.sh
-rw-r--r-- 1 root root 1239 Apr 3 13:37 ktune.sysconfig
-rw-r--r-- 1 root root 1562 Apr 3 13:37 sysctl.ktune
-rw-r--r-- 1 root root 191 Apr 3 13:37 tuned.conf
修改配置内容:
[root@SICS-MIGPC-DB enterprise-storage-no-thp]# sed -ie 's,set_transparent_hugepages always,set_transparent_hugepages never', /etc/tune-profiles/enterprise-storage-no-thp/ktune.sh
[root@SICS-MIGPC-DB enterprise-storage-no-thp]# grep set_transparent_hugepages ktune.sh
set_transparent_hugepages never
激活设置好的Profile,应用设定。
[root@SICS-MIGPC-DB enterprise-storage-no-thp]# tuned-adm profile enterprise-storage-no-thp
Stopping tuned: [ OK ]
Switching to profile 'enterprise-storage-no-thp'
Applying deadline elevator: dm-0 dm-1 dm-2 sda [ 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 ]
[root@SICS-MIGPC-DB enterprise-storage-no-thp]#
判断不使用Huge Page参数设置。
[root@SICS-MIGPC-DB enterprise-storage-no-thp]# cat /sys/kernel/mm/redhat_transparent_hugepage/enabled
always [never]
如果需要恢复默认的设置,只需要将tuned服务关闭即可。
[root@SICS-MIGPC-DB etc]# service --status-all | grep tun
Current ktune sysctl settings:
tuned (pid 32429) is running...
从ps –ef命令中,可以看到使用的后台进程和参数情况。
[root@SICS-MIGPC-DB ~]# ps -ef | grep tun
root 322 32642 0 14:05 pts/0 00:00:00 grep tun
root 32429 1 0 13:46 ? 00:00:00 /usr/bin/python /usr/sbin/tuned -d -c /etc/tuned.conf
从tuned执行使用的参数文件/etc/tuned.conf上,可以看出该工具带有监控功能。
[root@SICS-MIGPC-DB etc]# cat tuned.conf
# disable tuned
[main]
[DiskMonitor]
enabled=False
[DiskTuning]
enabled=False
[NetMonitor]
enabled=False
[NetTuning]
enabled=False
[CPUMonitor]
enabled=False
[CPUTuning]
enabled=False
tuned-adm工具用户配置和启用Profile文件和信息。
[root@SICS-MIGPC-DB ~]# tuned-adm help
Usage: tuned-adm <command>
commands:
help show this help message and exit
list list all available and active profiles
active show current active profile
off switch off all tuning
profile <profile-name> switch to given profile
[root@SICS-MIGPC-DB ~]# tuned-adm list
Available profiles:
- laptop-battery-powersave
- virtual-guest
- enterprise-storage
- desktop-powersave
- default
- throughput-performance
- spindown-disk
- sap
- enterprise-storage-no-thp
- laptop-ac-powersave
- virtual-host
- server-powersave
- latency-performance
Current active profile: enterprise-storage-no-thp
4、结论