九、服务与计划任务

一、服务

RHEL6:
1.linux系统中服务类型为三种:
由init控制的服务
有system V启动脚本启动服务
由xinetd管理的服务
1>.init
/etc/inittab
该服务配置在/etc/inittab配置文件中
此服务器可以配置respawn参数,表示在服务每次关闭时候会自动重启
2>.system V
启动脚本的存放路径为/etc/rc.d/init.d/
/etc/rc.d/init.d/xxx stop|start|restart|status
service xxx stop|start|restart|status
eg:

3>.xinetd
又名超级服务器,经常管理多种轻量级Internet服务
/etc/xinetd/xxx
service xinetd start

2.chkconfig指令:服务开机自启动
用法:
chkconfig --list 列出系统中所有服务列表
chkconfig xxx on|off 下次开机是否自启
chkconfig --list 显示服务列表
chkconfig --level 35 xxx on|off 指定运行界别

3.ntsysv服务配置工具
yum install -y ntsysv
ntsysv

RHEL7:
systemd是Linux系统用于管理系统和服务的工具。他被设计为向后
兼容SysV init脚本,并提供了大量的功能。包括在引导系统时并行
启动系统服务。按需激活守护进程。支持系统状态快照,基于依赖
关系的服务控制逻辑。在RHEL7中systemd取代upstart成为新的默认
初始化系统。

1、启动一个服务
service name start
systemctl start name.service

2、停止一个服务
service name stop
systemctl stop name.service

3、重新启动一个服务
service name restart
systemctl restart name.service

4、只有服务正在运行时,尝试重启他。
service name condrestart
systemctl try-restart name.service

5、重新加载配置文件
service name reload
systemctl reload name.service

6、检查服务是否正在运行
service name status
systemctl status name.service
systemctl is-active name.service

7、显示所有服务的状态
service --status-all
systemctl list-units --type service --all


二、计划任务


1、一次性计划任务
at 触发器
atd 守护进程

1>.查看已有的一次性计划任务
at -l,atq

2>.删除已有的一次性计划任务
atrm 任务号

3>.一次性计划任务访问控制
/etc/at.allow 允许
/etc/at.deny 拒绝
1个用户占一行,先检查at.allow文件
一般只有root用户才可以做一次性计划任务

2、周期性计划任务
1>.cron计划任务允许用户根据“时间表”自动周期的完成任务某些任务
crontab -e -u
crontab -l 查看时间表
crontab -r 针对性删除


2>.开启crond服务
service crond start
chkconfig crond on

3>.编辑crontab
crontab -e -u root
每天23点58分清空/tmp/所有内容
* * * * *
分 时 日 月 周 命令
58 23 * * * rm -rf /tmp/*
每周1,3,5的17点开启ftp服务
0 17 * * 1,3,5 service vsftpd start
1-10号之间每隔三天的18点执行一次重启http服务
0 18 1-10/3 1 * service httpd restart
1月-3月 每隔三天 在23点整 重启httpd服务
* 23 * 1-3/3 * service httpd restart

每周的1,3,5 23点 清空ftp根目录下的所有文件(/var/ftp/pub)
* 23 * * 1,3,5 rw -rf /var/ftp/pub

3、tmpwatch 为指定目录清空古旧文件
eg:tmpwatch /tmp/*

猜你喜欢

转载自www.cnblogs.com/xmdjb/p/10949412.html