码迷,mamicode.com
首页 > 系统相关 > 详细

实验:管理进程及计划任务

时间:2016-06-24 12:59:58      阅读:886      评论:0      收藏:0      [点我收藏+]

标签:管理进程;计划任务;kill;pid;crond;crontab

实验:管理进程及计划任务




实验环境

为了更好地了解和控制Linux服务器的有序运行,需要管理员熟悉进程管理和计划任务 设置的相关操作,以完成各种运行维护任务。


需求描述

  • 管理系统中的进程。

    • 使用kill命令终止postfix服务的运行。

    • 查找系统中CPU占用率超过80%的进程,并强行终止该进程。

  • 设置计划运行的系统管理任务。

    • 每周一的早上7:50自动清空FTP服务器公共目录“/var/ftp/pub”中的数据。

    • 每天晚上的10:30自动执行任务,完成以下操作:显示当前的系统时间并查看 已挂载磁盘分区的磁盘使用情况,将输出结果追加保存到文件/var/log/df.log 中,以便持续观察硬盘空间的变化。

    • 确认所设置的计划任务列表。




使用kill命令终止postfix服务的运行。

查看postfixpid

[root@test2 jason]# service postfix status
master (pid  6314) is running...

终止postfix进程

[root@test2 jason]# kill 6314

终止后查看postfix状态

[root@test2 jason]# service postfix status
master dead but pid file exists




查找系统中CPU占用率超过80%的进程,并强行终止该进程。

这里借助cpuburn-in来提升cpu占用率


运行

[root@test2 Desktop]# ./cpuburn-in 1

CPU Burn-in v1.00 - Linux
-------------------------
Michal Mienik (c) 2000. cluster2k@hotmail.com

0 iterations complete.
5000 iterations complete.
10000 iterations complete.
15000 iterations complete.
20000 iterations complete.
25000 iterations complete.
30000 iterations complete.
35000 iterations complete.
40000 iterations complete.
...                              //中间过程省略
480000 iterations complete.
485000 iterations complete.
490000 iterations complete.

Test Complete. No errors were found after running 493240 tests.
[root@test2 Desktop]#


通过top查看


技术分享


kill


技术分享




检查crond的状态:

[root@test2 init.d]# /etc/init.d/crond status
crond (pid  2841) is running...
[root@test2 init.d]#

crond已经启动


每周一的早上7:50自动清空FTP服务器公共目录“/var/ftp/pub”中的数据。

[root@test2 init.d]# crontab -e
no crontab for root - using an empty one

50 7 * * 1 /bin/rm -rf /var/ftp/pub/*
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
:wq

检查计划是否设置成功:

[root@test2 init.d]# crontab -l
50 7 * * 1 /bin/rm -rf /var/ftp/pub/*
[root@test2 init.d]#

已经设置成功




每天晚上的10:30自动执行任务,完成以下操作:显示当前的系统时间并查看已挂载磁盘分区的磁盘使用情况,将输出结果追加保存到文件/var/log/df.log 中,以便持续观察硬盘空间的变化。


[root@test2 ~]# crontab -e

50 7 * * 1 /bin/rm -rf /var/ftp/pub/*
30 22 /1 * * /bin/date >> /var/log/df.log
30 22 /1 * * /bin/mount >> /var/log/df.log
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
:wq

退出来后:

crontab: installing new crontab
"/tmp/crontab.TnDEbR":2: bad day-of-month
errors in crontab file, can‘t install.
Do you want to retry the same edit? 
Enter Y or N
Do you want to retry the same edit? y

50 7 * * 1 /bin/rm -rf /var/ftp/pub/*
30 22 */1 * * /bin/date >> /var/log/df.log
30 22 */1 * * /bin/mount >> /var/log/df.log
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
~   
:wq

这里面提示出现错误,是因为每日的格式是“*/1”,而不是"/1".重新修改格式。然后确认。

确认所设置的计划任务列表:

[root@test2 ~]# crontab -l
50 7 * * 1 /bin/rm -rf /var/ftp/pub/*
30 22 */1 * * /bin/date >> /var/log/df.log
30 22 */1 * * /bin/mount >> /var/log/df.log
[root@test2 ~]#

验证date和mount计划:

[root@test2 log]# ls -lh | grep df
-rw-r--r--  1 root root  779 Jun 23 22:30 df.log
[root@test2 log]#


[root@test2 log]# cat /var/log/df.log 
Thu Jun 23 22:30:01 CST 2016
/dev/mapper/vg_jason-lv_root on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw)
/dev/sda1 on /boot type ext4 (rw)
/dev/sdc1 on /home type ext4 (rw)
/dev/md1 on /mdata2 type ext4 (rw)
/dev/mapper/mail_store-mbox on /mailbox type ext4 (rw,usrquota,grpquota)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
vmware-vmblock on /var/run/vmblock-fuse type fuse.vmware-vmblock (rw,nosuid,nodev,default_permissions,allow_other)
/dev/sr0 on /media/CentOS_6.5_Final type iso9660 (ro,nosuid,nodev,uhelper=udisks,uid=507,gid=507,iocharset=utf8,mode=0400,dmode=0500)
gvfs-fuse-daemon on /root/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev)
[root@test2 log]#

截图:


技术分享






本文出自 “Code Life” 博客,请务必保留此出处http://zencode.blog.51cto.com/11714065/1792498

实验:管理进程及计划任务

标签:管理进程;计划任务;kill;pid;crond;crontab

原文地址:http://zencode.blog.51cto.com/11714065/1792498

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!