crontab、chkconfig、systemd、unit、targ
10.23 linux任务计划cron
# cat /etc/crontab
liunx下的任务计划配置文件
- crontab -u、-e、-l、-r
- 格式:分 时 日 月 周 user command
- 分范围0-59,时范围0-23,日范文:1-31,月范围:1-12,星期分为:0-6(sunday=0 or 7)
# crontab -e
进入到任务计划编辑界面
- 0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每一个星期,每一个月的天天的3点执行命令
- 0 3 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每周二周五,双数月份的前10天的3点,执行任务
# sytemctl start crond
启动服务# systemctl stop crond
//关闭服务
# ps aux | grep cron
查看是否有此进程
# systemctl status crond
查看状态,Actice绿色启动该
- 计划在/var/spool/cron/root(最后是以用户名命名的文件)
# cront -l
//列出信息
# cront -e
//编辑
# cront -r
//删除
# cront -u root -l
//查看指定用户的计划
10.24 Linux系统服务管理-chkconfig工具
# chkconfig --list
//当前系统中全部服务
# ls /etc/init.d/
# chkconfig network off
# chkconfig --level 3 network off
//指定某个级别的服务关闭
# chkconfig --level 345 network off
//指定多个级别的某个服务关闭
# chkconfig --del network
# chkconfig --add network
- 将脚本放到/etc/init.d/下再将服务add就能够将脚本在某几个级别运行的时候执行了
10.25 systemd管理服务
# systemctl list-units --all--type=service
- 几个经常使用的服务相关的命令
#systemctl enable crond.service
//让服务开机启动
# systemctl disable crond
//让服务开机不启动
# systemctl status crod
//查看状态
# systemctl stop crond
//中止服务
# systemctl start crond
//启动服务
# systemctl restart crond
//重启服务
# systemctl is-enabled crond
//检查服务是否开机启动
10.26 unit介绍
- ls /usr/lib/systemd/system //系统全部unit,分为如下类型:
- service 系统服务
- target 多个unit组成的组
- device 硬件设备
- mount 文件系统挂载点
- automount 自动挂载点
- path 文件或路径
- scope 不是有systemd启动的外部进程
- slice进程组
- snapshot systemd快照
- socket 进程间通讯套接字
- swap swap文件
- timer 定时器
10.27 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】部分
扩展
- anacron http://blog.csdn.net/strikers1982/article/details/4787226
- xinetd服(默认机器没有安装这个服务,须要yum install xinetd安装) http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
- systemd自定义启动脚本http://www.jb51.net/article/100457.htm
欢迎关注本站公众号,获取更多信息