系统调优-2(资源限制)

模块操作

lsmod
lsmod命令用于显示已经加载到内核中的模块的状态信息。执行lsmod命令后会列出所有已载入系统的模块。

查看模块是否加载到内核  lsmod | grep 模块名

模块在系统中的位置: /sys/module

modinfo

查看模块信息,

例如 modinfo -p 参数名,查看模块的参数.

modinfo 模块名,查看模块的所有信息

modprobe

modprobe命令用于智能地向内核中加载模块或者从内核中移除模块。

modprobe 模块名 :加载模块

modprobe -r 模块名:移除模块

/etc/modprobe.d/   模块开机启动配置文件

/etc/sysconfig/modules/  把需要加载的模块,写成以 *.modules 结尾的配置文件,开机就可以自动加载模块。

rmmod

rmmod命令用于从当前运行的内核中移除指定的内核模块。执行rmmod指令,可删除不需要的模块。Linux操作系统的核心具有模块化的特性,应此在编译核心时,务须把全部的功能都放如核心。你可以将这些功能编译成一个个单独的模块,待有需要时再分别载入它们。

性能调优 tuned服务

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

安装

yum install tuned -y
systemctl start tuned 
systemctl enable tuned

常用命令

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: desktop
tuned-adm profile desktop # 转换性能模式,更改后根据新的配置文件,更改内核参数

文件系统

文件碎片-fragmentation

e2freefrag

检查磁盘碎片,因为linux存储文件目前安装 extent 存储,磁盘碎片问题可以忽略不计.

[root@wpic throughput-performance]# e2freefrag /dev/vda1
Device: /dev/vda1
Blocksize: 4096 bytes
Total blocks: 10485248
Free blocks: 9953399 (94.9%)

Min. free extent: 4 KB 
Max. free extent: 2064256 KB
Avg. free extent: 76412 KB
Num. free extent: 465

HISTOGRAM OF FREE EXTENT SIZES:
Extent Size Range :  Free extents   Free Blocks  Percent
    4K...    8K-  :            56            56    0.00%
    8K...   16K-  :            51           121    0.00%
   16K...   32K-  :            55           280    0.00%
   32K...   64K-  :            53           553    0.01%
   64K...  128K-  :            61          1412    0.01%
  128K...  256K-  :            28          1177    0.01%
  256K...  512K-  :            32          2882    0.03%
  512K... 1024K-  :            20          4082    0.04%
    1M...    2M-  :            23          8063    0.08%
    2M...    4M-  :            20         15415    0.15%
    4M...    8M-  :            16         22809    0.23%
    8M...   16M-  :             4         12925    0.13%
   16M...   32M-  :             3         20496    0.21%
   32M...   64M-  :             4         45135    0.45%
   64M...  128M-  :            19        436615    4.39%
  256M...  512M-  :             2        187359    1.88%
    1G...    2G-  :            18       8123974   81.62%

filefrag

查看文件占用多少个 extent

[root@wpic ~]# filefrag jenkins-2.107.2-1.1.noarch.rpm 
jenkins-2.107.2-1.1.noarch.rpm: 1 extent found

Raid 格式化法则

#通过命令可以查看 Raid 的chunk size
chunk size  # raid 写入的时候每次在一块磁盘写入的 block 数
# 格式化 Raid 的法则
mkfs  -t -E stride=chunsize/blocksize,wtripe-width=有效磁盘*stripe
# Raid 5 为例
mkfs  -t -E stride=chunsize/blocksize,wtripe-width=2*stripe

资源限制

ulimit

需要和pam 验证配合使用,限制模块为 pam_limits.so,ulimit 用于限制 shell 启动进程所占用的资源.

pam 配置文件 /etc/pam.d/system-auth

模块的配置文件:/etc/security/limits.conf

常用命令

ulimit -a # 查看所有的参数
ulimit -n # 查看每个用户最大打开文件数

/etc/security/limits.conf

更改用户最大打开文件数,限制范围每个 session.

root soft nofile 65535
root hard nofile 65535
* soft nofile 65535
* hard nofile 65535

Cgroup 资源限制

CGroup 是 Control Groups 的缩写,是 Linux 内核提供的一种可以限制、记录、隔离进程组 (process groups) 所使用的物力资源 (如 cpu memory i/o 等等) 的机制。

安装

yum install libcgroup libcgroup-tools -y

配置文件

/etc/cgroup.conf     启动命令  systemctl start cgconfig

/etc/cgrules.conf     启动命令  systemctl start cgrep

Cgroup 子系统介绍

    blkio   -- 这个子系统为块设备设定输入/输出限制,比如物理设备(磁盘,固态硬盘,USB 等等)。
    cpu     -- 这个子系统使用调度程序提供对 CPU 的 cgroup 任务访问。
    cpuacct -- 这个子系统自动生成 cgroup 中任务所使用的 CPU 报告。
    cpuset  -- 这个子系统为 cgroup 中的任务分配独立 CPU(在多核系统)和内存节点。
    devices -- 这个子系统可允许或者拒绝 cgroup 中的任务访问设备。
    freezer -- 这个子系统挂起或者恢复 cgroup 中的任务。
    memory  -- 这个子系统设定 cgroup 中任务使用的内存限制,并自动生成由那些任务使用的内存资源报告。

cat /proc/cgroups  # 查看子系统

lssubsys

[root@wpic etc]# lssubsys  # 查看支持的子系统
cpuset
cpu,cpuacct
memory
devices
freezer
net_cls,net_prio
blkio
perf_event
hugetlb
pids
[root@wpic etc]# lssubsys -am # 查看子系统及对应的配置目录
cpuset /sys/fs/cgroup/cpuset
cpu,cpuacct /sys/fs/cgroup/cpu,cpuacct
memory /sys/fs/cgroup/memory
devices /sys/fs/cgroup/devices
freezer /sys/fs/cgroup/freezer
net_cls,net_prio /sys/fs/cgroup/net_cls,net_prio
blkio /sys/fs/cgroup/blkio
perf_event /sys/fs/cgroup/perf_event
hugetlb /sys/fs/cgroup/hugetlb
pids /sys/fs/cgroup/pids

如果需要配置:通过查看  man /etc/cgroup.conf  和 man /etc/cgrules.conf  配置

posted @ 2018-05-17 12:19  步绍训  阅读(217)  评论(0)    收藏  举报