1.时间管理命令
at /etc/adjtime
timedatectl
timedatectl set-local-rtc 0 不使用rtc时间
timedatectl set-timezone "Asia/Tokyo" 设置时区
timedatectl
timedatectl set-time "2021-11-11 11:11:11"
systemctl status chronyd.service 查看时间同步服务
systemctl stop chronyd.service 关闭服务
timedatectl set-time "2021-11-11 11:11:11"
timedatectl
systemctl restart chronyd.service 重新开启时间同步服务
timedatectl
systemctl status chronyd.service 查看服务状态
timedatect
2、时间同步
服务器:
systemctl stop firewalld 关闭防火墙
vim /etc/chrony.conf 查看配置文件
systemctl restart chronyd.service 重启服务
--------------------------------------------------------
配置文件:
allow 0.0.0.0/0 允许同步至所有主机
# Serve time even if not synchronized to a time source.
local stratum 10 去掉##
接收端:
vim /etc/chrony.conf
systemctl restart chronyd.service
------------------------------------------------
配置文件:pool 172.25.254.232 iburst
(实验结果正确)
3、系统延时
at (now+1min .......)
vim /etc/at.deny 黑名单
vim /etc/at.allow 白名单
4、系统定时
#/var/spool/cron/username ##任务保存文件
crontab -u username -e
crontab -u username -l
crontab -u username -r
1)crontab时间表(分钟小时天月周)
* * * * * ##每分钟
*/2 * * * * ##每两分钟
*/2 09-17 * * * ##早九到晚五每两分钟
*/2 09-17 3,5 2 5 ##二月的三号和五号以及每周五早九到晚5每隔两分钟
2) 黑白名单
3)定时时不发送邮件(两种方法)、不生成日志
dnf install postfix mailx 安装软件
systemctl enable --now postfix 立即启动软件
不发送邮件的第一种方法:设置定时任务时直接将命令丢入/dev/null 或MAILTO=' '
第二种方法:关闭定时任务的发送邮件功能 /etc/sysconfig/crond
4)系统级别的cron
5)临时文件管理
cd /lib/tmpfiles.d/
vim westos.conf 编辑临时文件规则
d /mnt/westos 1777 root root 6s
systemd-tmpfiles --create /lib/tmpfiles.d/westos.conf 执行规则,新建/mnt/westos目录
watch -n 1 ls -lR /mnt
在/mnt/westos下新建file1 file2文件
然后建立file3文件,并且立刻执行systemd-tmpfiles --clean /lib/tmpfiles.d/westos.conf清理不符合规则的文件
file1 file2被删除