如何在centos 7中设置ntp 服务

如何在centos 7中设置ntp 服务,第1张

一、搭建时间服务器

1、在一台linux服务器安装ntp server

tar zxvf ntp-426targz

cd ntp-426

/configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks

make && make install

2、修改ntpconf配置文件

vi /etc/ntpconf

# 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 notrap nopeer noquery

restrict default nomodify

(允许任何IP的客户机都可以进行时间同步,如果是只允许某个网段的客户机进行时间同步可以这样写

restrict 1058260 mask 2552552550 nomodify)

restrict -6 default kod nomodify notrap nopeer noquery

# 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 127001

restrict -6 ::1

# Hosts on local network are less restricted

#restrict 19216810 mask 2552552550 nomodify notrap

# Use public servers from the poolntporg project

# Please consider joining the pool

#server 0rhelpoolntporg(默认时间服务器)

#server 1rhelpoolntporg(默认时间服务器)

#server 2rhelpoolntporg(默认时间服务器)

server 101281425 (手工设置的时间服务器)

(如果是可以直连外网,可以使用LINUX默认提供的三组标准时间服务器,否则可以自己指定一个同步时间源)

#broadcast 1921681255 key 42 # broadcast server

#broadcastclient # broadcast client

#broadcast 224011 key 42 # multicast server

#multicastclient 224011 # multicast client

#manycastserver 239255254254 # manycast server

#manycastclient 239255254254 key 42 # manycast client

# Undisciplined Local Clock This is a fake driver intended for backup

# and when no outside source of synchronized time is available

server 12712710 # local clock

fudge 12712710 stratum 10

3、以守护进程启动ntpd

#/etc/rcd/initd/ntpd -c /etc/ntpconf -p /tmp/ntpdpid

#/etc/rcd/initd/ntpd start

#ps -ef|grep ntpd

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

下面命令可以知道何时ntp server完成了和自身同步的过程

在ntp server上使用命令:

# watch ntpq -p

注意LOCAL的这个就是与自身同步的ntp server。

注意reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒5=320秒的时间。

二、配置时间同步客户机

vi /var/spool/cron/root(或crontab -e)

增加一行,在每天的1点10分、9点10分、17点10分与时间同步服务器进行同步并写入BIOS

10 1 ,9,17 root /usr/sbin/ntpdate 101281425; /sbin/hwclock -w

如果同步不正常,可以加输出日志或看系统日志

输出日志的方法:

10 1 ,9,17 root /usr/sbin/ntpdate 101281425>>/tmp/1txt; /sbin/hwclock -w

在1txt中可查看时间同步时的输出结果。

或者看/var/mail/root系统日志

Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 101281425;/sbin/hwclock -w

X-Cron-Env: <SHELL=/bin/sh>

X-Cron-Env: <HOME=/root>

X-Cron-Env: <PATH=/usr/bin:/bin>

X-Cron-Env: <LOGNAME=root>

X-Cron-Env: <USER=root>

Message-Id: <20121127103001076FF2090E@tyzssq8site>

Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST)

27 Nov 18:29:59 ntpdate[6917]: step time server 101281425 offset -1361968 sec

可以看到同步成功了,如果未成功会报出错误。

三、无法同步的问题

检查ntp server主机的防火墙。可能是ntp server的防火墙屏蔽了upd 123端口。

可以用命令

#service iptables stop

  code stamp 英[kəud stæmp] 美[kod stæmp]

  [释义] 代号图章

  [例句]

  1、authorization of code symbol stamp

  规范符号标志的认可证书。

  2、First, the standards of Data Matrix two-dimensional barcode as security code in digital postage stamp was briefly introduced, following 3DES encryption algorithm was described

  文中首先简要介绍了Data Matrix二维条码作为防伪码在数字邮资戳印的标准,并介绍了与标准相关的3DES加密技术。

  3、The script can send the code to the server, have the server evaluate it, then return the results to a new buffer with an execution-time stamp

  这个脚本可以将代码发送到服务器,让服务器评估代码,然后将结果返回到一个带有执行时间戳的新缓冲区。

  4、Please stamp the code numbers on

  请把代号印上。

DABAN RP主题是一个优秀的主题,极致后台体验,无插件,集成会员系统
网站模板库 » 如何在centos 7中设置ntp 服务

0条评论

发表评论

提供最优质的资源集合

立即查看 了解详情