欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

crontab、chkconfig、systemd、unit、targ

发布时间:2025/6/16 编程问答 65 豆豆
生活随笔 收集整理的这篇文章主要介绍了 crontab、chkconfig、systemd、unit、targ 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

2019独角兽企业重金招聘Python工程师标准>>>

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
  • 转载于:https://my.oschina.net/u/3803446/blog/1811690

    总结

    以上是生活随笔为你收集整理的crontab、chkconfig、systemd、unit、targ的全部内容,希望文章能够帮你解决所遇到的问题。

    如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。