1、  首先检查虚拟机是否安装NTP,指令如下:

 rpm -qa | grep ntp

    如果没有安装,则下载RPM安装包,使用下面命令安装NTP

rpm –ivh *.rpm


2、  第二自己手动更新本地时间,用ntpdate手动更新时间,保证本地时间与目标时间相差不要太大,这样同步时间会快点。

Ntpdate ntp_server_name


3、  修改/etc/ntp.conf,加上同步的NTPServer。

     在很多集群中需要使用集群的主节点作为时间同步服务器

     尽量多同步几台NTP服务器,本地的NTP服务器才容易启动。

Server 127.127.1.0 ibrust #127.127.1.0作为LOOPBACK IP,被用于设置同步本机
Server ntp_server_name
fudge 127.127.1.0stratum 5


4、允许你想要的ip可以获得此机器的时间同步服务

   在/etc/ntp.conf文件修改配置文件如下

restrict default kod nomodify notrap nopeer noquery


#允许本机地址一切的操作

restrict127.0.0.1


#允许192.168.1.0网段获得服务

restrict192.168.1.0 mask 255.255.255.0 nomodify


5、 iptables设置,开放UDP协议的端口123

service iptables status
/sbin/iptables-I INPUT -p udp --dport 123 -j ACCEPT
serviceiptables status


6、  启动NTP服务,同时设置开机自启动

chkconfig--list ntpd
/etc/init.d/ntpdstart
chkconfig --level 35 ntpd on


7、  查看NTP的运行状态

Servicentpd status/start/stop/restart
Watchntpq –p


Ntpstat查看NTP服务器有无与上层NTP联通

注意:

局域网中的客户机连已建好的NTP服务器时,要加上一个额外的NTP server,这样同步的时间会准确。