ntpd
date //本年本地时间
hwclock -r //查看硬件时间
hwclock --set --date '2015-8-31 13:24:00' //此处填上你想修改的硬件时间。
hwclock --hctosys //设置硬件时间与系统时间同步。
hwclock -w //保存时间
init 6 //快速重启
--------------------搭建NTPserver-----------------------
ntp server 192.168.0.200端:
# yum install ntp
# chkconfig ntpd on
# chkconfig --list ntpd
//在配置前,先用ntpdate手动同步下时间,本机与外部时间服务器时间差距太大,ntpd同步会异常。
# ntpdate -u 202.112.10.36
22 Dec 16:52:38 ntpdate[6400]: adjust timeserver 202.112.10.36 offset 0.012135 sec
# vi/etc/ntp.conf
# For more information about this file, seethe 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 timesource, but do not
# permit the source to query or modify theservice on this system.
restrict default kod nomodify notrap nopeernoquery
restrict -6 default kod nomodify notrapnopeer noquery
# Permit all access over the loopbackinterface.This could
# be tightened as well, but to do so wouldeffect some of
# the administrative functions.
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are lessrestricted.
#允许内网其他机器同步时间
restrict 192.168.1.0 mask 255.255.255.0nomodify notrap
# Use public servers from the pool.ntp.orgproject.
# Please consider joining the pool(http://www.pool.ntp.org/join.html).
#中国这边最活跃的时间服务器:http://www.pool.ntp.org/zone/cn
server 210.72.145.44 perfer#中国国家受时中心
server 202.112.10.36# 1.cn.pool.ntp.org
server 59.124.196.83# 0.asia.pool.ntp.org
#broadcast 192.168.1.255 autokey# broadcast server
#broadcastclient# broadcast client
#broadcast 224.0.1.1 autokey# multicast server
#multicastclient 224.0.1.1# multicast client
#manycastserver 239.255.254.254# manycast server
#manycastclient 239.255.254.254 autokey #manycast client
# allow update time by the upper server
#允许上层时间服务器主动修改本机时间
restrict 210.72.145.44 nomodify notrapnoquery
restrict 202.112.10.36 nomodify notrapnoquery
restrict 59.124.196.83 nomodify notrapnoquery
# Undisciplined Local Clock. This is a fakedriver intended for backup
# and when no outside source of synchronizedtime is available.
#外部时间服务器不可用时,以本地时间作为时间服务
server127.127.1.0# local clock
fudge127.127.1.0 stratum 10
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and keyidentifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which aretrusted.
# trustedkey 4 8 42
# Specify the key identifier to use withthe ntpdc utility.
#requestkey 8
# Specify the key identifier to use with thentpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostatsloopstats peerstats
置文件修改完成,保存退出,启动服务。
# service ntpd start
启动后,一般需要5-10分钟左右的时候才能与外部时间服务器开始同步时间。可以通过命令查询NTPD服务情况。
查看服务连接和监听
# netstat -tlunp | grep ntp
ntpq -p查看网络中的NTP服务器,同时显示客户端和每个服务器的关系
# ntpq -p
ntpstat查看时间同步状态,这个一般需要5-10分钟后才能成功连接和同步。所以,服务器启动后需要稍等下。
# ntpstat
NTP-Clients 192.168.0.200:
内网其他设备作为NTP的客户端配置,相对就比较简单,而且所有设备的配置都相同。
首先需要安装NTPD服务,然后配置为自启动(与NTP-Server完全一样)。然后找其中一台配置/etc/ntp.conf文件,配置完成验证通过后,拷贝到其他客户端机器,直接使用即可。
# yum install ntp
# chkconfig ntp on
# vim /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict 127.0.0.1
restrict -6 ::1
#配置时间服务器为本地的时间服务器
server 192.168.0.200
restrict 192.168.0.200 nomodify notrapnoquery
server127.127.1.0# local clock
fudge127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
--------------------/搭建NTPserver-----------------------