7.17

1、linux任务计划cron

  cat /etc/crontab          查看任务计划的配置文件

  crontab -e            进入crontab的配置文件中,按“i”进入编辑模式

  每天三点指定脚本123.sh,并将正确输出和错误输出分别记录到相应的日志文件中

  偶数月1到10号中的周二和周五的三点指定脚本123.sh,并将正确输出和错误输出分别记录到相应的日志文件中

  systemctl start crond    启动服务

  ps aux |grep crond      查看服务是否启动,如果有crond表示服务启动

  systemctl status crond    查看crond的服务状态,如果显示为绿色,表示服务正常启动

  将服务停止以后,服务状态无颜色,显示为dead

  如果任务计划中的脚本使用的是命令,而未使用绝对路径,则任务计划很有可能不执行,可以通过将脚本中的命令改为绝对路径来解决,也可以通过将命令的路径假如到配置文件中的PATH中来解决

  建议每写一个任务几乎,都将正确和错误日志保留下来

  cron对应的配置文件在/var/spool/crom/目录下,每个用户都有自己的配置文件,如root用的配置文件为/var/spool/crom/root

 

  备份时,可以直接将目录拷贝到备份的指定文件夹下即可

  crontab -r      删除任务计划

  crontab -u root -l   查看指定用户的任务计划

2、chkconfig工具

  系统服务管理工具,chkconfig在centos6及之前版本使用,centos6之前服务管理采用的sysV方式,centos7采用的systemd方式

  chkconfig --list          查看系统中使用chkconfig的服务

  以上两个启动服务的脚本在/etc/init.d/目录下:

  chkconfig network off/on   配置0-6基本的开关状态

  0:关机状态

  1:单用户模式

  2:多用户模式-无图形,无NFS服务

  3:多用户模式-无图形 

  4:保留级别,未使用

  5:图形化多用户

  6:重启

  chkconfig --level 3 network off    关闭指定级别

  chkconfig --level 35 network off  关闭network的3和5级别

  将network启动脚本复制为123, cp /etc/init.d/network  /etc/init.d/123

  此时执行chkconfig查看服务,是没有123服务的

  执行chkconfig --add 123      将123添加到服务列表

  执行chkconfig --del 123      将123从服务列表删除

3、systemd管理服务

  systemctl list-unit-file      查看所有的systemd服务,不只包含services,还会包括socket

  systemctl --list-untis --all --type=services  查看所有services

  如果去掉--all选项,执行systemctl --list-untis --type=services,则只会查看所有active状态的services

  systemctl enable crond.service      让服务开机启动

  systemctl disable crond          不让服务开机启动

  systemctl status crond           查看服务状态

  systemctl stop crond           停止服务

  systemctl start crond           启动服务

  systemctl restart crond           重启服务

  systemctl is-enabled crond        查看服务是否开机启动

4、unit介绍

  ls /usr/lib/systemd/sys      查看系统所有的unit,分为以下类型

    service:系统服务

    target:多个unit组成的组 

    device:硬件设备

    mount:文件系统挂载点

    automoun:自动挂载点

    path:文件或路径

    scope:不是由systemd启动的外部进程

    slice:进程组

    snapshot: systemd快照

    socket:进程间通信套接字

    swap:swap文件

    timer:定时器

  systemctl list-units      列出正在运行的unit

  systemctl list-units -all      列出所有的unit,包括失败或者inactive的

  systemctl list-units --all --status=inactive    列出所有inactive状态的unit

  systemctl list-unit --type=service    列出状态为active的service

  systemctl is-active crond.service      查看某个服务是否为active

5、target介绍

  系统为了方便管理,使用target来unit

  systemctl list-unit-file --type=target    查看系统中所有的target

  systemctl list-dependencies multi-user.target    查看指定target下面有哪些unit,target下面还可以有target

   systemctl get-default    查看系统默认的target 

  systemctl set-default multi-user.target    设置默认的target

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

  cat /usr/lib/systemd/system/ssh.service    可以查看一个服务属于哪个target

 

猜你喜欢

转载自www.cnblogs.com/w494129131/p/9315195.html
今日推荐