10.23 linux任务计划cronhtml
10.24 chkconfig工具linux
10.25 systemd管理服务vim
10.26 unit介绍windows
10.27 target介绍centos
扩展ssh
crontab命令被用来提交和管理用户的须要周期性执行的任务,与windows下的计划任务相似,当安装完成操做系统后,默认会安装此服务工具,而且会自动启动crond进程,crond进程每分钟会按期检查是否有要执行的任务,若是有要执行的任务,则自动执行该任务。socket
systemctl start crond systemctl status crond systemctl stop crond //分别是开启、查看、中止crond服务
crontab命令 | 命令效果 | 命令含义 |
---|---|---|
crontab -e | vim /var/spool/cron/root | 编辑计划 |
crontab -l | cat /var/spool/cron/root | 查看计划 |
crontab -r | rm /var/spool/cron/root | 删除计划 |
crontab -ue user1 | vim vim /var/spool/cron/user1 | user1计划 |
[root@axiang ~]# crontab -e //设置任务计划 [root@axiang ~]# systemctl start crond [root@axiang ~]# ps aux | grep cron root 527 0.0 0.1 126220 1612 ? Ss 20:18 0:00 /usr/sbin/crond -n root 2593 0.0 0.0 112664 972 pts/0 S+ 21:51 0:00 grep --color=auto cron [root@axiang ~]# systemctl status crond //查看状态以下图
[root@axiang ~]# crontab -l //查看当前设置 1 10 * 2 * /usr/bin/find /tmp/ -type f -mtime +100 |xargs rm -f [root@axiang ~]# cat /var/spool/cron/root //若是想备份、从这里复制 1 10 * 2 * /usr/bin/find /tmp/ -type f -mtime +100 |xargs rm -f [root@axiang ~]# crontab -r //删除 [root@axiang ~]# crontab -l no crontab for root [root@axiang ~]# crontab -u root -l //制定用户
crontab -e //编写任务,进入相似vim的页面写任务计划
时间可选描述方式:工具
小实验: 注意:命令尽可能使用绝对路径,建议追加执行日志“>>/tmp/rigth.log 2>>/tmp/wrong.log”centos7
chkconfig命令检查、设置系统的各类服务。这是Red Hat公司遵循GPL规则所开发的程序,它可查询操做系统在每个执行等级中会执行哪些系统服务,其中包括各种常驻服务。谨记chkconfig不是当即自动禁止或激活一个服务,它只是简单的改变了符号链接(该命令多用于centos6及之前版本)。操作系统
常见参数
示例:
chkconfig --list 查看当前系统服务状态
ls /etc/init.d/ 查看现有服务 chkconfig --level 345 network off/on 开启某一级别的服务
运行级别配置文件:“/etc/inittab”,centos7已再也不使用该文件。
ls /etc/init.d/ 123 functions netconsole network README 添加/删除: chkconfig --add /etc/init.d/123 chkconfig --list 123 0:关 1:关 2:开 3:开 4:开 5:开 6:关 netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关 network 0:关 1:关 2:开 3:开 4:开 5:开 6:关 chkconfig --del /etc/init.d/123
systemctl命令是系统服务管理器指令,它实际上将 service 和 chkconfig 这两个命令组合到一块儿。
任务 | 旧指令 | 新指令 |
---|---|---|
使某服务开机启动 | chkconfig --level 3 httpd on | systemctl enable httpd.service |
使某服务开机不启动 | chkconfig --level 3 httpd off | systemctl disable httpd.service |
检查服务状态 | service httpd status | systemctl status httpd.service(服务详细信息),systemctl is-active httpd.service(仅显示状态为Active的服务信息) |
显示全部已启动的服务 | chkconfig --list | systemctl list-units (--all)--type=service(--all同时显示inactive状态的服务) |
启动某服务 | service httpd start | systemctl start httpd.service |
中止某服务 | service httpd stop | systemctl stop httpd.service |
重启某服务 | service httpd restart | systemctl restart httpd.service |
检测某服务是否开机启动 | 无 | systemctl is-enabled httpd.service |
systemctl enable crond systemctl disable crond ls /etc/systemd/system/
unit所在目录:/usr/lib/systemd/system/
unit文件类型
后缀 | 类型 |
---|---|
service | 系统服务 |
target | 多个unit组成的组 |
device | 硬件设备 |
mount | 文件系统挂载点 |
autoamount | 自动挂载点 |
path | 文件或路径 |
scope | 非systemd启动的外部程序 |
snapshot | systemd快照 |
socket | 进程间通讯套接字 |
swap | swap文件 |
timer | 定时器 |
命令 | 任务 |
---|---|
systemctl list-units | 列出正在运行的unit |
systemctl list-units --all | 列出全部unit(包括非运行状态的或启动失败的) |
systemctl list-units --all --status=inactive | 列出inactive状态的unit |
systemctl list-units --type=service | 列出状态为active的service |
systemctl is-active/enabled crond | 查看某服务是否为active/enabled状态 |
系统为了方便管理,因此使用target来管理unit。
任务 | 命令 |
---|---|
查看全部target文件 | systemctl list-unit-files --type=target |
查看指定target下面有哪些unit | systemctl list-dependencies multi-user.target |
查看系统默认target | systemctl get-default |
设置系统默认target | systemctl set-default multi-user.target |
一个service属于一种类型的unit,多个unit组成一个target,一个target包含多个service。
cat /usr/lib/systemd/system/sshd.service //查看service属于那个target