NTP服务器的配置

在安装Cloudera CDH的时候,是要求安装配置NTP服务器来实现不同主机之间的时间同步问题。下面详细的介绍一下NTP的安装过程。

一、服务器端的配置

1、首先安装ntp服务器,安装的方式有很多,可以选择rpm,tar也可以选择yum在线安装。那么在这里我选择的是在线安装

  执行 yum install ntp  即可

2、查看已安装的ntp的版本

    rpm -qa |grep ntp   结果如下图所示:

3、修改ntp.conf配置文件

  vi  /etc/ntp.conf  该文件主要注意两个地方

  (1)设置允许同步的客户端主机的ip地址或者ip段

  如:restrict 192.168.120.0 mask 255.255.255.0 nomodify 表示的是允许192.168.120.1--192.168.120.255的ip地址的主机都可以与服务器同步。

  (2)设置上一层同步的服务器

  server 2.rhel.pool.ntp.org(默认时间服务器)

 最后,该文件的修改形式如下:

# For more information about this file, see the 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 time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify 
restrict -6 default kod nomodify 

# Permit all access over the loopback interface.  This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
restrict 127.0.0.1 
restrict -6 ::1
restrict 192.168.120.0 mask 255.255.255.0 nomodify  //这里需要注意的地方

# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
server s1a.time.edu.cn prefer    //这里是需要注意的地方
server s1b.time.edu.cn
server s1c.time.edu.cn

#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

# Enable public key cryptography.
#crypto

includefile /etc/ntp/crypto/pw

# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography. 
keys /etc/ntp/keys

# Specify the key identifiers which are trusted.
#trustedkey 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

 4、以守护进程启动ntpd

  执行  ntpd  -c  /etc/ntp.conf  -p  /tmp/ntpd.pid

      ntpd start

      ps -ef|grep ntpd

 在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生 no server suitable for synchronization found的错误。

  那么如何知道何时ntp server完成了和自身同步的过程呢?

  在ntp server上使用命令查看是否连接上外网的服务器(这里可以注意:配置了多少个server就会出现多少个):

  watch ntpq -p

  出现如下画面:

  

二、配置时间同步客户机

  (1)vi  /var/spool/cron/root(或crontab -e) 在该文件中添加下面一行内容

    */30 * * * * root /usr/sbin/ntpdate 192.168.120.231 表示的是每个30分钟向服务器192.168.120.231更新一次时间。

  (2)  # 将计划任务设为自动,默认是启动的【可选】、


        chkconfig crond on

   (3) 启动计划任务服务

        service crond restart

  (4)执行如下命令

    ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid -l /app/ntp/log/ntp.log

  (5)查看是否能连接上上面配置的服务器

    watch ntpq  -p

 

转载于:https://www.cnblogs.com/ljy2013/p/4610089.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值