10.23 linux任务计划cron 10.24 chkconfig工具 10.25 systemd管理服务 10.26 unit介绍 10.27 target介绍

10.23 linux任务计划cron

cat /etc/crontab 任务计划的配置文件 , 在哪一个用户下面,默认就是哪一个用户linux

crontabvim

-u 指定一个用户 如 -u rootcentos

-e 进入到配置文件中编辑, 和vim同样 ,在哪一个用户下面,默认就是哪一个用户bash

-l 查看已有的任务计划socket

-r 删除工具

格式:分 时 日 月 星期(周) user(不写就是root) commandcentos7

分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7rest

可用格式1-5表示一个范围1到5进程

可用格式1,2,3表示1或者2或者3crontab

可用格式*/2表示被2整除的数字,好比小时,那就是每隔2小时

0 3 * * * /bin/bash /usr/local/sbin/123.sh >> /tmp/123.log 2>> /tmp/123.log 天天的3点执行 , 并重定向正确和错误的到123文件

0 3 1-10 */2 2,5 1-10号 的 周2和周5 每2个月 的3点

1 10 * 2 * /usr/bin/find /tmp -type -f -mtime +100 | xargs rm -f 2月份, 天天10点01分 删除tmp目录下大于建立时间100天的普通文件

文件/var/spool/cron/用户名 查看每一个用户的cron

要保证服务是启动状态

systemctl start crond.service

ps aux | grep cron 或 systemctl status crond.service 查看

任务计划不执行 , 有多是写的时候 命令没有使用绝对路径, 没找到命令

写任务计划最好 要用 重定向到文件, 方便查看任务计划是否执行成功

10.24 chkconfig工具

chkconfig --list 服务在 /etc/init.d/下

chkconfig --level 3 network off

chkconfig --level 345 network off

chkconfig --del network

chkconfig --add network

centos7 已经没有用户级别的概念, centos6 可编辑 /etc/inittab 编辑系统用户级别

用户级别:

0 关机 1 单用户模式 3 多用户模式不带图形 2只比3少了nfs服务 4 保留级别 5 多用户带图形 6 重启

10.25 systemd管理服务

systemctl list-units --all --type=service 不加--all则不会列出inactive的服务

几个经常使用的服务相关的命令

systemctl enable crond.service //让服务开机启动 .service能够省略 / enable 会建立1个软连接, disable则会取消软连接

systemctl disable crond //不让开机启动

systemctl status crond //查看状态

systemctl stop crond //中止服务

systemctl start crond //启动服务

systemctl restart crond //重启服务

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

10.26 unit介绍

ls /usr/lib/systemd/system //系统全部unit,分为如下类型

service 系统服务

target 多个unit组成的组

device 硬件设备

mount 文件系统挂载点

automount 自动挂载点

path 文件或路径

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

slice 进程组

snapshot systemd快照

socket 进程间通讯套接字

swap swap文件

timer 定时器

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

10.27 target介绍

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

systemctl list-unit-files --type=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

相关文章
相关标签/搜索