linux下利用ntpdate同步时间并定时更新时间

[size=medium]1,首先vim /etc/ntp.conf


# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery

# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
#restrict 127.0.0.1
#restrict -6 ::1
restrice 202.112.10.36
restrice 202.112.29.82
restrice 202.112.26.37
restrice 202.112.7.13
restrice 210.34.128.32

server 202.112.10.36 #s2c.time.edu.cn
server 202.112.29.82 #s2f.time.edu.cn
server 202.112.26.37 #s2g.time.edu.cn
server 202.112.7.13 #s2m.time.edu.cn
server 210.34.128.32 #time.jmu.edu.cn


server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

logfile /var/log/ntp.log

restrict 192.168.1.0 mask 255.255.255.0

#restrict 202.112.0.7
#server 202.112.0.7 prefer
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.centos.pool.ntp.org iburst
#server 1.centos.pool.ntp.org iburst

2,ntpdate 210.34.128.32 && hwclock -w

这个只是利用其中的一个服务器(210.34.128.32)

hwclock -w的作用是把同步的时间写入到BIOS中

----------------------------啦啦啦 我是分割线------------------------

3,定时同步 (这只是个例子 我还有另外一篇详细讲解了定时同步)

vim /etc/crontab
添加下面这行

*/10 * * * * root (ntpdate 210.34.128.32 && hwclock -w)

这行命令 是表示 每十分钟定时同步一次


----------------------------啦啦啦 我是分割线------------------------


注:

vim /etc/sysconfig/clock 在这个下面可以修改时区
修改为:

ZONE="Asia/Shanghai"


[/size]
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值