10月30日任务
10.27 target介绍
10.23 linux任务计划cron
-
crontab -u 、-e、-l 、 -r
-
格式:分 时 日 月 周 user command
-
分范围0-59 ,时范围0-23 ,日范围 0-31 ,月范围0-12 ,周1-6
-
可用格式1-5表示一个范围1到5
-
可用格式1,2,3表示1或者2或者3
-
可用格式*/2表示被2整除的数字,好比小时,那就是每隔2小时
-
要保证服务是启动状态
-
systemctl start crond.service
#任务计划的配置文件
[root@centos6 ~]# cat /etc/crontab
SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root
HOME=/
# For details see man 4 crontabs
# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * user-name command to be executed
#crontab -e 定义一个任务计划0 3 * * * /bin/bash /usr/local/sbin/123.sh >>/tmp/123.log 2>>tmp/123.log
[root@centos6 ~]crontab -e
要想让任务生效,须要执行systemctl start crond 命令,由于本地系统是centos 6不支持systemctl 。
[root@centos6 ~]# service crond start
[root@centos6 ~]# ps aux |grep cron
root 1201 0.0 0.1 116908 1304 ? Ss Oct16 0:04 crond
root 19782 0.0 0.0 103312 880 pts/0 S+ 12:24 0:00 grep --color=auto cron
[root@centos6 ~]# service crond status
crond (pid 1201) is running...
10.24 chkconfig工具
Linux系统服务管理-chkconfig
[root@zgxlinux-aliyun ~]# chkconfig --list
Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.
If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.
aegis 0:off 1:off 2:on 3:on 4:on 5:on 6:off
agentwatch 0:off 1:off 2:on 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
[root@zgxlinux-aliyun ~]# LANG="zh_CN.UTF-8"
[root@zgxlinux-aliyun ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@zgxlinux-aliyun ~]# chkconfig network off
[root@zgxlinux-aliyun ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:关 3:关 4:关 5:关 6:关
[root@zgxlinux-aliyun ~]# chkconfig network on
[root@zgxlinux-aliyun ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:开 4:开 5:开 6:关
[root@zgxlinux-aliyun ~]# chkconfig --level 3 network off
[root@zgxlinux-aliyun ~]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
#添加和删除一个服务,必需要进入/etc/init.d/这个目录。
[root@zgxlinux-aliyun ~]# cd /etc/init.d/
[root@zgxlinux-aliyun init.d]# ls
aegis agentwatch functions netconsole network README
[root@zgxlinux-aliyun init.d]# cp network 123
[root@zgxlinux-aliyun init.d]# ls
123 aegis agentwatch functions netconsole network README
[root@zgxlinux-aliyun init.d]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
[root@zgxlinux-aliyun init.d]# chkconfig --add 123
[root@zgxlinux-aliyun init.d]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
123 0:关 1:关 2:开 3:开 4:开 5:开 6:关
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
[root@zgxlinux-aliyun init.d]# chkconfig --del 123
[root@zgxlinux-aliyun init.d]# chkconfig --list
注:该输出结果只显示 SysV 服务,并不包含
原生 systemd 服务。SysV 配置数据
可能被原生 systemd 配置覆盖。
要列出 systemd 服务,请执行 'systemctl list-unit-files'。
查看在具体 target 启用的服务请执行
'systemctl list-dependencies [target]'。
aegis 0:关 1:关 2:开 3:开 4:开 5:开 6:关
agentwatch 0:关 1:关 2:开 3:开 4:开 5:开 6:关
netconsole 0:关 1:关 2:关 3:关 4:关 5:关 6:关
network 0:关 1:关 2:开 3:关 4:开 5:开 6:关
10.25 systemd管理服务
-
systemctl list-units --all --type=service //列出全部的服务类型为service
-
几个经常使用的服务相关的命令
-
systemctl enable crond.servuce //让服务开机启动
-
systemctl disable crond //不让开机启动
-
systemctl status crond //查看状态
-
systemctl stop crond //中止服务
-
systemctl start crond //启动服务
-
systemctl restart crond //重启服务
-
systemctl is-enabled crond //检查服务是否开机启动