$yum install -y ntp      #安装NTP服务包

$cd /etc

$cp ntp.conf ntp.conf.bak      #备份配置文件


$vim ntp.conf   #修改配置文件 


driftfile /var/lib/ntp/drift


restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery


restrict 127.0.0.1

restrict -6 ::1


#注册本地(局域网)地址

restrict 192.168.240.129


#注册互联网服务器地址,用于本服务器与互联网的时间同步

server time.nist.gov

server 192.168.240.129

fudge 192.168.240.129 straatum 10


#启动ntpd服务

$service ntpd start


#ntpq用来监视ntpd操作,ntpq -p查询网络中的NTP服务器,同时显示客户端和每个服务器的关系

$ntpq -p      #这是Ver. 4.2.6p5。根据不同的版本,可能要写成下面的方式,即要加上时间服务器名

$ntpq -p time.windows.com


#和time.windows.com 进行时间同步。

$ntpdate time.windows.com