导航:首页 > IDC知识 > centos配置ntp服务器

centos配置ntp服务器

发布时间:2020-10-23 11:25:51

1、如何在centos 7中设置ntp 服务

确认已经ntp程序包:# yum install ntp
配置时间源# vi /etc/ntp.conf server time.lib.tsinghua.e.cn server 0.pool.ntp.org server 1.pool.ntp.org server 2.pool.ntp.org
配置是否为其他PC提供时间服务# vi /etc/ntp.conf restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
配置开机时自动运行时间服务# chkconfig ntpd on
启动或停止时间服务# service ntpd start # service ntpd stop # service ntpd restart
验证ntp服务已经运行# pgrep ntpd
初始同步# ntpdate -u time.lib.tsinghua.e.cn
确认同步成功# ntpq -p
如果要提供时间服务,还必须相应的设置iptable防火墙的配置。CentOS的时间服务使用udp 123端口。

2、centos怎么设置时间与另一台服务器时间同步

一,用ntpdate从时间服务器更新时间
如果你的linux系统根本没有ntpdate这个命令
yum install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下
[root@localhost ~]# ntpdate time.nist.gov
22 Oct 21:11:43 ntpdate[5014]: adjust time server 207.200.81.113 offset -0.018788 sec

如果出去上面的内容说明,同步成功了。然后在crontab里面加上以下内容。
*/10 * * * * ntpdate time.nist.gov #域名或IP
每隔十分钟同步一次。推荐几个时间服务器。
time.nist.gov
time.nuri.net
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
asia.pool.ntp.org
二,用ntp搭建自己的时间服务器
上面我们是利用别人的时间服务器来同步时间,这些时间服务器都是比较权威的。当我们自己搭建时间服务器就不用crontab来定时去跑。
1,安装时间服务器ntp
yum install ntp
2,配置ntp
查看复制打印?
[root@localhost ~]# cat /etc/ntp.conf |awk '{if($0 !~ /^$/ && $0 !~ /^#/) {print $0}}'
restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包
restrict 127.0.0.1 //给于本机所有权限
restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限
server time.nist.gov prefer //设置时间服务器,加prefer表示优先
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
driftfile /var/lib/ntp/drift
keys /etc/ntp/keys

3,启动 ntp
[root@localhost ~]# /etc/init.d/ntpd start
4,查看并测试
[root@localhost ~]# netstat -upnl |grep ntpd //查看时程
[root@localhost ~]# ntpq -pn //查看同步的服务器IP
remote refid st t when poll reach delay offset jitter
==============================================================================
50.77.217.185 .INIT. 16 u - 64 0 0.000 0.000 0.000
202.90.158.4 .INIT. 16 u - 64 0 0.000 0.000 0.000
202.71.100.89 .INIT. 16 u - 64 0 0.000 0.000 0.000
202.134.1.10 .INIT. 16 u - 64 0 0.000 0.000 0.000
*127.127.1.0 .LOCL. 10 l 18 64 377 0.000 0.000 0.001
[root@localhost ~]# ntpstat //同步的结果
synchronised to local net at stratum 11
time correct to within 12 ms
polling server every 512 s

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾做过时间同步更新的操作
poll:下次更新在几秒之后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差异时间

3、centos6.3 ntp时间同步怎么配置 ?

一、服务器配置
1 安装ntp
yum install ntp -y
2 修改ntp配置文件
vi /etc/ntp.conf
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#server 2.centos.pool.ntp.org
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
server 3.asia.pool.ntp.org
注:服务端的配置文件内网的配置不略有不同,如果内网有很多机器,只需要配置一台外网机器服务端,然后配置内网的,安装方式都一样,只是内网的配置文件/etc/ntp.conf略有不同
nomodify - 用户端不能更改ntp服务器的时间参数
noquery - 用户端不能使用ntpq,ntpc等命令来查询ntp服务器
notrap - 不提供trap远端登陆
3 启动
/etc/rc.d/init.d/ntpd start
4 设置开机启动
chkconfig ntpd on
5 查询网络中的NTP服务器,同时显示客户端和每个服务器的关系
ntpq -p 其中,
remote - 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid - 参考上一层ntp主机地址
st - stratum阶层
when - 多少秒前曾经同步过时间
poll - 下次更新在多少秒后
reach - 已经向上层ntp服务器要求更新的次数
delay - 网络延迟
offset - 时间补偿
jitter - 系统时间与bios时间差
6 内网客户端配置
安装及启动方式都一样,只是server的配置不一样,把server的配置,修改成连接外网的那台内网IP
server 192.168.1.8

