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

linux任务计划:

一.  Crontab 介绍

crontab命令的功能是在一定的时间间隔调度一些命令的执行。

二.查看/etc/crontab文件

vi  /etc/crontab

三.文件/etc/crontab中每行任务的描述格式如下:

minute hour day month dayofweek command

  minute - 从0到59的整数 
    hour - 从0到23的整数 
    day - 从1到31的整数 (必须是指定月份的有效日期)
    month - 从1到12的整数 (或如Jan或Feb简写的月份)
    dayofweek - 从0到7的整数,0或7用来描述周日 (或用Sun或Mon简写来表示)
    command - 需要执行的命令(可用as ls /proc >> /tmp/proc或 执行自定义脚本的命令)

    root表示以root用户身份来运行
    run-parts表示后面跟着的是一个文件夹,要执行的是该文件夹下的所有脚本

    对于以上各语句,星号(*)表示所有可用的值。例如*在指代month时表示每月执行(需要符合其他限制条件)该命令。 
    整数间的连字号(-)表示整数列,例如1-4意思是整数1,2,3,4  (范围)

指定数值由逗号分开。如:3,4,6,8表示这四个指定整数。(指定某几个数字)

符号“/”指定步进设置。“/<interger>”表示步进值。如0-59/2定义每两分钟执行一次。步进值也可用星号表示。如*/3用来运行每三个月份运行指定任务。

以“#”开头的为注释行,不会被执行。

4.范围

可用格式1-5表示一个范围1到5
可用格式1,2,3表示1或者2或者3
可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时

crontab -u、-e、-l、-r    编辑需要配置的文件  -l=查询任务计划   -r=删除计划    -u=指定用户     -e=进入编辑模式

5.启动服务

sbin/service crond start //启动服务       =    systemctl start crond 
/sbin/service crond stop //关闭服务      =    systemctl stop crond
/sbin/service crond restart //重启服务   =    systemctl  restart crond
/sbin/service crond reload //重新载入配置

 chkconfig工具:

chkconfig --list    查看系统服务

chkconfig --level 3network off    指定某个服务在开机系统关闭或者开启  off=关闭 on=开启

chkconfig --add 123   把脚本添加到系统服务里面去

首先,把脚本添加到 /etc/init.d/ 目录里面去,然后就可以添加服务了。(被添加的服务必须是一个脚本)

chkconfig --del    删除系统服务

systemd系统服务管理:

systemctl list-units --all --type=service    列出系统所有服务

systemctl enable crond.service //让服务开机启动     crond =服务的名称
systemctl disable crond //不让开机启动
systemctl status crond //查看状态
systemctl stop crond //停止服务
systemctl start crond //启动服务
systemctl restart crond //重启服务
systemctl is-enabled crond //检查服务是否开机启动

unit介绍:

unit相关的命令
 systemctl list-units //列出正在运行的unit
 systemctl list-units --all //列出所有,包括失败的或者inactive的
 systemctl list-units --all --state=inactive //列出inactive的unit    (指定状态)
 systemctl list-units --type=service//列出状态为active的service
 systemctl is-active crond.service //查看某个服务是否为active

target介绍:

系统为了方便管理用target来管理unit
 systemctl list-unit-files --type=target    列出系统下的target
 systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
 systemctl get-default //查看系统默认的target
 systemctl set-default multi-user.target
 一个service属于一种类型的unit
 多个unit组成了一个target
 一个target里面包含了多个service
 cat /usr/lib/systemd/system/sshd.service //看[install]部分

扩展


1. anacron  http://blog.csdn.net/strikers1982/article/details/4787226

2. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装)   http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html

3. systemd自定义启动脚本  http://www.jb51.net/article/100457.htm

猜你喜欢

转载自my.oschina.net/u/3769333/blog/1785327