任务计划cron / chkconfig工具/ system管理服务/unit及target介绍

一、linux任务计划cron

1、cat /etc/crontab 任务计划的配制文件;

2、crontab -e 编辑配制文件。

图片说明,每个月的1-10号3点执行脚本123.sh ,以追加形式生成日志文件123.log,生成错误文件日志321.log
crontab -e 实际上是打开了 “/var/spool/cron/username” (如果是root则打开的是/var/spool/cron/root)这个文件,所以不要直接去编辑那个文件,因为可能会出错,所以一定要使用 crontab -e 来编辑,另外备份的话,直接复制一份这个目录下的文件即可!
制定计划建议都使用追加命令 >>,把正确和错误的都追加进一个文件里记录。
启动服务 systemctl start crond ,才会生效。

二、chkconfig工具(系统服务管理)

其实这就是系统所有的预设服务了,如network,cron 等等服务(service 服务名 start|stop|restart)

1、chkconfig –list 查看使用chkconfig这个工具的服务端有哪些
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
注:0:关机状态
1:单用户
2:无NFS支持的多用户模式
3:完全多用户模式
4:保留给用户自定义
5:图形登录方式
6:重启
ls /etc/init.d/ //服务端的启动脚本都放在这个目录下,只有启动脚本放在这个目录下才能加入系统服务中。
把network的3级别打开/关闭:
chkconfig --level 3 network off/on
(不加 –level 3 就是将0-6个级别都关掉)
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe

删除network服务端:
chkconfig –del network

添加network服务端(在/etc/init.d/目录下添加了启动脚本后需要用这个命令才能把服务加入到系统服务中):
chkconfig –add network

三、 systemd管理服务

查看所有的系统服务:
systemctl list-unit-files
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
列出所有的service的服务情况(如果不加all,不激活状态的就不会列出来):
systemctl list-units –all –type=service
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
几个常用的服务相关的命令
让某个服务开机启动(.service可以省略):
systemctl enable crond.service

不让开机启动:
systemctl disable crond

查看状态:
systemctl status crond

停止服务:
systemctl stop crond

启动服务:
systemctl start crond

重启服务:
systemctl restart crond

检查服务是否开机启动:
systemctl is-enabled crond

unit介绍

系统所有unit,分为以下类型:
ls /usr/lib/systemd/system
service:系统服务
target:多个unit组成的组
device:硬件设备
mount:文件系统挂载点
automount:自动挂载点
path:文件或路径
scope:不是由systemd启动的外部进程
slice:进程组
snapshot:systemd快照
socket:进程间通信套接字
swap:swap文件
timer:定时器
以上每种类型的文件都为一个unit,正式这些unit才组成了系统的各个资源(各个服务,各个设备等)。
unit相关的命令

列出正在运行(active)的unit:
systemctl list-units

列出所有,包括失败的或者inactive的:
systemctl list-units –all

列出inactive的unit:
systemctl list-units –all –state=inactive

列出所有状态的service:
systemctl list-units –all –type=service

列出状态为active的service:
systemctl list-units –type=service

查看某个服务是否为active:
systemctl is-active crond.service

四、unit相关的命令

系统所有unit,分为以下类型:
ls /usr/lib/systemd/system
service:系统服务
target:多个unit组成的组
device:硬件设备
mount:文件系统挂载点
automount:自动挂载点
path:文件或路径
scope:不是由systemd启动的外部进程
slice:进程组
snapshot:systemd快照
socket:进程间通信套接字
swap:swap文件
timer:定时器
以上每种类型的文件都为一个unit,正式这些unit才组成了系统的各个资源(各个服务,各个设备等)。

列出正在运行(active)的unit:
systemctl list-units

列出所有,包括失败的或者inactive的:
systemctl list-units –all

列出inactive的unit:
systemctl list-units –all –state=inactive

列出所有状态的service:
systemctl list-units –all –type=service

列出状态为active的service:
systemctl list-units –type=service

查看某个服务是否为active:
systemctl is-active crond.service**

五、target介绍

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

列出系统所有的target:
systemctl list-unit-files –type=target
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
查看指定target下面有哪些unit,如下列的multi-user:
systemctl list-dependencies multi-user.target
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
查看系统默认的target:
systemctl get-default
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe
设置默认的target:
systemctl set-default multi-user.target

一个service属于一种类型的unit

多个unit组成了一个target

一个target里面包含了多个service

cat /usr/lib/systemd/system/sshd.service //看[install]部分,定义了该service属于哪一个target
linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe

原文地址:http://blog.51cto.com/10690709/2115443

时间: 2024-08-29 14:12:12

