centos内网ntp时间同步,centos输出重定向,linux定时任务

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27901091/article/details/88017168

一、搭建内网ntp时间服务器(假设ip为1.2.3.4)
1.安装ntp:

yum install ntp

2.修改配置文件:
只用改两个个地方

line 8:    restrict default nomodify 
line 21:   server ntp.fudan.edu.cn

此处是外部的时间服务器。
3.启动时间服务器

systemctl start ntpd
ntpq -p  #查看可用时间源

二、客户端
1.现在执行

ntpdate 1.2.3.4  #可以运行

2.创建定时任务
可能在定时任务中,报错/bin/sh: netdate: command not found

whereis ntpdate

输出:ntpdate: /usr/sbin/ntpdate /usr/share/man/man8/ntpdate.8.gz
所以使用/usr/sbin/ntpdate来同步

crontab -e 

在打开的文本里,编辑如下:

*/5 * * * * /usr/sbin/ntpdate 1.2.3.4 >>/root/ntplog

表示每5分钟同步一次,并把输出存到/root/ntplog

注1:定时任务的五个 * * * * * 分别是分 时 日 月 周;表示每;/5是每几分钟
注2:输出重定向>覆盖;>>添加。

猜你喜欢

转载自blog.csdn.net/qq_27901091/article/details/88017168
今日推荐