linux设置ntp时间同步

NTP时钟同步方式说明

NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步:
直接同步
使用ntpdate命令进行同步,直接进行时间变更。如果服务器上存在一个12点运行的任务,当前服务器时间是13点,但标准时间时11点,使用此命令可能会造成任务重复执行。因此使用ntpdate同步可能会引发风险,因此该命令也多用于配置时钟同步服务时第一次同步时间时使用。
平滑同步
使用ntpd进行时钟同步,可以保证一个时间不经历两次,它每次同步时间的偏移量不会太陡,是慢慢来的,这正因为这样,ntpd平滑同步可能耗费的时间比较长。

1、安装ntp

yum install ntp

2、设置ntp服务开机启动

systemctl  restart ntp.service

3、设置服务器

3.1. vi /etc/ntp.conf,内容如下:

driftfile /var/lib/ntp/ntp.drift #草稿文件

# 允许内网其他机器同步时间

restrict 192.168.137.0(替换成自己的ip) mask 255.255.255.0 nomodify notrap

# Use public servers from the pool.ntp.org project.

# 中国这边最活跃的时间服务器 :

[http://www.pool.ntp.org/zone/cn](http://www.pool.ntp.org/zone/cn)

server 210.72.145.44 perfer   # 中国国家受时中心

server 202.112.10.36             # 1.cn.pool.ntp.org

server 59.124.196.83             # 0.asia.pool.ntp.org  

# allow update time by the upper server

# 允许上层时间服务器主动修改本机时间

restrict 210.72.145.44 nomodify notrap noquery

restrict 202.112.10.36 nomodify notrap noquery

restrict 59.124.196.83 nomodify notrap noquery  

# 外部时间服务器不可用时,以本地时间作为时间服务

server  127.127.1.0     # local clock

fudge   127.127.1.0 stratum 10

3.2 重启服务:service ntpd restart

3.3查看同步状态:netstat -tlunp | grep ntp

4、设置同步

4.1 vim /etc/ntp.conf,内容如下:

driftfile /var/lib/ntp/ntp.drift # 草稿文件

statsdir /var/log/ntpstats/

statistics loopstats peerstats clockstats

filegen loopstats file loopstats type day enable

filegen peerstats file peerstats type day enable

filegen clockstats file clockstats type day enable

#让NTP Server为内网的ntp服务器

server 192.168.137.110 (master节点ip)

fudge 192.168.137.110 stratum 5

#不允许来自公网上ipv4和ipv6客户端的访问

restrict -4 default kod notrap nomodify nopeer noquery

restrict -6 default kod notrap nomodify nopeer noquery

#Local users may interrogate the ntp server more closely.

restrict 127.0.0.1

restrict ::1

4.2重启服务:service ntpd restart

4.3手动同步:ntpdate -u 192.168.124.146

原文地址:https://blog.51cto.com/14259167/2427537

时间: 2024-08-30 00:03:50

linux设置ntp时间同步的相关文章

关于linux下ntp时间同步服务的安装与配置

1.安装ntp服务,要使用时间同步.那么服务端与客户端都需要使用如下命令安装NTP软件包 [[email protected]5201351 ~]# yum install ntp -y 2.如果只是作为客户端的话,配置则可以非常简单,编辑/etc/ntp.conf文件,注释掉默认的如下默认的4行       再加上我们的时间同步服务端的IP地址或者域名即可,其中prefer选项表示该服务器优先 #server 0.centos.pool.ntp.org iburst #server 1.cen

linux中设置ntp时间同步

NTP全称为Network Time Protocol,即网络时间协议.是用来使计算机时间同步的一种协议.它可以使计算机对服务器或时钟源做同步,可以提供高精度的时间校正(LAN 上与标准时间小于1毫秒,WAN上几十毫秒),而且可以由加密确认的方式防止恶意的协议***. 实验环境两台虚拟机 NTP时间服务器 192.168.43.57主机 192.168.43.29 服务端 安装ntp yum install -y ntp 编辑配置文件 vim /etc/ntp.conf 将这行给注释#restr

Linux下ntp时间同步

在root用户下执行 先安装同步时间软件,每台机器执行 yum install -y ntp 然后执行以下命令: crontab -e */10 * * * * /usr/sbin/ntpdate -u time.nist.gov 然后保存退出 esc  :wq service crond restart 验证:过十分钟后 所有节点时间和网络时间同步 date命令查看

Linux 搭建NTP时间同步服务器

1.下载NTP时间软件 2.配置上海滩时区 3.启动这个时间软件,并开机自启动 4.手动设置个时间,关闭红帽提供的同步时间 5.打开配置文件配置,重启时间服务然后服务端已经配置好了 6.客户端也装上NTP时间软件,然后打开配置文件,注释掉默认同步项,同时再下一行手写一个时间服务地址 7.时间服务器搭建成功! 原文地址:http://blog.51cto.com/kangxi/2115344

Linux/Centos ntp时间同步,联网情况和无网情况配置

机器联网: 如果服务器可以联网:执行 ntpdate 1.cn.pool.ntp.org 服务器就会自动同步时间 写一个计划任务 每俩分钟执行一次时间同步; crontab -e /2 * /usr/sbin/ntpdate 1.cn.pool.ntp.org //这样就可以实现时间同步 下面是国内的NTP Server1.cn.pool.ntp.org2.cn.pool.ntp.org3.cn.pool.ntp.org0.cn.pool.ntp.orgcn.pool.ntp.orgtw.poo

linux配置ntp时间同步

一.安装ntf yum –y ×××tall ntp 二.配置ntp服务1)修改所有节点的/etc/ntp.conf vi /etc/ntp.confrestrict 172.18.74.59 nomodify notrap nopeer noquery //当前节点IP地址restrict 172.18.74.253 mask 255.255.255.0 nomodify notrap //集群所在网段的网关(Gateway),子网掩码(Genmask) 2)修改主节点/etc/ntp.con

Linux下 ntp 时间同步服务ntpd 出现 the NTP socket is in use, exiting 解决

1.出现"the NTP socket is in use, exiting"错误.造成该原因是系统ntpd服务器正在运行中,可以通过 ps aux | grep ntpd 查看,如果还是要手动同步时间,就必须先停止该服务,命令为:service ntpd stop 或 /etc/init.d/ntpd stop 2.npdate time.windows.com或ntpdate us.pool.ntp.org 就能够同步时间成功了.

Linux下快速搭建ntp时间同步服务器

背景: 服务器多了,时间是否一致以及是否准备就显得格外重要,虽然这个问题总是被忽略,但是统一时间是很有必要的,因为时间问题导致服务出现问题也是司空见惯,本文简单介绍一下ntp的快速搭建和使用. 1.  安装ntp yum -y install ntp(直接yum安装即可) 2.  修改ntp.conf的配置 1)vim /etc/ntp.conf ①   配置方法一:只允许192.168.100.0网段的客户机进行时间同步 在restrict default kod nomodify notra

Linux杂记-配置ntp时间同步服务

概念 NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议. 安装 目标 现集群有三台主机,分别为centos7-1,centos7-2,centos7-3. centos7-1作为master,同步硬件时间. centos7-2,centos7-3同步centos7-1的时间. 安装ntp 三台主机分别安装ntp,并设置一个初始时间. yum -y install ntp date -s '2018-05-04 00:00:00' 修改/