cron-chkconfig-systemd-unit-target

时间秒杀一切 提交于 2019-12-04 07:37:56

任务计划cron

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

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

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

配置定时任务

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

例子:

crontab -e

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。

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

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

 

启动定时服务

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]部分

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!