crontab、chkconfig、systemd、unit、targ

10.23 linux任务计划cron

  1. # cat /etc/crontab liunx下的任务计划配置文件
  2. crontab -u、-e、-l、-r
  3. 格式:分 时 日 月 周 user command
  4. 分范围0-59,时范围0-23,日范文:1-31,月范围:1-12,星期分为:0-6(sunday=0 or 7)
  5. # crontab -e进入到任务计划编辑界面
  6. 0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每个星期,每个月的每天的3点执行命令
  7. 0 3 1-10 */2 2,5 /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>/tmp/123.log //每周二周五,双数月份的前10天的3点,执行任务
  8. # sytemctl start crond 启动服务# systemctl stop crond //关闭服务
  9. # ps aux | grep cron 查看是否有此进程
  10. # systemctl status crond查看状态,Actice绿色启动该
  11. 计划在/var/spool/cron/root(最后是以用户名命名的文件)
  12. # cront -l //列出信息
  13. # cront -e //编辑
  14. # cront -r //删除
  15. # cront -u root -l //查看指定用户的计划

10.24 Linux系统服务管理-chkconfig工具

  1. # chkconfig --list //当前系统中所有服务
    1. # ls /etc/init.d/
    2. # chkconfig network off
  2. # chkconfig --level 3 network off //指定某个级别的服务关闭
  3. # chkconfig --level 345 network off //指定多个级别的某个服务关闭
  4. # chkconfig --del network
  5. # chkconfig --add network
  6. 将脚本放到/etc/init.d/下再将服务add就可以将脚本在某几个级别运行的时候执行了

10.25 systemd管理服务

  1. # systemctl list-units --all--type=service
  2. 几个常用的服务相关的命令
    1. #systemctl enable crond.service //让服务开机启动
    2. # systemctl disable crond //让服务开机不启动
    3. # systemctl status crod //查看状态
    4. # systemctl stop crond //停止服务
    5. # systemctl start crond //启动服务
    6. # systemctl restart crond //重启服务
    7. # systemctl is-enabled crond //检查服务是否开机启动

10.26 unit介绍

  1. ls /usr/lib/systemd/system //系统所有unit,分为以下类型:
  2. service 系统服务
  3. target 多个unit组成的组
  4. device 硬件设备
  5. mount 文件系统挂载点
  6. automount 自动挂载点
  7. path 文件或路径
  8. scope 不是有systemd启动的外部进程
  9. slice进程组
  10. snapshot systemd快照
  11. socket 进程间通信套接字
  12. swap swap文件
  13. timer 定时器

10.27 target介绍

  1. 系统爲了方便管理用target来管理unit
  2. systemctl list-unit-files --type=target
  3. systemctl list-dependencies multi-user.target //查看指定target下面有哪些unit
  4. systemctl get-default //查看系统默认的target
  5. systemctl set-default multi-user.target
  6. 一个service属于一种类型的unit
  7. 多个unit组成了一个target
  8. 一个target里面包含了多个service
  9. cat /usr/lib/systemd/system/sshd/service // 看【install】部分

扩展

  1. anacron http://blog.csdn.net/strikers1982/article/details/4787226
  2. xinetd服(默认机器没有安装这个服务,需要yum install xinetd安装) http://blog.sina.com.cn/s/blog_465bbe6b010000vi.html
  3. systemd自定义启动脚本http://www.jb51.net/article/100457.htm

猜你喜欢

转载自my.oschina.net/u/3803446/blog/1811690