cron-chkconfig-systemd-unit-target

任务计划cron

/etc/crontab          #任务计划配置文件bash

格式: 分(0-59) 时(0-23) 日(1-31) 月(1-12) 周(0-6or1-7) 用户 命令            ssh

/var/spool/cron/[username]                       #各个用户配置的任务历史 socket

配置定时任务

使用crontab命令,经常使用参数:-u指定用户 -e编辑  -l查看 -r删除spa

例子:rest

crontab -eblog

0 3 * * * /bin/bash /root/1.sh                               #天天凌晨3点整执行 /root/1.sh 。“*”表示全部进程

0 3 1-10 * *  /bin/bash /root/1.sh                         #每个月1至10号凌晨3点整执行 /root/1.sh。crontab

0 3 1-10 */2 *  /bin/bash /root/1.sh                      #每隔两个月的1至10号凌晨3点整执行 /root/1.shci

0 3 * * 3,5  /bin/bash /root/1.sh                            #每周三和周五的凌晨3点整执行 /root/1.shget

 

启动定时服务

systemctl start crond 

 

系统服务管理chkconfig

chkconfig --list                                                   #列出全部sysV的服务

chkconfig --level 3 network off                           #network服务在3启动项下不开机自启动

chkconfig --level 345 network on                        #network服务在345启动项下开机自启动

chkconfig --add XXXX                                         #添加自定义XXXX服务到sysV里面

chkconfig --del network                                      #删除服务

 

/etc/init.d/                              #SysV的服务的启动脚本存放路径

 

系统服务管理systemd

systemctl list-unit-files                                                       #查看systemd服务(systemctl list-units --all --type=service详细显示)

systemctl xxx  服务名                                                          # xxx:enable开机启动,disable开机不启动,start如今开启,stop如今关闭,status如今状态,restart重启,is-enabled检查时候开机启动

 

unit:

/usr/lib/systemd/system                                                     #目录下为全部unit(包含:service系统服务,target多个unit组成,device硬件设备,mount文件系统挂载点,automount自动挂载点,path文件或路径,scope不是由systemd启动的外部进程,slice进程组,snapshot systemd快照,socket进程间通讯套接字,swap swap文件,timer定时器)

systemctl list-units                                                               #显示正在运行的unit,添加参数:--all显示全部,--all --state=inactive列出激活的unit,--type=service(列出active的service)

 

target

系统使用target来方便管理unit

systemctl list-unit-files --type=target                                     #列出全部target,systemctl list-dependencies xxx.target.查看xxx.target下面有哪些unit,systemctl get-default查看系统默认target,systemctl set-default xxx.target设置xxx为默认target

 

 

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

/usr/lib/systemd/system/sshd.service                                   #文件查看sshd服务属于哪一个target,文件中[Install]部分

本站公众号
   欢迎关注本站公众号,获取更多信息