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

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"





猜你喜欢

转载自indinna1.iteye.com/blog/2284435