全站搜索 公开课 学习资料 未分类

RHCE培训课堂实验-25 开放研究实验-监控和管理LINUX进程

系统技术 97

红帽系统管理1-学员练习册-08监控和管理LINUX进程.pdf—P260

在本实验中,您将查找和管理系统上使用最多资源的进程。

目标:

您应能够使用top作为流程管理工具来管理流程。

实验准备工作:

student用户身份并使用student作为密码登录workstation

workstation上,运行lab processes-review start命令。该命令将运行—个起始脚本,以确定主机serverb是否可从网络访问。


[student@workstation ~]$ lab processes-monitor start
 

1workstation上,打开两个终端窗口并将它们并排显示。在本节中,这些终端指代为。在每个终端窗口中,以student用户身份登录serverb。创建—个名为process101的脚本,这将生成人为CPU负载。在/home/student/bin目录中创建该脚本。

1.1 在workstation上,打开两个终端窗口并将它们并排显示。在每个终端中,使用ssh命令以student用户身份登录serverb


[student@workstation ~]$ ssh student@serverb
 

1.2 在左终端shell中,使用mkdir命令来创建/home/student/bin目录。


[student@serverb ~]$ mkdir /home/student/bin
 

1.3 在左终端shell中, 使用vim命令来创建process101脚本。按i键,以进入交互模式。键入:wq以保存文件。


[student@serverb ~]$ vim /home/student/bin/process101
 

#在process101文件中添加下列内容

#!/bin/bash

while true; do

 var=1

 while [[ var -lt 50000 ]]; do

 var=$(($var+1))

 done

 sleep 1

done

1.4 使用chmod命令,使process101文件变为可执行文件。


[student@serverb ~]$ chmod +x /home/student/bin/process101
 

2右侧终端中,运行top实用程序。

2.1 在右侧终端中, 运行top实用程序。尽可能将窗口调高。


[student@serverb ~]$ top
 

3左侧终端shell中,确定虚拟机上的逻辑CPU数蛋。在后台运行process101脚本。

3.1 使用grep命令确定逻辑CPU的数量。


[student@serverb ~]$ grep "model name" /proc/cpuinfo | wc -l
 

3.2 使用cd命令更改到/home/student/bin目录。在后台运行process101脚本。


[student@serverb ~]$ cd /home/student/bin
[student@serverb bin]$ process101 &
 

4右终端shell中,观察top显示。在负载、线程和内存之间切换。记下process101的进程ID(PID) 。查看CPU百分比。它应该在10%15%左右徘徊。在查看了负载、线程和内存后,确保top显示CPU使用率。

4.1 按Shift+m

注意

请注意,当top切换到内存模式时,process101不再是第一个进程。您可以通过按Shift+p返回到CPU使用率。

4.2 按m

4.3 按t

4.4 按Shift+p

5 关闭显示中的粗体使用。保存此配置,以便在重启top时重新利用。确认己保存更改。

5.1 按Shift+b, 以关闭粗体使用。

5.2 按Shift+w,以保存此配置默认配置存储在/home/student/.config/procps目录下的toprc中。在左终端shell中,确认toprc文件存在。


[student@serverb bin]$ ls -l /home/student/.config/procps/toprc
 

5.3 在右终端shell中,退出top, 然后重新启动它。确认新显示使用了保存的配置。

6process101脚本复制到名为process102的新文件。编辑脚本,以创建更多人为CPU负载。将负载从五万增加到十万。在后台启process102 进程。

6.1 在左终端shell中,使用cp命令将process101复制到process102


[student@serverb bin]$ cp process101 process102
 

6.2 使用vim命令编辑process102脚本。将加法题数量从五万增加到十万。通过按i进入交互模式。键入:wq以保存文件。


[student@serverb bin]$ vim process102
 

#在process102中添加下列内容

#!/bin/bash
while true; do
 var=1
  while [[ var -lt 100000 ]]; do
   var=$(($var+1))
 done
 sleep 1
done

6.3 在后台启动process102进程。


[student@serverb bin]$ process102 &
 

6.4 使用jobs命令,确认两个进程都在后台运行。


[student@serverb bin]$ jobs
 

7右终端shell中,确认进程正在运行并在使用最多的CPU资源。负载应该在25%35%之间徘佪。

7.1 在右终端shell中,确认进程正在运行并在使用最多的CPU资源。负载应该在25%35%之间徘佪。

8 负载平均值仍低于1。将process101复制到一个名为process103的新脚本。将加法数呈增加到八十万。在后台启动process103。确认负载平均值超过1 。可能需要等几分钟后,负载平均值才会变化。

8.1 在右终端shell中,确认负载平均值低千1

8.2 在左终端shell中,使用cp命令将process101复制到名为process103的新脚本。


[student@serverb bin]$ cp process101 process103
 

8.3 在左终端shell中,使用vim命令来编辑process103脚本。将加法数量增加到八十万。通过按i键进入交互模式。键入:wq以保存文件。


[student@serverb bin]$ vim process103
 

#在process103中添加下列内容

#!/bin/bash
while true; do
 var=1
  while [[ var -lt 800000 ]]; do
   var=$(($var+1))
  done
  sleep 1
done

8.4 在后台启动process103CPU使用率在60%85%之间徘佪。


[student@serverb bin]$ process103 &
 

8.5 确认所有三个作业都在后台运行。


[student@serverb bin]$ jobs
 

8.6 在右终端窗口中,确认负载平均值超过1。

9左终端shell中,变为root用户。暂停process101进程。列出剩余的作业。观察process101的进程状态现在为T

9.1 使用su – 命令变为root用户。密码是redhat


[student@serverb bin]$ su - 
 

9.2 使用pkill命令及-SIGSTOP选项来暂停process101进程。


[root@serverb ~]# pkill -SIGSTOP process101
 

9.3 在右终端shell中,确认process101不再运行。

9.4 在左终端shell中, 运行ps jT命令以查看剩余的作业。


[root@serverb ~]# ps jT
 

注意

process101状态为T。这表示该进程目前已被暂停。

10 恢复process101进程。

10.1 在左终端shell中,使用pkill命令及-SIGCONT选项来恢复process101进程。


[root@serverb ~]# pkill -SIGCONT process101
 

10.2 在右终端shell 中,确认进程重新处于运行状态。

11 通过命令行终止process101process102 process103。确认top中不再显示这些进程。

11.1 在左终端shell中,使用pkill命令终止process101process102process103


[root@serverb ~]# pkill process101
[root@serverb ~]# pkill process102
[root@serverb ~]# pkill process103
 

11.2 在右终端shell中,确认top中不再显示这些进程。

12左终端shell中, 从root用户退出。在右终端shell中,停止top命令。在两个窗口中,退出serverb

12.1 使用exit命令,从root用户注销。


[root@serverb ~]# exit
 

12.2 从所有终端窗口退出。


[student@serverb bin]$ exit
 

12.3 在右终端shell中,按q键以退出top。使用exit命令注销。


[student@serverb ~]$ exit
 

评估

workstation上,运行lab processes-review grade脚本来确认是否成功完成本练习。


[student@Workstation ~]$ lab processes-review grade
 

完成

workstation上,运行lab processes-review finish脚本来完成本实验。


[student@Workstation ~]$ lab processes-review finish
 

本实验到此结束。

扫码添加教务-杨老师微信号,备注“红帽”,可免费领取实验环境和完整的PDF技术资料。

上一篇: 下一篇:

相关推荐

展开更多
1
点击联系客服咨询!咨询电话:0756-2180090