八周一次课(5月11日)

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

10.23 crontab命令

crontab:任务计划 在约定时间里执行命令或者脚本

crontab的配置文件在/etc/crontab

[root@kun0769 ~]# vim /etc/crontab

 

可以发型crontab命令的格式是 分 时 日 月 周 用户名(默认是系统登录的用户) 执行的命令(命令最好写绝对路径)

可以使用1-5表示范围1到5

可以使用1,2,3表示1和2和3

可以使用*/2表示能被2整除的数 比如小时 就是每隔2小时 月就是双号的月份

-e:编辑任务计划内容

[root@kun0769 ~]# crontab -e

在双月份的1到10号中的星期二和星期四的凌晨3点来执行123.sh并把执行成功和错误的结果追加到123.txt里

 

systemctl start crond:开启任务计划的服务

[root@kun0769 ~]# systemctl start crond

可以使用ps aux |grep crond 或者 systemctl status crond 来查看是否开启任务计划服务

-l:列出所有的任务计划

[root@kun0769 ~]# crontab -l

0 3 1-10 */2 2,4 /bin/bash /usr/loacl/sbin/123.sh >>/tmp/123.txt 2>>/tmp.txt

 

-r:删除所有的任务计划

[root@kun0769 ~]# crontab -e

 

-u:指定用户

[root@kun0769 ~]# crontab -u root -l   ##查看root用户的任务计划

0 3 1-10 */2 2,4 /bin/bash /usr/loacl/sbin/123.sh >>/tmp/123.txt 2>>/tmp.txt

 

任务计划的编辑的内容都是存放在/vat/spool/cron/用户名 文件中 备份就直接cp这个目录即可

 

10.24/10.2510.26/10.27 服务管理

由于CentOS7默认使用了systemd命令来管理服务 而chkconfig命令只管理小部分的服务了 chkconfig的服务都是在/etc/init.d/目录下

chkconfig:服务管理命令

chkconfig --list:列出所有服务的列表

每行服务都有6个状态 0关机 1单用户模式 2多用户模式(少NFS) 3多用户模式 4保留 5多用户模式(图形)6重启

 

chkconfig 服务 on/off:启动/关闭服务

[root@kun0769 ~]# chkconfig network off  ##关闭network服务

 

chkconfig --level 序号 服务 on/off:在某模式下启动/关闭服务

[root@kun0769 ~]# chkconfig --level 35 network on  ##在3和5模式下开启network服务

 

chkconfig --add 服务:添加服务到列表中 服务必须在/etc/init.d/中

[root@kun0769 ~]# chkconfig --add netconsole  添加netconsole服务到列表中

 

chkconfig --del 服务:删除服务列表中的服务

[root@kun0769 ~]# chkconfig --del netconsole  ##从列表中删除netconsole服务

 

systemctl list-units --all --type=service:列出系统所有服务

[root@kun0769 ~]# systemctl list-units --all --type=service

 

systemctl enable 服务:允许服务开机启动

[root@kun0769 ~]# systemctl enable crond

 

sytemctl disable 服务:禁止服务开机启动

[root@kun0769 ~]# systemctl disable crond

 

systemctl start 服务:开启服务

[root@kun0769 ~]# systemctl start crond

 

systemctl stop 服务:停止服务

[root@kun0769 ~]# systemctl stop crond

 

systemctl restart 服务:重启服务

[root@kun0769 ~]# systemctl restart crond

 

systemctl status 服务:查看服务状态

[root@kun0769 ~]# systemctl status crond

 

systemctl is-enabled 服务:服务是否开机启动

[root@kun0769 ~]# systemctl is-enabled crond

enabled

 

/usr/lib/systemd/systemm/目录下,存放了所有的units,units是systemd下的单位 在此目录每个文件都是一个units 他包含多个类型 

service是系统服务 

target是多个units的组合  

device 是硬件设备 

mount 是文件系统挂载点 

automount是 自动挂载 

path是 文件或路径 

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

slice 是进程组snapshot 是systemd快照 

socket 是进程间通信套接字 

swap是swap文件 

timer是定时器

systemctl list-units:列出系统正在允许的units

[root@kun0769 ~]# systemctl list-units

 

systemctl list-units --all:列出系统所有的units

[root@kun0769 ~]# systemctl list-units --all

 

systemctl list-units --all --state=inactive:列出所有是inactive状态的units

[root@kun0769 ~]# systemctl list-units --all --state=inactive

 

systemctl list-units --type=service:列出所有运行的服务

[root@kun0769 ~]# systemctl list-units --type=service

 

systemctl is-active 服务:查看服务是否运行

[root@kun0769 ~]# systemctl is-active crond

active

 

syttemctl list-unit-files --type=target:列出系统所有target类型的units文件

[root@kun0769 ~]# systemctl list-unit-files --type=target

 

systemctl list-dependencies target名:查看指定target由什么units组成的

[root@kun0769 ~]# systemctl list-dependencies basic.target

 

其中也可以去/usr/lib/systemd/system/服务 的[install]部门来查看此服务是属于哪个target的

 

systemctl get-default:查看系统默认的target

[root@kun0769 ~]# systemctl get-default

multi-user.target

 

systemctl set-default target名:设置系统默认的target

[root@kun0769 ~]# systemctl set-default multi-user.target

 

 

总结

units有多个类型 其中service target是其中一种类型 而多个units组成了target 所有单个target里面可以有若干个service

 

转载于:https://my.oschina.net/u/3803568/blog/1811158

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值