一、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