这是我之前安装的记录,详细你可以参考:
http://mnt.conf.blog.163.com/blog/static/115668258201432492034844/

4、如何在 CentOS 中设置 NTP 服务器

一、搭建时间服务器
1、在一台linux服务器安装ntp server
tar zxvf ntp-4.2.6.tar.gz
cd ntp-4.2.6
./configure --prefix=/usr/local/ntp --enable-all-clocks --enable-parse-clocks
make && make install
2、修改ntp.conf配置文件
vi /etc/ntp.conf
# 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 10.58.26.0 mask 255.255.255.0 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 127.0.0.1
restrict -6 ::1
# 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
#server 0.rhel.pool.ntp.org(默认时间服务器)
#server 1.rhel.pool.ntp.org(默认时间服务器)
#server 2.rhel.pool.ntp.org(默认时间服务器)
server 10.128.14.25 (手工设置的时间服务器)
(如果是可以直连外网,可以使用LINUX默认提供的三组标准时间服务器,否则可以自己指定一个同步时间源)

#broadcast 192.168.1.255 key 42 # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 key 42 # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 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 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10

3、以守护进程启动ntpd
#/etc/rc.d/init.d/ntpd -c /etc/ntp.conf -p /tmp/ntpd.pid
#/etc/rc.d/init.d/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 10.128.14.25; /sbin/hwclock -w
如果同步不正常,可以加输出日志或看系统日志
输出日志的方法:
10 1 ,9,17* * * root /usr/sbin/ntpdate 10.128.14.25>>/tmp/1.txt; /sbin/hwclock -w
在1.txt中可查看时间同步时的输出结果。
或者看/var/mail/root系统日志
Subject: Cron <root@tyzssq8> /usr/sbin/ntpdate 10.128.14.25;/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: <[email protected]>
Date: Tue, 27 Nov 2012 18:30:01 +0800 (CST)
27 Nov 18:29:59 ntpdate[6917]: step time server 10.128.14.25 offset -1.361968 sec
可以看到同步成功了,如果未成功会报出错误。

三、无法同步的问题
检查ntp server主机的防火墙。可能是ntp server的防火墙屏蔽了upd 123端口。
可以用命令
#service iptables stop

5、如何在 CentOS 中设置 NTP 服务器

centos 5.6安装NTP服务器 为有些服务和实验需要多台机器的时间同步,所以就有了搭建NTP的前提条件了,具体步骤如下: 1,安装ntp服务 yum install ntp.i* -y 2,修改/etc/ntp.conf restrict default kod nomodify notrap nopeer noquery # restrict -6 default kod nomodify notrap nopeer noquery #针对ipv6设置 #这是ntp的默认设置 # 允许本地所有操作 restrict 127.0.0.1 restrict -6 ::1 # 允许的局域网络段 restrict 10.0.0.0 mask 255.0.0.0 nomodify motrap restrict 192.168.0.0 mask 255.255.0.0 nomodify motrap # 使用上层的internet ntp服务器 restrict 207.46.232.182 mask 255.255.255.255 nomodify notrap noquery server 207.46.232.182 # 如果无法与上层ntp server通信以本地时间为标准时间 server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 # 计算本ntp server 与上层ntpserver的频率误差 driftfile /var/lib/ntp/drift # Key file containing the keys and key identifiers used when operating # with symmetric key cryptography. keys /etc/ntp/keys #日志文件 logfile /var/log/ntp.log #说明: restrict <IP 地址> <子网掩码> <网段> <子网掩码> [] ignore :关闭所有ntp服务 noquery:不提供ntp服务 notrap:不提供trap远程事件登录的功能 nomodiy:表示客户端不能更改ntp服务器的时间参数,但可以通过ntp服务器进行时间矫正 notrust:拒绝没有通过认证的客户端 nokod:kod技术可以组织一种dos攻击 2,在修改/etc/ntp/step-tickers文件 207.46.232.182 127.127.1.0 #当ntp服务器启动时自动与这个文件中的记录ip进行时间校对 3,修改/etc/sysconfig/ntpd SYNC_HWCLOCK=YES #允许BIOS与系统时间同步 4,客户端设置略。

