10.23 linux任务计划cron
cat /etc/crontab 任务计划配置文件
里面包含环境变量,命令路径,发送邮件给谁
下面是格式:分 时 日 月 周 user command
分(minute)范围0-59,时(hour)范围0-23,日(day)范围0-31,月(month)范围0-12,周(day of week)1-6(0或7都是周日).
user用户默认是root command需要执行的命令
crontab –e进入到crontab配置文件中
每天凌晨3点去执行某个脚本,把正确错误输出分别追加到123.log中 (*表示所有)
可用格式1-5表示一个范围1到5
可用格式1,2,3表示1或者2或者3
可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时(或者月份,2,4,6,8,10,12)
systemctl start crond.service 启动cron服务启动(要保证服务是启动状态)
ps aux |grep cron 检查服务是否启动
systemctl status crond 也可以启动服务(显示为绿色就ok)
systemctl stop crond 停掉服务
crontab –u(指定用户) –e(编辑) –l(列出) –r(删除)
crontab –l 查看cron任务计划的信息
/var/spool/cron/username crontab文件路径(username就是用户名)
10.24 chkconfig
Linux系统服务管理-chkconfig(centos7之前用的服务管理,过渡用)
chkconfig --list
ls /etc/init.d 服务脚本在这个里面
0:关机状态 1:单用户 2:比3少了个nffs服务 3:多用户模式(不带图形)4:保留级别(暂时没用) 5:多用户带图像 6:重启
chkconfig network off network全部关闭
chkconfig --level 3 network off network3级别关闭
chkconfig --level 345 network off network3,4,5,级别关闭(on开启)
chkconfig --del network 删除一个脚本
chkconfig --add 123 添加一个脚本
脚本中圈起来的这两部分必须有才能被识别。
10.24 systemd管理服务
Linux系统服务管理-systemd (centos7服务管理)
systemctl list-units –all --type=service 列出service
几个常用的服务相关的命令
systemctl enable crond.service 让服务开机启动
systemctl disable crond 不让开机启动
systemctl status crond 查看状态
systemctl stop crond 停止服务
systemctl start crond 启动服务
systemctl restart crond 重启服务
systemctl is-enabled crond 检查服务是否开机启动
10.26 unit介绍
Linux系统服务管理-sytemd
ls /usr/lib/systemd/system 系统所有unit,分为以下类型
service 系统服务
target 多个unit组成的组
device 硬件设备
mount 文件系统挂载点
automount 自动挂载点
path 文件和路径
scope 不是由systemd启动的外部进程
slice 进程组
snapshot system 快照
socket 进程间通信套接字
swap swap文件
timer 定时器
target的七个级别跟centos6的7个级差不多
Unit相关的命令
systemctl list-units 列出正在运行的unit
systemctl list-units --all 列出所有,包括失败的或者inactive的
systemtcl list-units --all --state=inactive 列出inactive的unit
systemctl list-units –type=service列出状态为active的service
systemctl is-active crond.service 查看某个服务是否为active
systemctl is-enabled crond.service 查看是否enabled
10.27 target介绍
系统为了方便管理用target来管理unit
systemctl list-unit-files –type=target 列出所有target
systemctl list-dependencies multi-user.target 查看指定target下面有哪些unit
systemctl get-default 查看系统默认的target(multi-user.target)
systemctl set-default multi-user.target 设置默认target,会创建个软连接
一个service属于一种类型的unit
多个unit组成了一个target
一个target里面包含了多个service
cat /usr/lib/systemd/system/sshd.service 看install部分