cron工具用来制定任务计划,大部分系统管理工做都是经过按期自动执行某个脚原本完成,如何制定就靠cron工具linux
经过如下命令查看计划任务的配置文件,了解计划文件的内容编写格式ide
[root@ask-02 ~]# cat /etc/crontab工具
模拟编写一个任务计划使用crontab -e命令来操做oop
[root@ask-02 ~]# crontab -e
no crontab for root - using an empty one命令行0 3 /2 6 /usr/bin/echo "hello world" > /root/cs.log //字符串分别意思是(从左往右):分、时、日、月、周和命令行rest
编写好后保存并退出,执行如下命令开启该任务计划blog
[root@ask-02 ~]# systemctl start crondcrontab
使用如下命令查看查看执行状态ci
[root@ask-02 ~]# systemctl status crond资源
使用如下命令中止任务计划
[root@ask-02 ~]# systemctl stop crond
在Centos 6上的服务管理工具为chkconfig工具,Linux系统全部预设的服务都已能够经过/etc/init.d/目录获得
[root@ask-02 ~]# ls /etc/init.d/
functions netconsole network README
只有屈指可数的几个文件是由于Centos 7已经再也不延续Centos 6版本的服务管理方案,可是咱们依然能够继续使用chkconfig这个命令。
使用命令chkconfig --list 列出全部的服务及其每一个级别的开启状态
[root@ask-02 ~]# chkconfig --list
图中咱们能够看到执行命令后系统所提示的内容,说明内容并无包含Centos 7原生的systemd服务,而仅仅列出了SysV服务,也就是说Centos 7以前的版本采用的服务都是SysV。
这里的级别(数字0-6)为系统启动级别(如今的Centos 7已经再也不严格区分级别的概念),运行级别0、1和6倍系统保留。其中0做为shutdown动做,1做为重启至单用户模式,6为重启。通常都是用2、3、4、5级别,2表示无NFS支持的多用户模式,3表示彻底多用户模式(也是最经常使用的级别),4保留给用户自定义,5表示图形登陆方式
更改某级别下的开启状态
[root@ask-02 ~]# chkconfig --level 3 network off
[root@ask-02 ~]# chkconfig --list |grep network
network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
这里--level指定级别,后面跟服务名,而后是设定开关(off关on开),还能够指定多个级别
[root@ask-02 ~]# chkconfig --level 245 network off
[root@ask-02 ~]# chkconfig --list |grep network
network 0:关 1:关 2:关 3:关 4:关 5:关 6:关
还能够省略掉级别,但默认是针对2、3、4、5级别来操做的
[root@ask-02 ~]# chkconfig network on
[root@ask-02 ~]# chkconfig --list |grep network
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
chkconfig还有如下功能
[root@ask-02 ~]# chkconfig --del network //移除指定的服务
[root@ask-02 ~]# chkconfig --add network //添加指定的服务
使用systemd如下命令列出系统全部的服务
[root@ask-02 ~]# systemctl list-units --all --type=service
关于systemd经常使用的相关命令
[root@ask-02 ~]# systemctl enable crond.service //让某个服务开启(.service能够省略)
[root@ask-02 ~]# systemctl disable crond //不让开机启动
[root@ask-02 ~]# systemctl status crond //查看服务状态
[root@ask-02 ~]# systemctl start crond //启动某个服务
[root@ask-02 ~]# systemctl stop crond //中止某个服务
[root@ask-02 ~]# systemctl restart crond //重启某个服务
[root@ask-02 ~]# systemctl is-enable crond //查看某个服务是否开机启动
使用如下命令查看启动脚本文件
[root@ask-02 ~]# ls /usr/lib/systemd/system/
abrt-ccpp.service quotaon.service
abrtd.service rc-local.service
abrt-oops.service rdisc.service
abrt-pstoreoops.service reboot.target
abrt-vmcore.service reboot.target.wants
这个路径下有不少文件,这里简单列出一小部分,这些文件有多种类型,不一样类型的文件都为一个unit,正式这些unit组成了系统的各个资源。unit能够归类为如下几种
unit相关的命令
[root@ask-02 ~]# systemctl list-units //列出正在运行(active)的unit
[root@ask-02 ~]# systemctl list-units --all //列出全部的unit(包括失败的、inactive的)
[root@ask-02 ~]# systemctl list-units --all --state=inactive //列出全部inactive的unit
[root@ask-02 ~]# systemctl list-units --all --type=service //列出全部状态的service
[root@ask-02 ~]# systemctl list-units --type=service //列出状态的active的service
[root@ask-02 ~]# systemctl is-active crond.service //查看某个unit是否active
target实际上是多个unit的组合,为了管理方便,就是用target来管理这些unit。
查看当前系统全部的target;
[root@ask-02 ~]# systemctl list-unit-files --type=target
查看一个target包含的全部unit
[root@ask-02 ~]# systemctl list-dependencies multi-user.target
关于target相关的命令
[root@ask-02 ~]# systemctl get-default //查看系统默认的targetmulti-user.target[root@ask-02 ~]# systemctl set-default multi-user.target //设置默认的target