6、redhat7.2 centos7.2怎么配置ntp服务器

本地源之前已经发布了相关的经验,没有源安装的可以寻找作者之前写的经验。这里只分享如何搭建TFTP服务器。并能正常使用。先搜索TFTP服务器,看看都有哪些:yum search tftp

有两个TFTP,一个是服务器,一个是客户端。

安装TFTP服务器与客户端,使用命令: yum install tftp -y tftp-server

安装过程请等待......

安装完成,默认TFTP是不会启动服务的。需要修改配置文件:vi /etc/xinetd.d/tftp

只需要修改disable = yes 改为no。悠然后保存即可。

使用登录systemctl restart tftp.service重新启动,并查看状态是running.

ss -tunlp |grep tftp查看TFTP服务器是否监听69号端口。

在tftp根目录下创建one文件:touch /var/lib/tftpboot/one;

使用tftp连接到本地的地址;

使用get下载one到所在目标

ls查看是否下载成功。

7、如何在 CentOS 中设置 NTP 服务器

配置的环境及要求:
1.假设在192.168.0.0网段内,要以IP为192.168.0.240的Linux机器时间服务器。
2.192.168.0.240服务器能上外网,能与比较权威的公网时间服务器同步
3.同网段内的其他机器每小时自动向192.168.0.240同步时间
一、安装
yum -y install ntp ntpdate
二、配置
2.1.NTP server的主配置文件为/etc/ntp.conf 现对/etc/ntp.conf的各项进行说明
cp /etc/ntp.conf /etc/ntp.conf.bak
vim /etc/ntp.conf
2.vi /etc/ntp.conf(以下是ntp.conf文件的内容)
#设置此服务器同上层服务器做时间同步的IP地址,prefer意味着首选IP地址
#经试验,下面的几个时间服务器速度还不错(默认配置即可)
server 210.72.145.44 prefer
server 218.21.130.42
server 0.asia.pool.ntp.org
server 1.asia.pool.ntp.org
server 2.asia.pool.ntp.org
#记录上次的NTP server与上层NTP server联接所花费的时间
driftfile /etc/ntp/drift
#设置默认策略为允许任何主机进行时间同步
restrict default ignore
#设置允许访问此时间服务器的时间服务的IP地址
#根据自己实际情况配置
restrict 127.0.0.1
restrict 192.168.10.2# 指定某台机器时间同步
restrict 192.168.0.0 mask 255.255.255.0 #允许192.168.0.0/254子网内主机时间同步
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #允许任何主机跟进行时间同步
#指定阶层编号为10,降低其优先度。
fudge 127.127.1.1 stratum 10
#设置ntp日志的path
statsdir /var/log/ntp/
#设置ntp日志文件
logfile /var/log/ntp/ntp.log
三、维护
----添加为服务
chkconfig --level 345 ntpd on
----启动
service ntpd start

/etc/rc.d/init.d/ntpd start
----停止
service ntpd stop

/etc/rc.d/init.d/ntpd stop
----管理命令
ntpq –p #查看本机和上层服务器的时间同步结果
ntptrace #可以用来追踪某台时间服务器的时间对应关系
ntpdate IP #客户端要和NTP server进行时钟同步。
/var/log/ntp/ntp.log #查看ntp日志
----------------------------------
开启防火墙端口
iptables -A INPUT -p udp -dport 123 -j ACCEPT
/etc/init.d/iptables save
service iptables restart
四、配置客户端
测试同步:
ntpdate ip地址
设置自动同步:
echo “00 */1 * * * root /usr/sbin/ntpdate 192.168.0.240;/sbin/hwclock -w”>>/etc/crontab
每小时同NTP server进行一次时钟同步,并写入本机BIOS

8、redhat7.2 centos7.2怎么配置ntp服务器

步骤(Server):

1
redhat版本不同ntp的版本可能也会有所变化,在安装之前需要查找ntp服务,看下是否存在:
yum search ntp

2
查找到ntp.x86_64,使用yum进行安装。安装时.x64_64可以不输入。
yum install -y ntp
-y:不提示,直接安装

3
进入ntp配置目录:
vi /etc/ntp.conf
4
进入ntp.conf配置文件,注释以server开头的配置,并添加内容:server 127.127.1.1
添加完成保存退出。

