Linux-例行性工作+时间服务器

例行性工作

1.单一执行

bash 复制代码
1.主要文件夹
#at工作调度对应的系统服务
/etc/atd 
#at的工作文件存放目录
/var/spool/at
#at工作的日志文件
/var/log/cron

2.命令
命令格式:at [参数] [时间]
参数:-m 当任务完成之后,即使没有标准输出,将给用户发送邮件
-l atq的别名,可列出目前系统上面的所有该用户的at调度
-d atrm的别名,可以取消一个在at调度中的工作
-v 使用较明显的时间格式,列出at调度中的任务列表
-c 可以列出后面接的该项工作的实际命令内容
-f 从文件中读取作作业
时间格式:
HH:MM  在今天的HH小时MM分钟执行,如果今天的这个时间点已经过了,则明
天执行
HH:MM YYYY-MM-DD  强制规定在某年某月的某一天的特殊时刻进行该工作
now + 2 minutes 从现在开始几分钟minutes, hours, days, or weeks

[root@server ~]# at now + 3 minutes

2.循环执行

bash 复制代码
1.主要文件
#crontab工作调度对应的系统服务
[root@localhost ~]# systemctl status crond
#crontab工作的日志文件
[root@localhost ~]# ll /var/log/cron
#用户定义计划任务的文件所在目录
[root@localhost ~]# ll /var/spool/cron/

2.命令
[root@localhost ~]# crontab  --help
crontab: invalid option -- '-'
crontab: usage error: unrecognized option
Usage:
 crontab [options] file
 crontab [options]
 crontab -n [hostname]
Options:
 -u <user>  define user
 -e         edit user's crontab
 -l         list user's crontab
 -r         delete user's crontab
 -i         prompt before deleting
 -n <host>  set host in cluster to run users' crontabs
 -c         get host in cluster to run users' crontabs
 -s         selinux context
 -V         print version and exit
 -x <mask>  enable debugging
 
#注意
1. 用户级定时任务(crontab -e)
路径:/var/spool/cron/用户名格式:
* * * * * 命令
不用写用户名
2. 系统级定时任务(/etc/crontab)
格式才需要写用户名:
* * * * * 用户名 命令
你现在是用 crontab -e,所以不能加 root。

时间服务器

1.软件安装

bash 复制代码
yum install chrony -y
systemctl enable --now chronyd

2.主要文件

bash 复制代码
/etc/chrony.conf

#设置时间服务器的服务端名字
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst   

# Allow NTP client access from local network.
#设置允许哪个客户端可以访问该服务器
#allow 192.168.0.0/16

#修改配置文件之后需要重启服务
[root@localhost ~]# systemctl  restart chronyd

3.配置时间服务器服务端

bash 复制代码
172.25.254.100 服务端
172.25.254.200 客户端

100服务端允许客户端接入时间服务器
[root@test ~]#  grep allow /etc/chrony.conf
allow 172.25.254.0/24
[root@test ~]#

200客户端配置服务端ip作为时间服务器
[root@harbor ~]# grep iburst /etc/chrony.conf
server 172.25.254.100 iburst

测试
[root@harbor ~]# chronyc sources
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* 172.25.254.100                3   6    17     4    +96us[+1937us] +/-   39ms
相关推荐
无足鸟ICT1 小时前
【RHCA+】swap和物理内存
linux
zly35003 小时前
esxi安装 windows2000 鼠标不动
运维·服务器
LabVIEW开发4 小时前
Ethernet/IP 会话无效 -251723770
服务器·网络协议·tcp/ip
Huangjin007_6 小时前
【Linux 系统篇(四十一)】线程(二):线程的优缺点、资源共享与上下文切换
linux·运维·服务器
张张123y7 小时前
个人助手型 Agent 的六个工程细节:Hermes 与 OpenClaw 的审批、委派、上下文与调度
网络·人工智能·开源·后端开发·ai agent
嵌入式 Linux手记7 小时前
嵌入式面试都考的置位清位:位运算四件套
linux·c语言·驱动开发·面试·职场和发展·嵌入式
Rabitebla7 小时前
【Linux】文件篇(六):Shell 实战——从系统调用到命令行重定向
linux·服务器·c++·笔记·学习
nice_lcj5208 小时前
【从零理解计算机网络 · 15】完整串联:一次请求的全旅程,以及那道经典面试题
网络·计算机网络·http·面试·tcp·总结·网络排查
dingdingfish8 小时前
TLPI 第57章 读书笔记:Sockets: UNIX Domain
linux·socket·domain·sendto·recvfrom·tlpi·socketpair
戊本菌17 小时前
进程(三)runqueue 与 Linux 的 O(1) 调度
linux·运维·服务器