加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

centos7自动校时

(2018-07-26 15:44:22)
标签:

centos7

ntp

ntpdate

校时

时间校准

分类: linux
1、轻量级,不启动服务,使用ntpdate和crontab做定时时间修正,比较暴力
#安装ntpdate
yum -y install ntpdate;
#时间修正,同aliyun的时间服务器
ntpdate ntp1.aliyun.com;
#修改crontab作业列表,重启系统或重启crond服务即可定时修正时间
/bin/crontab -l > /tmp/crontab.bak;
echo "* */1 * * * /sbin/ntpdate ntp1.aliyun.com ntp2.aliyun.com ntp3.aliyun.com ntp4.aliyun.com ntp5.aliyun.com ntp6.aliyun.com ntp7.aliyun.com;/sbin/hwclock -w;" >> /tmp/crontab.bak;
/bin/crontab /tmp/crontab.bak;

2、自动校时,需启动ntp服务,时间慢慢校正
#安装ntp
yum -y install ntp;
#修改/etc/ntp.conf配置文件
/usr/bin/sed -i.ori 's#restrict default.*noquery#restrict default nomodify#;13i\restrict 0.centos.pool.ntp.org nomodify notrap noquery\nrestrict 1.centos.pool.ntp.org nomodify notrap noquery\nrestrict 2.centos.pool.ntp.org nomodify notrap noquery\nrestrict 3.centos.pool.ntp.org nomodify notrap noquery\nrestrict 4.ntp1.aliyun.com nomodify notrap noquery' /etc/ntp.conf;
/usr/bin/sed -i.ori '29a\server ntp1.aliyun.com\nserver time.nist.gov' /etc/ntp.conf;
#启动ntpd服务
systemctl start ntpd.service;

两种方法,可结合使用。

参考:
https://www.cnblogs.com/liuyou/archive/2012/07/29/2614330.html
https://www.cnblogs.com/fanjifen/p/6382919.html
https://ken.io/note/ntp-server-deploy-time-sync
https://www.cnblogs.com/anyux/p/7844260.html

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有