5
重启ntp服务器,并查看状态是否running。
systemctl restart ntpd.service #重启服务
systemctl status ntpd.service #查看状态

6
查看ntp服务是否能够被同步,显示为“LOCAL”,表示成功。如果没有任何显示,客户端将无法同步。

END
步骤2(Client):

1
服务器已经配置完成,现在是Client配置,测试Client能否与Server相连。

2
在Clientt上使用ntpdate来同步:ntpdate 192.168.116.2
同步后反馈是是成功同步的。

9、如何在 CentOS 中设置 NTP 服务器

1.LinuxNTP客户端主机需要ntpupdate软件包来和服务器同步时间。可以轻松地使用yum或apt-get安装这个软件包。安装完软件包之后,用服务器的IP地址运行下面的命令。#ntpdate基于RHEL和Debian的系统命令都相同。2.Windows如果你正在使用Windows,在日期和时间设置(DateandTimesettings)下查找网络时间(InternetTime)。3.Cisco设备如果你想要同步Cisco设备的时间,你可以在全局配置模式下使用下面的命令。#ntpserver来自其它厂家的支持NTP的设备有自己的用于网络时间的参数。如果你想将设备和NTP服务器同步时间,请查看设备的说明文档。

10、如何在 CentOS 中设置 NTP 服务器

备 CentOS 服务器

现在让我们来开始在 CentOS 上设置 NTP 服务器。

首先,我们需要保证正确设置了服务器的时区。在 CentOS 7 中,我们可以使用 timedatectl 命令查看和更改服务器的时区(比如,"Australia/Adelaide",LCTT 译注:中国可设置为 Asia/Shanghai )

# timedatectl list-timezones | grep Australia

# timedatectl set-timezone Australia/Adelaide

# timedatectl

继续并使用 yum 安装需要的软件

# yum install ntp

然后我们会添加全球 NTP 服务器用于同步时间。

# vim /etc/ntp.conf

server 0.oceania.pool.ntp.org

server 1.oceania.pool.ntp.org

server 2.oceania.pool.ntp.org

server 3.oceania.pool.ntp.org

默认情况下,NTP 服务器的日志保存在 /var/log/messages。如果你希望使用自定义的日志文件,那也可以指定。

logfile /var/log/ntpd.log

如果你选择自定义日志文件,确保更改了它的属主和 SELinux 环境。

# chown ntp:ntp /var/log/ntpd.log

# chcon -t ntpd_log_t /var/log/ntpd.log

现在初始化 NTP 服务并确保把它添加到了开机启动。

# systemctl restart ntp

# systemctl enable ntp

验证 NTP Server 时钟

我们可以使用 ntpq 命令来检查本地服务器的时钟如何通过 NTP 同步。

控制到 NTP 服务器的访问

默认情况下,NTP 服务器允许来自所有主机的查询。如果你想过滤进来的 NTP 同步连接,你可以在你的防火墙中添加规则过滤流量。

# iptables -A INPUT -s 192.168.1.0/24 -p udp --dport 123 -j ACCEPT

# iptables -A INPUT -p udp --dport 123 -j DROP

该规则允许从 192.168.1.0/24 来的 NTP 流量(端口 UDP/123),任何其它网络的流量会被丢弃。你可以根据需要更改规则。

配置 NTP 客户端

1. Linux

NTP 客户端主机需要 ntpupdate 软件包来和服务器同步时间。可以轻松地使用 yum 或 apt-get 安装这个软件包。安装完软件包之后,用服务器的 IP 地址运行下面的命令。

# ntpdate <server-IP-address>

基于 RHEL 和 Debian 的系统命令都相同。

2. Windows

如果你正在使用 Windows,在日期和时间设置(Date and Time settings)下查找网络时间(Internet Time)。

3. Cisco 设备

如果你想要同步 Cisco 设备的时间,你可以在全局配置模式下使用下面的命令。

# ntp server <server-IP-address>

来自其它厂家的支持 NTP 的设备有自己的用于网络时间的参数。如果你想将设备和 NTP服务器同步时间,请查看设备的说明文档。

结论

总而言之,NTP 是在你的所有主机上同步时钟的一个协议。我们已经介绍了如何设置 NTP 服务器并使支持 NTP 的设备和服务器同步时间。

与centos配置ntp服务器相关的知识