任务计划cron / chkconfig工具/ system管理服务/unit及target介绍的相关文章

linux任务计划cron chkconfig工具 systemd管理服务 unit介绍 target介绍

[[email protected] ~]# crontab -e  编写任务计划no crontab for root - using an empty one 20 11 29 01 1 echo "OK" > /root/cron.log      表示在1月29日(星期一)的11点20分执行:echo  "OK" > /root/cron.log 命令crontab -e 实际上打开/var/spool/cron/username文件(如果用户是

cron计划任务、chkconfig工具、systemd管理服务、unit、target介绍

1. linux任务计划cron linux的大部分系统管理工作都是通过定期自动执行某个脚本来完成的,那么如何定期执行某个脚本呢?这就要借助linux的cron功能了,这部分的内容很重要,请牢记! 命令crontab linux的任务计划功能的操作都是通过crontab命令来完成的,其常用的选项有以下几个: -u:表示指定某个用户,不加-u选项则为当前用户. -e:表示制定计划任务 -l:表示列出计划任务 -r:表示删除计划任务 任务计划的配置文件: # cat /etc/crontab SHE

任务计划、chkconfig工具、systemd管理服务、unit、target

比如备份数据或者重启服务. crontab -u.-e.-l.-r(删除) 格式:分 时 日 月 周 user command 文件/var/spool/cron/username 分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7 可用格式1-5表示一个范围1到5 可用格式1,2,3表示1或者2或者3 可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时 要保证服务是启动状态 systemctl start crond.service cat /etc/cront

Android窗口管理服务WindowManagerService的简要介绍和学习计划

在前一个系列文章中,我们从个体的角度来分析了Android应用程序窗口的实现框架.事实上,如果我们从整体的角度来看,Android应用程序窗口的 实现要更复杂,因为它们的类型和作用不同,且会相互影响.在Android系统中,对系统中的所有窗口进行管理是窗口管理服务 WindowManagerService的职责.在本文中,我们就将简要介绍WindowManagerService的职能以及制定学习计划. 我们知道,在Android系统中,同一时刻,只有一个Activity窗口是激活的,但是,对于W

cron,chkconfig,systemd,unit,target介绍

cron任务计划 1.配置文件路径及模板: [[email protected] ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/usr/sbin:/usr/bin MAILTO=root # For details see man 4 crontabs # Example of job definition: # .---------------- minute (0 - 59) # | .------------- hour (0

Linux:综合架构批量管理服务(ansible)-- 下

综合架构批量管理服务之--ansible 00. 介绍部分 1) 利用剧本功能简单完成服务一键化部署 2) 主机清单配置 3) 剧本的扩展配置功能 4) 多个剧本如何进行整合 5) 剧本的角色目录??? 01. 知识回顾 1) 将所有模块进行了讲解说明 command 模块: 在远程主机上执行命令操作 默认模块 shell 模块: 在远程主机上执行命令操作 万能模块 PS: 有时剧本不能反复执行!!! script 模块: 批量执行本地脚本 copy 模块: 用于批量分发传输数据信息 fetch

linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、target介绍

linux任务计划cron [[email protected] ~]# crontab -e no crontab for root - using an empty one 每天的凌晨3点 执行这个 0 3 * * * /usr/bin/touch /root/123.txt &>/dev/null 启动服务 [[email protected] ~]# systemctl start crond 基本格式 : * * * * * command 分 时 日 月 周 命令 第1列表示分钟

linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和targe

一. linux任务计划cron 关于cron任务计划功能的操作都是通过crontab这个命令来完成的. 其中常用的选项有: -u :指定某个用户,不加-u选项则为当前用户: /etc/crontab 任务计划的配置文件 前面两行是定义变量,第三行是指发送邮件给谁,然后最后一行有五个点分别对应着五个位,也就是上面的五行,分别表示:1.表示分钟(0-59)2.表示小时(0-23)3.表示日期(1-31)4.表示月份(1-12可以写数字或者英文的简写)5.表示星期(0-6,0或者7表示周日,也可以写

十(6)任务计划 cron、chkconfig工具、systemd管理服务、unit、target

                  Linux 任务计划 cron 任务计划的配置文件: /etc/crontab (图中:MAILTO 表示发送任务计划给谁) crontab: -u:表示指定某个用户,不加-u则为当前用户 -e :表示制定计划任务(进入到编辑模式) -l :列出计划任务 -r: 删除计划任务 进入编辑模式 : crontab -e (编写任务计划crond服务是如果执行一个bash/命令,写它的绝对路径) 指定执行范围:   ( 分范围0-59,时范围0-23,日范围1-31