关于 Linux中系统调优的一些笔记(一)
【摘要】 我突然又明白,死亡是聪明的兄长,我们可以放心地把自己托付给他,他会知道在我们有所准备的适当时刻前来。我也突然懂得,原来痛苦、失望和悲愁不是为了惹恼我们,使我们气馁或者无地自容;它们的存在,是为了使我们心智成熟,臻于完善。—赫尔曼·黑塞《彼得·卡门青》
写在前面
- 推送的的邮件里看到有大佬讲的公共课,听了之后这里整理学习笔记。
- 因为是公开课,所以讲的很浅,没接触过,这里做为了解,长长见识。
我突然又明白,死亡是聪明的兄长,我们可以放心地把自己托付给他,他会知道在我们有所准备的适当时刻前来。我也突然懂得,原来痛苦、失望和悲愁不是为了惹恼我们,使我们气馁或者无地自容;它们的存在,是为了使我们心智成熟,臻于完善。—赫尔曼·黑塞《彼得·卡门青》
零、系统调优原理概述:
通过调整系统设置
来提高计算机资源的利用率
、数据吞吐量
或用戶体验
的过程,消除或减轻系统中的排队现象
。
分析系统性能的方法:
分析利用率、饱和、错误 (Utilization, Saturation and Errors (USE))和系统资源 | – |
---|---|
资源 Resource | 服务器中的硬件资源(CPU、内存、网络、 磁盘和控制器) |
利用率 Utilization | 资源提供服务的平均时间(70%) |
饱和度 Saturation | 资源承担额外工作量的能力,这类工作通常 排队(队列长度) |
错误 Errors | 错误事件数量 |
执行系统变更的步骤:
执行系统变更的步骤 |
---|
设定基线:在调优中,执行性能测试,收集指标 |
执行变更:在系统上执行变更,建议查阅相应官方文档 |
验证变更有效性:执行变更后,重新运行测试,比较一些关键指标 |
取消变更并与基线对比:如有需要,可以取消变更并返回到基线状态 |
应用最终更改:应用并记录最终变更 |
一、如何检测系统的性能瓶颈
1、检测系统当前运行负载:vmstat、mpstat、iostat、top 等
装包,一般不需要
yum install -y sysstat
sysstat
包含监测系统性能及效率的一组工具,这些工具对于我们收集系统性能数据,比如 CPU 使用率、硬盘和网络吞吐数据,这些数据的收集和分析,有利于我们判断系统是否正常运行,是提高系统运行效率、安全运行服务器的得力助手。
vmstat 内存子系统监控
┌──[root@liruilongs.github.io]-[~]
└─$ vmstat
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 3228884 2076 594152 0 0 10 6 102 152 0 0 100 0 0
┌──[root@liruilongs.github.io]-[~]
└─$ vmstat 1
procs -----------memory---------- ---swap-- -----io---- -system-- ------cpu-----
r b swpd free buff cache si so bi bo in cs us sy id wa st
1 0 0 3228852 2076 594184 0 0 10 6 102 152 0 0 100 0 0 # 平均值
0 0 0 3228852 2076 594184 0 0 0 0 197 289 0 1 99 0 0
0 0 0 3228852 2076 594184 0 0 0 0 192 290 0 0 100 0 0
1 0 0 3228852 2076 594184 0 0 0 0 180 285 0 0 100 0 0
0 0 0 3228852 2076 594184 0 0 0 0 174 276 1 0 99 0 0
0 0 0 3228852 2076 594184 0 0 0 0 173 267 0 0 100 0 0
0 0 0 3228852 2076 594184 0 0 0 0 176 268 0 0 100 0 0
0 0 0 3228852 2076 594184 0 0 0 0 173 274 0 0 100 0 0
^C
┌──[root@liruilongs.github.io]-[~]
└─$
mpstat CUP子系统监控
┌──[root@liruilongs.github.io]-[~]
└─$ mpstat 1
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/23/2021 _x86_64_ (2 CPU)
01:41:22 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
01:41:23 AM all 0.52 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 99.48
01:41:24 AM all 0.00 0.00 0.51 0.00 0.00 0.00 0.00 0.00 0.00 99.49
01:41:25 AM all 0.00 0.00 0.00 0.00 0.00 0.52 0.00 0.00 0.00 99.48
01:41:26 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
01:41:27 AM all 0.00 0.00 0.52 0.00 0.00 0.00 0.00 0.00 0.00 99.48
01:41:28 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
01:41:29 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
^C
Average: all 0.07 0.00 0.15 0.00 0.00 0.07 0.00 0.00 0.00 99.71
┌──[root@liruilongs.github.io]-[~]
└─$ mpstat 1 3
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/23/2021 _x86_64_ (2 CPU)
01:42:06 AM CPU %usr %nice %sys %iowait %irq %soft %steal %guest %gnice %idle
01:42:07 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
01:42:08 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
01:42:09 AM all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
Average: all 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 0.00 100.00
┌──[root@liruilongs.github.io]-[~]
└─$
iostat IO子系统监控
┌──[root@liruilongs.github.io]-[~]
└─$ iostat 1 3
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/23/2021 _x86_64_ (2 CPU)
avg-cpu: %user %nice %system %iowait %steal %idle
0.21 0.00 0.24 0.05 0.00 99.50
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.56 19.86 12.15 387999 237243
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.52 0.00 99.48
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 1.00 8.00 0.00 8 0
avg-cpu: %user %nice %system %iowait %steal %idle
0.00 0.00 0.00 0.00 0.00 100.00
Device: tps kB_read/s kB_wrtn/s kB_read kB_wrtn
sda 0.00 0.00 0.00 0 0
┌──[root@liruilongs.github.io]-[~]
└─$
top 综合情况监控
top - 01:46:43 up 5:29, 1 user, load average: 0.01, 0.02, 0.05
Tasks: 151 total, 1 running, 150 sleeping, 0 stopped, 0 zombie
%Cpu0 : 0.0 us, 0.0 sy, 0.0 ni,100.0 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
%Cpu1 : 0.3 us, 0.0 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st
KiB Mem : 4030172 total, 3227596 free, 205988 used, 596588 buff/cache
KiB Swap: 10485756 total, 10485756 free, 0 used. 3531292 avail Mem
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
844 etcd 20 0 10.308g 22996 11100 S 2.7 0.6 11:10.71 etcd
572 root 20 0 220312 5208 3508 S 0.3 0.1 0:06.03 rsyslogd
592 root 20 0 298868 6260 4916 S 0.3 0.2 1:32.71 vmtoolsd
1 root 20 0 125408 3836 2440 S 0.0 0.1 0:09.03 systemd
2 root 20 0 0 0 0 S 0.0 0.0 0:00.07 kthreadd
3 root 20 0 0 0 0 S 0.0 0.0 0:00.61 ksoftirqd/0
5 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/0:0H
7 root rt 0 0 0 0 S 0.0 0.0 0:00.27 migration/0
8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 rcu_bh
9 root 20 0 0 0 0 S 0.0 0.0 0:05.72 rcu_sched
10 root rt 0 0 0 0 S 0.0 0.0 0:01.25 watchdog/0
11 root rt 0 0 0 0 S 0.0 0.0 0:01.15 watchdog/1
12 root rt 0 0 0 0 S 0.0 0.0 0:00.17 migration/1
13 root 20 0 0 0 0 S 0.0 0.0 0:00.54 ksoftirqd/1
15 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kworker/1:0H
17 root 20 0 0 0 0 S 0.0 0.0 0:00.05 kdevtmpfs
18 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 netns
19 root 20 0 0 0 0 S 0.0 0.0 0:00.03 khungtaskd
20 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 writeback
21 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kintegrityd
22 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 bioset
23 root 0 -20 0 0 0 S 0.0 0.0 0:00.00 kblockd
- load average: 0.01 不能超过 0.7
- 需要除以 cpu核数 ;数字1
2、检测系统历史运行负载:sar
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ pwd
/usr/lib/systemd/system
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ cat sysstat.service
# /usr/lib/systemd/system/sysstat.service
# (C) 2012 Peter Schiffer (pschiffe <at> redhat.com)
#
# sysstat-10.1.5 systemd unit file:
# Insert a dummy record in current daily data file.
# This indicates that the counters have restarted from 0.
[Unit]
Description=Resets System Activity Logs
[Service]
Type=oneshot
RemainAfterExit=yes
User=root
ExecStart=/usr/lib64/sa/sa1 --boot
[Install]
WantedBy=multi-user.target
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ systemctl status sysstat.service
● sysstat.service - Resets System Activity Logs
Loaded: loaded (/usr/lib/systemd/system/sysstat.service; enabled; vendor preset: enabled)
Active: active (exited) since Wed 2021-10-13 01:53:41 CST; 1 weeks 3 days ago
Main PID: 584 (code=exited, status=0/SUCCESS)
CGroup: /system.slice/sysstat.service
Oct 13 01:53:41 liruilongs.github.io systemd[1]: Starting Resets System Activity Logs...
Oct 13 01:53:41 liruilongs.github.io systemd[1]: Started Resets System Activity Logs.
红帽8没有,需要自己开启,红帽7有
┌──[root@liruilongs.github.io]-[/]
└─$ cd /var/log/sa
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$ ls
sa01 sa03 sa04 sa05 sa06 sa08 sa09 sa13 sa14 sa23 sa24 sa30 sar03
CPU 监控信息
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$ sar -f sa24 -p # CPU 监控信息
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM CPU %user %nice %system %iowait %steal %idle
09:40:01 AM all 1.44 0.00 1.72 0.21 0.00 96.64
09:50:01 AM all 0.80 0.00 1.51 0.01 0.00 97.69
10:00:01 AM all 0.81 0.00 1.56 0.00 0.00 97.63
10:10:01 AM all 0.74 0.00 1.40 0.02 0.00 97.83
10:20:01 AM all 0.65 0.00 1.26 0.00 0.00 98.08
10:30:01 AM all 0.78 0.02 1.50 0.04 0.00 97.67
10:40:01 AM all 3.24 0.00 5.65 0.01 0.00 91.11
Average: all 1.18 0.00 2.10 0.03 0.00 96.69
负载信息
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$ sar -f sa24 -q # 负载信息
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM runq-sz plist-sz ldavg-1 ldavg-5 ldavg-15 blocked
09:40:01 AM 0 215 0.06 0.40 0.42 0
09:50:01 AM 0 215 0.41 0.21 0.28 0
10:00:01 AM 1 215 0.27 0.13 0.20 0
10:10:01 AM 1 216 0.03 0.08 0.14 0
10:20:01 AM 0 216 0.00 0.04 0.10 0
10:30:01 AM 1 217 0.00 0.03 0.06 0
10:40:01 AM 0 215 0.07 0.16 0.14 0
Average: 0 216 0.12 0.15 0.19 0
内存信息
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$ sar -f sa24 -r # 内存信息
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM kbmemfree kbmemused %memused kbbuffers kbcached kbcommit %commit kbactive kbinact kbdirty
09:40:01 AM 3472808 557364 13.83 2076 266132 832840 5.74 157400 244716 8
09:50:01 AM 3470960 559212 13.88 2076 266516 832840 5.74 158004 244652 4
10:00:01 AM 3466736 563436 13.98 2076 270432 832972 5.74 158272 248436 0
10:10:01 AM 3465552 564620 14.01 2076 270856 833480 5.74 159624 247772 0
10:20:01 AM 3465732 564440 14.01 2076 271172 833584 5.74 159720 248028 0
10:30:01 AM 3457092 573080 14.22 2076 272904 833772 5.74 161872 247732 0
10:40:01 AM 3458440 571732 14.19 2076 271864 833032 5.74 160824 247256 0
Average: 3465331 564841 14.02 2076 269982 833217 5.74 159388 246942 2
网卡信息
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$ sar -f sa24 -n DEV # 网卡信息
Linux 3.10.0-693.el7.x86_64 (liruilongs.github.io) 10/24/2021 _x86_64_ (2 CPU)
08:14:46 AM LINUX RESTART
08:20:03 AM IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
09:40:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:40:01 AM ens32 0.34 0.37 0.04 0.33 0.00 0.00 0.00
09:40:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
09:40:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:50:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
09:50:01 AM ens32 1.19 0.78 0.10 0.36 0.00 0.00 0.00
09:50:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
09:50:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:00:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:00:01 AM ens32 0.20 0.13 0.02 0.01 0.00 0.00 0.00
10:00:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
10:00:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:10:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:10:01 AM ens32 0.49 0.50 0.04 0.54 0.00 0.00 0.00
10:10:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
10:10:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:20:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:20:01 AM ens32 0.17 0.11 0.01 0.01 0.00 0.00 0.00
10:20:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
10:20:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:30:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:30:01 AM ens32 0.04 0.03 0.00 0.00 0.00 0.00 0.00
10:30:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
10:30:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:40:01 AM br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
10:40:01 AM ens32 0.08 0.06 0.01 0.00 0.00 0.00 0.00
10:40:01 AM lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
10:40:01 AM docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: IFACE rxpck/s txpck/s rxkB/s txkB/s rxcmp/s txcmp/s rxmcst/s
Average: br-4b3da203747c 0.00 0.00 0.00 0.00 0.00 0.00 0.00
Average: ens32 0.36 0.28 0.03 0.17 0.00 0.00 0.00
Average: lo 0.13 0.13 0.01 0.01 0.00 0.00 0.00
Average: docker0 0.00 0.00 0.00 0.00 0.00 0.00 0.00
┌──[root@liruilongs.github.io]-[/var/log/sa]
└─$
3、通过 Performance Co-Pilot(PCP) 收集性能数据
安装相关包
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ yum -y install pcp
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ yum install pcp-gui -y
启动相关服务
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ systemctl enable --now pmcd # 启动监控服务
Created symlink from /etc/systemd/system/multi-user.target.wants/pmcd.service to /usr/lib/systemd/system/pmcd.service.
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
└─$ systemctl enable --now pmlogger # 启动存数据的数据库
Created symlink from /etc/systemd/system/multi-user.target.wants/pmlogger.service to /usr/lib/systemd/system/pmlogger.service.
┌──[root@liruilongs.github.io]-[/usr/lib/systemd/system]
通过pmchart,pminfo,pmval读取系统当前及历史运行数据
查看所有的监控内容
┌──[root@liruilongs.github.io]-[~]
└─$ pminfo
jbd2.njournals
jbd2.transaction.count
jbd2.transaction.requested
......
┌──[root@liruilongs.github.io]-[~]
└─$ pminfo | wc -l
2052
查看所有的监控参数详细信息
┌──[root@liruilongs.github.io]-[~]
└─$ pminfo -dt proc.nprocs #参数详细信息
proc.nprocs [instantaneous number of processes]
Data Type: 32-bit unsigned int InDom: PM_INDOM_NULL 0xffffffff
Semantics: instant Units: none
┌──[root@liruilongs.github.io]-[~]
└─$ pminfo proc.nprocs #进程监控
proc.nprocs
监控进程信息 pmval proc.nprocs
┌──[root@liruilongs.github.io]-[~]
└─$ pmval proc.nprocs #进程监控
metric: proc.nprocs
host: liruilongs.github.io
semantics: instantaneous value
units: none
samples: all
158
158
158
158
158
158
^C
监控剩余内存的量 pmval -t 2 mem.freemem
┌──[root@liruilongs.github.io]-[~]
└─$ pmval -t 2 mem.freemem # 剩余内存信息
metric: mem.freemem
host: liruilongs.github.io
semantics: instantaneous value
units: Kbyte
samples: all
3471612
3471636
3471636
3471636
3471636
^C
┌──[root@liruilongs.github.io]-[~]
└─$
查看监控日志
┌──[root@liruilongs.github.io]-[~]
└─$ pminfo | grep mem.freemem
mem.freemem
┌──[root@liruilongs.github.io]-[~]
└─$ cd /var/log/pcp
┌──[root@liruilongs.github.io]-[/var/log/pcp]
└─$ ls
NOTICES pmcd pmie pmlogger pmproxy
┌──[root@liruilongs.github.io]-[/var/log/pcp]
└─$ cd pmlogger/
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger]
└─$ ls
liruilongs.github.io pmlogger_check.log.prev pmlogger_daily-K.log.prev pmlogger_daily.stamp
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger]
└─$ cd liruilongs.github.io/
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger/liruilongs.github.io]
└─$ ls
20211023.02.05.0.xz 20211023.02.30-00.0.xz 20211023.02.30.0.xz 20211024.08.16.0 Latest
20211023.02.05.index 20211023.02.30-00.index 20211023.02.30.index 20211024.08.16.index pmlogger.log
20211023.02.05.meta.xz 20211023.02.30-00.meta.xz 20211023.02.30.meta.xz 20211024.08.16.meta pmlogger.log.prior
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger/liruilongs.github.io]
└─$ pmval -a 20211024.08.16.0 mem.freemem # 查看监控日志 每秒
metric: mem.freemem
archive: 20211024.08.16.0
host: liruilongs.github.io
start: Sun Oct 24 08:17:06 2021
end: Sun Oct 24 10:02:06 2021
semantics: instantaneous value
units: Kbyte
samples: 6301
interval: 1.00 sec
08:17:06.095 No values available
08:17:07.095 No values available
08:17:08.095 3651184
08:17:09.095 3651184
08:17:10.095 3651184
08:17:11.095 3651184
08:17:12.095 3651184
08:17:13.095 3651184
08:17:14.095 3651184
08:17:15.095 3651184
08:17:16.095 3651184
08:17:17.095 3651184
08:17:18.095 3651184
08:17:19.095 3651184
08:17:20.095 3651184
08:17:21.095 3651184
08:17:22.095 3651184
08:17:23.095 3651184
08:17:24.095 3651184
08:17:25.095 3651184
08:17:26.095 3651184
......
加时间粒度
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger/liruilongs.github.io]
└─$ pmval -a 20211024.08.16.0 -t 500 mem.freemem # 加时间粒度
metric: mem.freemem
archive: 20211024.08.16.0
host: liruilongs.github.io
start: Sun Oct 24 08:17:06 2021
end: Sun Oct 24 10:08:06 2021
semantics: instantaneous value
units: Kbyte
samples: 14
interval: 500.00 sec
08:17:06.095 No values available
08:25:26.095 3488128
08:33:46.095 3488128
08:42:06.095 3488128
08:50:26.095 3488128
08:58:46.095 3488128
09:07:06.095 3488128
09:15:26.095 3488128
09:23:46.095 3488128
09:32:06.095 3488128
09:40:26.095 3472784
09:48:46.095 3472024
09:57:06.095 3467052
10:05:26.095 3466276
┌──[root@liruilongs.github.io]-[/var/log/pcp/pmlogger/liruilongs.github.io]
└─$
二、如何进行内核参数调优
/proc & /sys
/proc 存放内存中数据,每次重启就没了。
┌──[root@liruilongs.github.io]-[/]
└─$ cd proc/
┌──[root@liruilongs.github.io]-[/proc]
└─$ ls
1 16836 241 269 284 3 313 362 45 647 853 crypto keys pagetypeinfo tty
10 16842 242 270 285 300 314 363 469 649 856 devices key-users partitions uptime
1041 16843 250 271 286 301 315 364 47 66 857 diskstats kmsg sched_debug version
1043 16850 251 272 287 302 316 365 5 6671 861 dma kpagecount schedstat vmallocinfo
1045 16862 253 273 288 303 317 366 506 7 864 driver kpageflags scsi vmstat
1050 17 254 274 289 304 318 367 509 7603 8922 execdomains loadavg self zoneinfo
1051 18 255 275 290 305 319 368 570 7604 9 fb locks slabinfo
1054 19 256 276 291 306 32 369 581 7606 98 filesystems mdstat softirqs
1055 2 262 277 292 307 320 370 583 8 acpi fs meminfo stat
1056 20 263 278 293 308 321 371 585 8095 buddyinfo interrupts misc swaps
11 21 264 279 294 309 322 372 594 8158 bus iomem modules sys
12 22 265 280 295 31 33 373 595 8159 cgroups ioports mounts sysrq-trigger
13 23 266 281 296 310 34 42 596 8160 cmdline irq mpt sysvipc
15 24 267 282 298 311 348 44 627 8161 consoles kallsyms mtrr timer_list
16006 240 268 283 299 312 361 441 642 8162 cpuinfo kcore net timer_stats
┌──[root@liruilongs.github.io]-[/proc]
└─$ pwd
/proc
┌──[root@liruilongs.github.io]-[/proc]
└─$ cd sys
┌──[root@liruilongs.github.io]-[/proc/sys]
└─$ ls
abi crypto debug dev fs kernel net user vm
内存调优目录
┌──[root@liruilongs.github.io]-[/proc/sys]
└─$ cd vm # 内存调优目录
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ ls
admin_reserve_kbytes hugepages_treat_as_movable mmap_min_addr overcommit_memory
block_dump hugetlb_shm_group mmap_rnd_bits overcommit_ratio
compact_memory laptop_mode mmap_rnd_compat_bits page-cluster
dirty_background_bytes legacy_va_layout nr_hugepages panic_on_oom
dirty_background_ratio lowmem_reserve_ratio nr_hugepages_mempolicy percpu_pagelist_fraction
dirty_bytes max_map_count nr_overcommit_hugepages stat_interval
dirty_expire_centisecs memory_failure_early_kill nr_pdflush_threads swappiness
dirty_ratio memory_failure_recovery numa_zonelist_order user_reserve_kbytes
dirty_writeback_centisecs min_free_kbytes oom_dump_tasks vfs_cache_pressure
drop_caches min_slab_ratio oom_kill_allocating_task zone_reclaim_mode
extfrag_threshold min_unmapped_ratio overcommit_kbytes
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$
查看内核参数:cat & sysctl -a
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ sysctl -a # 查看所有调优参数
abi.vsyscall32 = 1
crypto.fips_enabled = 0
debug.exception-trace = 1
debug.kprobes-optimization = 1
debug.panic_on_rcu_stall = 0
dev.hpet.max-user-freq = 64
dev.mac_hid.mouse_button2_keycode = 97
dev.mac_hid.mouse_button3_keycode = 100
dev.mac_hid.mouse_button_emulation = 0
dev.parport.default.spintime = 500
dev.parport.default.timeslice = 200
dev.raid.speed_limit_max = 200000
dev.raid.speed_limit_min = 1000
dev.scsi.logging_level = 0
fs.aio-max-nr = 65536
fs.aio-nr = 0
..............
根据变量找对应文件参数
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ sysctl -a | grep net.ipv4.ip_forward
net.ipv4.ip_forward = 1
net.ipv4.ip_forward_use_pmtu = 0
sysctl: reading key "net.ipv6.conf.all.stable_secret"
sysctl: reading key "net.ipv6.conf.br-4b3da203747c.stable_secret"
sysctl: reading key "net.ipv6.conf.default.stable_secret"
sysctl: reading key "net.ipv6.conf.docker0.stable_secret"
sysctl: reading key "net.ipv6.conf.ens32.stable_secret"
sysctl: reading key "net.ipv6.conf.lo.stable_secret"
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cd ../net/ipv
ipv4/ ipv6/
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cd ../net/ipv4/
┌──[root@liruilongs.github.io]-[/proc/sys/net/ipv4]
└─$ cat ip_forward
1
调整内核参数:echo & sysctl
设置调优参数:临时调整
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cat swappiness
30
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ echo 40 > swappiness ## 临时调整
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cat swappiness
40
设置调优参数:永久调整
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cat /etc/sysc
sysconfig/ sysctl.conf sysctl.d/
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward = 1
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ echo "vm.swappiness = 20" >> /etc/sysctl.conf ## 永久调整
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ cat /etc/sysctl.conf
# sysctl settings are defined through files in
# /usr/lib/sysctl.d/, /run/sysctl.d/, and /etc/sysctl.d/.
#
# Vendors settings live in /usr/lib/sysctl.d/.
# To override a whole file, create a new file with the same in
# /etc/sysctl.d/ and put new settings there. To override
# only specific settings, add a file with a lexically later
# name in /etc/sysctl.d/ and put new settings there.
#
# For more information, see sysctl.conf(5) and sysctl.d(5).
net.ipv4.ip_forward = 1
vm.swappiness = 20
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$ sysctl -p
net.ipv4.ip_forward = 1
vm.swappiness = 20
┌──[root@liruilongs.github.io]-[/proc/sys/vm]
└─$
嗯,字数限制原因,发表不了,所以分开发布了
【版权声明】本文为华为云社区用户原创内容,转载时必须标注文章的来源(华为云社区)、文章链接、文章作者等基本信息, 否则作者和本社区有权追究责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)