linux任务计划 chkconfig工具 systemd管理服务 unit介绍 target介绍
linux任务计划
任务计划:特定时间备份数据,重启服务,shell脚本,单独的命令等等。
任务计划配置文件:cat /etc/crontab
[root@centos7 ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
shell脚本,PATH环境变量,MAILTO发送邮件给谁
时间5个位置格式依次:
分钟,小时,几号,月份,星期;
user-name command to be executed
用户(root可以省略) 最后是需要执行的命令。
crontab -e 需要执行的任务计划。
每天凌晨3点执行的脚本
0 3 * * * /bin/bash /usr/local/sbin/123.sh >> /tmp/123.log 2>>/tmp/123.log
/usr/local/sbin/123.sh >> /tmp/123.log 正确输出追加
2>>/tmp/123.log 错误输出追加
1到10号的3点 双月能被2整除的月份,星期周2和周5,
0 3 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh>> /tmp/123.log 2>>/tmp/123.log
没有年份:月份几号和星期确定年份的唯一性。
启动服务:
systemctl start crond
查看是否启动:
ps aux |grep cron
或者:
systemctl status crond
注意:
crontab -e编写脚本的时候:
直接写命令有可能没有在PATH里面定义,或者用绝对路径,例如iptables 可以写成绝对路径/usr/sbin/iptables或者加入到PATH里面;
此外还要添加一个错误日志用来查看执行信息。
crontab -e编辑一个计划任务
删除2月10点1分的大于100天的文件
1 10 * 2 * /usr/bin/find /tmp/ -type f -mtime +100 |xargs rm -f
备份任务计划
crontab任务文件存储在 /var/spool/cron/username
这里面有对于用户的文件root,xiaobo用户等。
直接拷贝这个目录路径文件即可。
总结:
crontab -u 、-e 、-l 、-r
crontab -e编辑一个计划任务
crontab -l 查看当前添加的计划任务
crontab -r 删除当前计划任务
crontab -u 指定一个用户
格式: 分 时 日 月 周 user command
文件 /var/spool/cron/username
分范围0-59,时范围0-23 ,日范围0-31,月范围0-12,周1-6
可用格式1-5表示一个范围1到5
可用格式1,2,3表示1或者2或者3
可用格式*/2表示被2整除的数字,比如小时,那就是每隔2小时要保证服务是启动状态
linux系统服务管理工具chkconfig
用来管理一些服务: network,mysql,httpd等等
Chkconfig --list列出当前的服务
[root@centos7 ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
系统7个运行级别0~6
0级别 关机状态
1级别 单用户
2级别 多用户模式不带图形不带nfs服务
3级别 多用户模式不带图形
4级别 保留
5级别 多用户带图形
6级别 重启状态
服务启动脚本存储在:/etc/init.d/
[root@centos7 ~]# ls /etc/init.d/
functions netconsole network README
关闭服务:systemctl network off
开启服务:systemctl network on
/etc/inittab 不再使用
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
指定3级别关闭
chkconfig --level 3 network off
指定345级别关闭
chkconfig --level 345 network off
cd /etc/init.d/
自定义一个脚本 cp network 123
添加到服务
chkconfig --add 123
删除服务
chkconfig --del 123
systemd管理服务
查看所有的服务
[root@centos7 ~]# systemctl list-unit-files
列出所有的服务service,包括描述信息
systemctl list-units --all --type=service
几个常用的服务相关的命令
systemctl enable cond.service //让服务开机启动
systemctl enable crond (.service可以省略)
systemctl disable crond //不让开启启动
[root@centos7 ~]# systemctl is-enabled crond.service
enabled
[root@centos7 ~]# systemctl disable crond.service
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.
[root@centos7 ~]# systemctl is-enabled crond.service
disabled
[root@centos7 ~]# systemctl enable crond.service
Created symlink from /etc/systemd/system/multi-user.target.wants/crond.service to /usr/lib/systemd/system/crond.service.
Created symlink 创建软连接
生成软连接
[root@centos7 ~]# ls -l /etc/systemd/system/multi-user.target.wants/crond.service
lrwxrwxrwx 1 root root 37 1月 27 12:45 /etc/systemd/system/multi-user.target.wants/crond.service -> /usr/lib/systemd/system/crond.service
disable 会把软连接remove
[root@centos7 ~]# systemctl disable crond.service
Removed symlink /etc/systemd/system/multi-user.target.wants/crond.service.
systemctl status crond //查看状态
systemctl stop crond //停止服务
systemctl start crond //启动服务
systemctl restart crond //重启服务
systemctl is-enableed crond //检查服务是否开机启动
linux系统服务管理-systemd unit介绍
ls /usr/lib/systemd/system //系统所有unit,分为以下类型
service系统服务
tartget 多个unit组成的组
[root@centos7 systemd]# cd /usr/lib/systemd/system
[root@centos7 system]# ls -l runlevel*
7个运行级别 target
lrwxrwxrwx. 1 root root 15 12月 19 05:49 runlevel0.target -> poweroff.target
lrwxrwxrwx. 1 root root 13 12月 19 05:49 runlevel1.target -> rescue.target
lrwxrwxrwx. 1 root root 17 12月 19 05:49 runlevel2.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 12月 19 05:49 runlevel3.target -> multi-user.target
lrwxrwxrwx. 1 root root 17 12月 19 05:49 runlevel4.target -> multi-user.target
lrwxrwxrwx. 1 root root 16 12月 19 05:49 runlevel5.target -> graphical.target
lrwxrwxrwx. 1 root root 13 12月 19 05:49 runlevel6.target -> reboot.target
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-unit --type=service //列出状态为active的service
systemctl is-active crond.service //查看某个服务示范为active]
systemctl is-enable crond.service //查看服务是否开启
target
系统为了方便管理用target来管理unit
一个target 由多个unit组成。
列出系统里面所有的target
systemctl list-unit-files --type=target
systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
大多数是service
systemctl get-default //查看系统默认的target
systemctl set-default multi-user.target //设置默认的多用户target
一个service属于一种类型的unit
多个unit组成了一个target
一个target里面包含了多个service
cat /usr/lib/systemd/system/sshd.service //查看[install]部分
sshd.service 属于multi-user.target
[Install]
WantedBy=multi-user.target
linux任务计划 chkconfig工具 systemd管理服务 unit介绍 target介绍的更多相关文章
- linux任务计划cron、chkconfig工具、systemd管理服务、unit和target介绍
第8周第1次课(5月14日) 课程内容: 10.23 linux任务计划cron10.24 chkconfig工具10.25 systemd管理服务10.26 unit介绍10.27 target介绍 ...
- Linux centos7 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、 target介绍
一.linux任务计划cron crontab -u -e -l -r 格式;分 时 日 月 周 user command 文件/var/spool/corn/username 分范围0-59,时范 ...
- Linux操作系统的文件查找工具locate和find命令常用参数介绍
Linux操作系统的文件查找工具locate和find命令常用参数介绍 作者:尹正杰 版权声明:原创作品,谢绝转载!否则将追究法律责任. 一.非实时查找(数据库查找)locate工具 locate命 ...
- Android窗口管理服务WindowManagerService的简要介绍和学习计划
在前一个系列文章中,我们从个体的角度来分析了Android应用程序窗口的实现框架.事实上,如果我们从整体的角度来看,Android应用程序窗口的 实现要更复杂,因为它们的类型和作用不同,且会相互影响. ...
- systemd管理服务
[root@zbs-staging-api system]# cat /lib/systemd/system/ncmulti@.service [Unit] Description=many on % ...
- Linux编程 16 文件权限(组管理 groupadd, groupmod,文件权限介绍)
一.用户组 前面章节知道用户账户在控制单个用户安全性方面很好,但涉及到共享资源或把用户类型分组时,组概念就出来了. 组权限允许多个用户对系统中的对象(比如文件,目录,设备等)共享一组共用的权限. 在c ...
- linux任务计划cron
linux任务计划cron 1.crontab命令任务计划配置文件 [root@bogon ~]# cat /etc/crontab SHELL=/bin/bash PATH=/sbin:/bin:/ ...
- [CoreOS 转载] CoreOS实践指南(七):Docker容器管理服务
转载:http://www.csdn.net/article/2015-02-11/2823925 摘要:当Docker还名不见经传的时候,CoreOS创始人Alex就预见了这个项目的价值,并将其做为 ...
- Android窗口管理服务WindowManagerService显示窗口动画的原理分析
文章转载至CSDN社区罗升阳的安卓之旅,原文地址:http://blog.csdn.net/luoshengyang/article/details/8611754 在前一文中,我们分析了Activi ...
随机推荐
- 【神经网络】BP反向传播神经网络
BP算法细节 参数说明:假设有n层.J表示代价函数,和上面的E是同样的意思,只不过用不同的字母写而已. 分析:要想知道第l层的第i个结点的残差,必须知道层已经计算出来了残差,你只要把后面一层的每个结点 ...
- sphinx增量索引和主索引来实现索引的实时更新
项目中文章的信息内容因为持续有新增,而文章总量的基数又比较大,所以做搜索的时候,用了主索引+增量索引这种方式来实现索引的实时更新. 实现原理: 1. 新建一张表,记录一下上一次已经创建好索引的最后一条 ...
- Android动画知识汇总
Interpolator(插值器) Interpolatort通常在动画中使用,主要来改变动画变化率.常用的有下面几种Interpolator,下面图文解说下: AccelerateDecelerat ...
- CentOS7安装MySQL5.7常见问题
下载与安装 亲测有效: https://www.linuxidc.com/Linux/2016-09/135288.htm 设置MySQL服务开机自启动 注意,CentOS6和7有一点不同:CentO ...
- <悟道一位IT高管20年的职场心经>笔记
1. 你一定会在某个时候惊讶地发现,原来当初你曾经硬着头皮挨过来的日子对你是那么的珍贵.2. "'老板就是老板'.这一点,你可能会忘,他一定不会忘.'老板不会总是老板'.这一点,他可能会忘, ...
- [ssh]如何设计ARM板上多用户key登录系统
如何设计ARM板上多用户key登录系统
- ASP.NET MVC分页 Ajax+JsRender
前段时间整mvc的分页,倒是很顺利,参考了以下几篇博客,启发很大. http://www.cnblogs.com/tangmingjun/archive/2012/05/30/2526301.html ...
- openCV—Python(5)—— 图像几何变换
一.函数简单介绍 1.warpAffine-图像放射变换(平移.旋转.缩放) 函数原型:warpAffine(src, M, dsize, dst=None, flags=None, borderMo ...
- 【Java集合源码剖析】HashMap源码剖析
转载出处:http://blog.csdn.net/ns_code/article/details/36034955 HashMap简介 HashMap是基于哈希表实现的,每一个元素是一个key-va ...
- css控制固定表头,兼容行列合并
项目中设计的报表table设计的列数相对过多,当拖动下方的滚动条时无法对应表头所对应的列,因此在网上搜索了好一段日子,最后在网上找到了一些参考资料,然后总结归纳出兼容行列合并的固定表头demo. 多浏 ...