您的位置:首页 > 运维架构 > Linux

Linux 使用 NTP 时钟同步

2015-12-19 21:24 411 查看
一、安装NTP

1、  下载 tar 包: ntp-ntp-4.2.8.tar.gz

2、  上传 tar 包到需要安装时钟同步的服务端及客户端机器上

3、  进入上传文件目录解压文件

命令: tar -zxvf ntp-ntp-4.2.8.tar.gz

4、  进入解压后的文件目录:

命令: cd ntp-ntp-4.2.8

5、  编译安装包

命令:./configure --prefix=/usr/local/ntp && make

6、  安装

命令: make install

 

二、服务端配置

1、  修改配置文件:

命令: vi /etc/ntp.conf

【写入一下内容】

###权限设置

restrict default nomodify

 

#开放本机的访问

restrict 127.0.0.1

 

driftfile /etc/ntp/drift

logfile /var/log/ntp.log

 

#设置上级同步服务器

server 127.127.1.1

fudge 127.127.1.1 stratum 5

 

2、  启动ntp服务

命令: /usr/local/ntp/bin/ntpd start

 

三、客户端配置

1、  安装NTP,步骤与服务端相同

2、  修改配置文件

命令: vi /etc/ntp.conf

server 【NTP服务端IP】

3、  手动同步时间

命令: /usr/local/ntp/bin/ntpdate【NTP服务端IP】

 

4、 自动同步时间

命令: crontab–e

*/5 * * * * /usr/local/ntp/bin/ntpdate 【NTP服务端IP】

四、可能出现的问题

1、  客户端手动同步时,报错:

no serversuitable for synchronization found

出现此问题有三种情况:

1)   服务端启动后需要等5分钟左右,才能进行同步

2)   服务端启动失败,可以使用 watch /usr/local/ntp/bin/ntpq –p 命令查看服务端运行情况

3)   防火墙拦截,关闭防火墙,命令:service iptables stop

2、  服务端使用 /usr/local/ntp/bin/ntpq–p 命令查询时间同步信息时,提示:

no associationID`s returned

需要检查服务端配置文件是否正确。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Linux