Red Hat/Centos 性能调优 - tuned 服务

简介:

        从 RHEL/Centos 6.3 之后,引入了一套新的调优工具 tuned ,带来了大量的调优配置,可以针对不同的业务服务调整不同的优化策略。也旨在于简化调优的实施,充分利用系统资源与能效。

        另外,RHEL 6 和 RHEL 7 的 tuned 设置还是有一点区别的。


安装部署:

  1. 安装 tuned 服务

      # yum -y install tuned


  2. 查看当前系统中有的 tuned profile

      # tuned-adm list

  Available profiles:
- balanced                    - General non-specialized tuned profile
- desktop                     - Optmize 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.  This is the default profile for RHEL7.
- virtual-guest               - Optimize for running inside a virtual guest.
- virtual-host                - Optimize for running KVM guests
Current active profile: powersave


  3. 查看默认 profile 目录

      # ls -lt /usr/lib/tuned/

total 20
drwxr-xr-x. 2 root root    23 May  6 01:09 throughput-performance
drwxr-xr-x. 2 root root    23 Mar 24 17:52 virtual-host
drwxr-xr-x. 2 root root    23 Mar 24 17:52 virtual-guest
drwxr-xr-x. 2 root root    39 Mar 24 17:52 powersave
drwxr-xr-x. 2 root root    23 Mar 24 17:52 network-throughput
drwxr-xr-x. 2 root root    23 Mar 24 17:52 network-latency
drwxr-xr-x. 2 root root    23 Mar 24 17:52 latency-performance
drwxr-xr-x. 2 root root    23 Mar 24 17:52 desktop
drwxr-xr-x. 2 root root    23 Mar 24 17:52 balanced
-rw-r--r--. 1 root root 12532 Jun 17  2016 functions
-rw-r--r--. 1 root root  1288 Jun 17  2016 recommend.conf


  4. web profile 配置要求

  •     磁盘的调度算法为 deadline
  •     将打开的最大文件数设置成  65535
  •     启用该tuned profile 后,广播消息 “Tuned Profile change to webserver !”,通知各个终端已经更改了 tuned profile。


  5. 配置新的名为 webserver 的 tuned Profile

  • 复制一个模板 profile 到 /etc/tuned/ 目录下
# cp -R /usr/lib/tuned/balanced /etc/tuned/webserver
  • 查看新建的 Profile 结构数

# tree /etc/tuned/webserver

/etc/tuned/webserver/
└── tuned.conf

0 directories, 1 file


提示

    在 RHEL 6 中,还有 ktune 服务及文件,RHEL 7 中已经全部集成到了 tuned.conf 中了,更多参数和详细信息请移步

    RHEL 6 tuned/ktune 调优参考

    RHEL 7 tuned 调优参考


  • 修改 tuned.conf 文件

 

    #  cd /etc/tuned/webserver/

    #  vi tuned.conf
...
[main]
summary=This is a web server tuned profile        # 此处是改 profile 文件的描述

...

[disk]

# device=sda                 # 如果不写,则是该设备连接的所有磁盘

elevator=deadline          # 将磁盘 IO 的调度算法更改为 deadline

...

[my_sysctl]                 # 自定义的 sysctl 字段
type=sysctl                 # 类型为 sysctl
fs.file-max=655350     # 修改最大打开的文件数

...

[my_script]

type=script

script=script.sh         # 不写全路劲的话,默认主目录为 webserver,即默认会在 /etc/tuned/webserver 目录下去找该脚本文件

...


  • 在 webserver tuned profile 目录中新建一个 script.sh 脚本 [名字可以随便起]

  # vi script.sh

#!/bin/sh
. /usr/lib/tuned/functions

start() {
  wall "Tuned Profile change to webserver !"
  return 0
}
stop() {
  return 0
}
process $@


提示

   其实不用写这么复杂,直接下面这样也是可以的。

       #!/bin/bash

       wall  xxxx


#  chmod +x  script.sh  

需要赋予他执行权限,否则会报错,无法正常被执行。



  6. 使该 profile 生效

    #  tuned-adm profile webserver

Broadcast message from root@xxx (Sat May  6 05:10:04 2017):

Tuned Profile change to webserver !


  7. 验证

    # tuned-adm active

Current active profile: webserver

    # sysctl  -a |grep 'fs.file-max'
fs.file-max = 655350


    # cat /sys/block/sda/queue/scheduler
noop [deadline] cfq

   

    全部都已经生效了。设置成功,另外,我们可以输入如下命令查看一下 tuned.conf 到底都能写入何种类型的字段【type=xxx】

    # rpm  -ql  tuned | grep 'plugins/plugin_.*.py$'
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_audio.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_bootloader.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_cpu.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_disk.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_eeepc_she.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_modules.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_mounts.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_net.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scheduler.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_script.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_scsi_host.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_selinux.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysctl.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_sysfs.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_usb.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_video.py
/usr/lib/python2.7/site-packages/tuned/plugins/plugin_vm.py


更多 tuned.conf 的参数也可以参考红帽官方网站的 tuned 章节。另外,性能调优是在出现问题后或者瓶颈后才需要调整,不要一味的盲目调节,否则只会适得其反。

    且调且珍惜




       



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值