一、任务计划

1、crontab   /etc/crontab  任务计划的配置文件

共有五个*:从左到右依次为分钟(0-59),时(0-23),日(1-31),月(1-12),周(0-6)或(7-6),周末可以用0或者7表示。当对哪一项没有要求时,对应项填*即可。

最后一列为用户和执行的命令。

2、crontab -e   进入任务创建的配置文件中,就可以编辑我们要执行的任务。

例如本例中的第4个任务,表示每隔8个小时执行一次,则用*/8表示,如果是2小时,则为*/2。

本例中的第5个任务,表示表示每天1点,12点,18点各执行一次,即遇到多个分钟、小时、月、周时,输入数值,用逗号隔开即可。

本例中的第6个任务,表示每天9点到18点时间段执行,即遇到在时间段的任务可以用n-m的方式表示。

3、查看crond的状态 systemctl status crond,  Active哪行,active (running)表示启动,未启动则显示inactive(dead)

也可以用 ps aux|grep crond

4启动crond服务 systemctl start crond

5、crontab -l 查看已经设定的任务计划

6、crontab -r 删除任务,删除之前可以备份,路径为/var/spool/cron/user,因为-r 会删除所有任务。

二、chkconfig 服务管理工具,ceotos7已经不再使用。

1、查看当前系统有哪些服务使用 chkconfig 工具   chkconfig --list

2、chkconfig network off /on  关闭或者开启某些服务,默认针对2,3,4,5四个级别操作

3、指定级别操作  --level  ,可以指定一个或者多个

 

4、--del   --add 删除或者添加某些服务

三、systemd 服务管理

1、列出系统所有服务  systemctl list-unit-files 

  systemctl list-units --all --type=service 列出所有service服务,但比 systemctl list-unit-files直观详细,不加--all,只会列出active的,不会列出inactive的。

2、常用的服务相关命令

1)让crond服务开即启动 systemctl enable crond 或开机不启动  systemctl disable crond

2)查看服务状态 systemctl status crond

3)启动服务 systemctl start crond  或停止服务 systemctl stop crond 重启服务  systemctl restart crond

4)查看某个服务是否开机启动

四、unit 

1、ls /usr/lib/systemd/system 下的unit,可分为9大类 

service 系统服务 
target 多个unit组成的组 
device 硬件设备 
mount 文件系统挂载点 
automount 自动挂载点 
path 文件或路径 
scope 不是由systemd启动的外部进程 
slice 进程组 
snapshot systemd快照 
socket 进程间通信套接字 
swap swap文件 
timer 定时器

2、7个运行级别

3、unit 相关命令

1)列出正在运行的until     systemctl list-units

2)列出所有的unit  systemctl list-units --all

3)列出所有inactive 的unit

4)列出所有状态的service

5)列出所有状态位active的service

6)查看某个unit是否active

五、target   系统为了方便管理用target来管理unit 

1、列出系统所有的target  systemctl list-unit-files --type=target

2、查看指定target包含的unit   systemctl list-dependencies multi-user.target 

3、查看系统默认的target systemctl get-default  

设置默认的target  stemctl set-default multi-user.target 

4、service 、unit、target 之间的联系

一个service属于一种类型的unit ,多个unit组成了一个target ,一个target里面包含了多个service ,

cat /usr/lib/systemd/system/sshd.service //看[install]部分,定义了该service属于哪一个target

posted on 2018-01-29 23:13  天梭  阅读(149)  评论(0编辑  收藏  举报