码迷,mamicode.com
首页 > 其他好文 > 详细

centos 6.5 搭建ntp服务

时间:2015-08-08 06:52:11      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:centos 6.5 搭建ntp服务

       我们大家来学习第一个服务,ntp时间服务器。学习服务首先得知道这个服务主要是做什么的,怎么去安装,怎么去配置,然后启动。知道了这些之后,我们再来搭建ntp服务。

     1. NTP服务是主要做什么的?

            答:NTP(Network Time Protocol)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正。本例讲解如何在CentOS6.5上配置NTP服务器和NTP客户端,可使多台客户机的时间与指定的NTP服务器的时间保持一致。从而保证了多台服务器的时间同步。

       2.ntp服务器和ntp客户端都需要安装哪些包?

            答: ntp服务器 yum install ntp ntpdate -y  (首先必须配置好yum,这里就不多介绍)

                    ntp客户端 yum install ntpdate -y 

    3.我们需要实现的需求?

            答: 

            1)准备好3台机器,分别为192.168.137.11(ntp服务器) 和 192.168.137.12-13(ntp客户端)

            2)服务端与上层服务器同步时间,客户端半个小时和ntp服务端同步一次时间,来客户端时间和服务端时间的正常。

       

实验步骤

1.在192.168.137.11(ntp服务端) 

[root@hx ~]# yum install ntp ntpdate -y
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: centos.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntp.i686 0:4.2.6p5-3.el6.centos will be installed
.....(此处省略)
Installed:
  ntp.i686 0:4.2.6p5-3.el6.centos              ntpdate.i686 0:4.2.6p5-3.el6.centos             
Dependency Installed:
  libedit.i686 0:2.11-4.20080712cvs.1.el6                                                       
Complete!

然后我们来配置ntp服务器的配置文件。

[root@hx ~]# vim /etc/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
server ntp.fudan.edu.cn    (server是指定上层服务器时间)
restric ntp.fudan.edu.cn nomodify notrap noquery  (允许上层服务器修改本地机器时间,如果此列不写,那么本地时间不会修改)
server 127.127.1.0    
fudge  127.127.1.0 stratum 10(如果上层服务器同步不了时间,那么本机器自动同步自己的时间)
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

修改好配置文件之后,重启ntp服务。

[root@hx ~]# service ntpd start
Starting ntpd:                                             [  OK  ]
[root@hx ~]# date
Fri Aug  7 21:25:35 CST 2015

如果时间没有立马同步,那需要等几分钟会和上层服务器同步。

2.在192.168.137.12和13(ntp客户端)

[root@localhost ~]# yum install ntpdate -y
Loaded plugins: fastestmirror, security
Determining fastest mirrors
 * base: mirrors.163.com
 * extras: mirrors.163.com
 * updates: centos.ustc.edu.cn
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.i686 0:4.2.6p5-1.el6.centos will be updated
.....(此处省略)                   
Dependency Updated:
  ntp.i686 0:4.2.6p5-3.el6.centos                                                     
Complete!
[root@localhost ~]#

安装好软件之后,主要设置自动任务计划,就可以自动同步ntp服务器时间。

[root@localhost ~]# crontab -e
*/30 * * * * /usr/sbin/ntpdate 192.168.138.12 >>/tmp/ntp.log

设置自动任务计划,半个小时同步一次ntp服务器时间。

192.168.137.12 和 192.168.137.13 都是一样的操作。


实验就是这么简单,但是如果你想了解ntp服务端的配置文件,可以去Google下。











本文出自 “linux” 博客,请务必保留此出处http://liunxbk.blog.51cto.com/8683822/1682789

centos 6.5 搭建ntp服务

标签:centos 6.5 搭建ntp服务

原文地址:http://liunxbk.blog.51cto.com/8683822/1682789

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!