*一、linux任务计划cron ** cat /etc/crontab crontab -u、 //指定用户 -e //编辑 -l //查看 -r //删除 格式:分 时 日 月 周 user command 每个用户的任务计划保存在文件/var/spool/cron/username 分范围0-59,时范围0-23,日范围1-31,月范围1-12,周1-7 可用格式1-5表示一个范围1到5 可用格式1,2,3表示1或者2或者3 可用格式/2表示被2整除的数字,比如小时,那就是每隔2小时 要保证服务是启动状态

 systemctl start crond.service   //启动服务

  systemctl stop crond.service  //关闭服务

二、linux系统服务管理chkconfig 此工具在centos6之前使用,centos7之后已废弃,

chkconfig --list   //列出所有服务

0 --关机状态 1 --单用户模式 2 --不带图形的多用户模式(比3少nfs服务) 3 --不带图形的多用户模式 4 --待定,暂时无用 5 --带图形的多用户模式 6 --重启状态

ls /etc/init.d/

chkconfig --level 3 network off  //3级别的network服务关闭
 chkconfig --level 345 network off  //345级别的network服务关闭
 chkconfig --del network   //删除network服务
 chkconfig --add network    //添加network服务

添加服务之前需要先将服务脚本放进 /etc/init.d/文件夹 三、systemd 此服务是centos7开始使用的系统服务管理机制 systemctl list-units --all --type=service //查看所有service服务 (空格向下翻页) load 反映设备定义是否正确加载 ACTIVE 激活状态, SUB 是否运行 几个常用的服务相关的命令 systemctl enable crond.service //让服务开机启动(.service可以省略) systemctl disable crond //不让开机启动 systemctl status crond //查看状态 systemctl stop crond //停止服务 systemctl start crond //启动服务 systemctl restart crond //重启服务 systemctl is-enabled crond //检查服务是否开机启动

开机启动的服务,会在/etc/systemd/system/multi-user.target.wants/crond.service 目录下建立一个软连接,关闭开机启动后会删除这个软连接 四、unit

ls /usr/lib/systemd/system //系统所有unit,分为以下类型 service 系统服务 target 多个unit组成的组 device 硬件设备 mount 文件系统挂载点 automount 自动挂载点 path 文件或路径 scope 不是由systemd启动的外部进程 slice 进程组 snapshot systemd快照 socket 进程间通信套接字 swap swap文件 timer 定时器 **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
 systemctl 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 //设置系统默认的target 一个service属于一种类型的unit 多个unit组成了一个target 一个target里面包含了多个service cat /usr/lib/systemd/system/sshd.service //看[install]部分