Cron,Chkconfig,Systemd,Target
2017-08-04 00:00
78 查看
Cron :
# cat /etc/crontab //查看设置任务计划的(配置文件)格式#crontab -e //自定义计划内容
0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/1.txt 2>>/tmp/2.txt
详解:每天的3点执行/usr/local/sbin/ 23.sh 此命令,并且把正确的日志输出到1.txt;错误的信息输出到2.txt
0 3 1-10 */2 2,5 /usr/bin/find /tmp/ -type f -mtime +100 | xargs rm -f >>/tmp/1.txt 2>>/tmp/2.txt
详解:每天的3点;1-10号;双数月份(2,4,6,8……);周二和周五去执行此命令。找到tmp下修改文件超过100天,然后删除。
# systemctl start crond //启动cron服务
# ps aux | grep cron //检查是否启动
# crontab -l //查看任务计划
# systemctl status crond.service //查看服务状态
计划任务,一定要写绝对路径,如果仅仅是添加一个命令是不执行的。
# cat /var/spool/cron/root //查看指定用户的任务计划
# crontab -r //移除任务计划
Chkconfig :(centos 7 不会再使用了)
# chkconfig 系统服务管理由于centos7 已经选择不再使用chkconfig了,但是为了配合老版本的使用还没有移出此服务(后期的发展趋势也就是放弃此命令了)。
# chkconfig --list //查看使用此服务的list
# ls /etc/init.d //各个服务的具体位置
# chkconfig network off //关闭network 这个服务
# chkconfig network off //打开network这个服务
# chkconfig --level 3 network off //自定义network的3状态为关闭
# chkconfig --level 35 network off
Linux下的7个运行级别:
0 系统停机状态,系统默认运行级别不能设置为0,否则不能正常启动,机器关闭。1 单用户工作状态,root权限,用于系统维护,禁止远程登陆,就像Windows下的安全模式登录。
2 多用户状态,没有NFS支持。
3 完整的多用户模式,有NFS,登陆后进入控制台命令行模式。
4 系统未使用,保留一般不用,在一些特殊情况下可以用它来做一些事情。例如在笔记本电脑的电池用尽时,可以切换到这个模式来做一些设置。
5 X11控制台,登陆后进入图形GUI模式,X Window系统。
6 系统正常关闭并重启,默认运行级别不能设为6,否则不能正常启动。运行init 6机器就会重启。
在centOS 6及之前的版本,都可以使用此命令来编辑启动的选项 # vim /etc/inittab
systemd管理服务 :(重心在于此)
当我们输入:[root@zhdy-01 ~]# chkconfig --list 注意:该输出结果只显示 SysV 服务,并不包含原生 systemd 服务。SysV 配置数据可能被原生 systemd 配置覆盖。 如果您想列出 systemd 服务,请执行 'systemctl list-unit-files'。 欲查看对特定 target 启用的服务请执行 'systemctl list-dependencies [target]'。
# systemctl list-unit-files //查看所有的服务
包含了很多内容(service,target,socket,timer等)
# systemctl list-units --all --type=service //只查看系统服务类型为services的服务,同理去查看其它类型的服务情况。
几个常用的服务相关的命令:
# systemctl enable crond.service //让服务开机启动
# systemctl disable crond //不让开机启动
# systemctl status crond //查看状态
# systemctl stop crond //停止服务
# systemctl start crond //启动服务
# systemctl restart crond //重启服务
# systemctl is-enabled crond //检查服务是否开机启动
查看一个服务的enable和disable;其实就是创建了软链接
/usr/lib/systemd/system/crond.service
# ls /usr/lib/systemd/system //系统所有unit,分为以下类型
service 系统服务 target 多个unit组成的组 device 硬件设备 mount 文件系统挂载点 automount 自动挂载点 path 文件或路径 scope 不是由systemd启动的外部进程 slice 进程组 snapshot systemd快照 socket 进程间通信套接字 swap swap文件 timer 定时器
# cd /usr/lib/systemd/system //进入目录
[root@zhdy-01 system]# ls -l runlevel* lrwxrwxrwx. 1 root root 15 5月 31 18:53 runlevel0.target -> poweroff.target lrwxrwxrwx. 1 root root 13 5月 31 18:53 runlevel1.target -> rescue.target lrwxrwxrwx. 1 root root 17 5月 31 18:53 runlevel2.target -> multi-user.target lrwxrwxrwx. 1 root root 17 5月 31 18:53 runlevel3.target -> multi-user.target lrwxrwxrwx. 1 root root 17 5月 31 18:53 runlevel4.target -> multi-user.target lrwxrwxrwx. 1 root root 16 5月 31 18:53 runlevel5.target -> graphical.target lrwxrwxrwx. 1 root root 13 5月 31 18:53 runlevel6.target -> reboot.target
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
# systemct is-active crond.service //查看某个服务是否为active
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
# cat /usr/lib/systemd/system/sshd.service //看[install]部分
相关文章推荐
- 12.4 linux任务计划cron chkconfig工具 systemd管理服务 unit介绍 target介绍
- 2018-1-29 8周1次课 cron,chkconfig,systemd,unit,target
- linux任务计划cron、 chkconfig工具、systemd管理服务、unit与target
- linux任务计划cron 、chkconfig工具 、systemd管理服务、 unit介绍、 target介绍
- 八周第一次课 2017.12.4 linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、target介绍
- cron、chkconfig、systemd、unit、target
- cron,chkconfig,systemd,unit,target介绍
- 笔记9(日常运维2iptables nat表、zone、service、cron、chkconfig、systemd、unit、target、rsyncscreen)
- 10.23 linux任务计划cron10.24chkconfig工具10.25 systemd管理服务10.26 unit介绍 10.27 target介绍
- linux的cron、chkconfig工具、systemd管理服务、unit、target介绍
- 10.23 linux任务计划cron 10.24 chkconfig工具 10.25 systemd管理服务 10.26 unit介绍 10.27 target介绍
- linux任务计划cron,chkconfig工具,systemd管理,unit,target介绍
- 计划任务cron,chkconfig工具,systemd管理服务,unit,target
- linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍和target介绍讲解
- cron计划任务、chkconfig工具、systemd管理服务、unit、target介绍
- linux学习第三十二篇:linux任务计划cron,chkconfig工具,systemd管理服务,unit介绍,target介绍
- Linux任务计划cron,chkconfig工具,systemd管理服务,unit介绍,target介绍
- linux任务计划cron、chkconfig工具、systemd管理服务、unit介绍、target介绍
- 2018-1-29 8周1次课 cron,chkconfig,systemd,unit,target
- Linux系统管理-crond、chkconfig、systemd、unit、target