天天看點

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]

繼續閱讀