在工作中,内网环境机器的时间会有所差异,在某些测试环境下需要一毫秒都不允许出现误差,但又不想同步外网时间,那我们可以选择一台机器作为时间服务器来供其他机器进行时间同步,例如每隔1分钟同步一次时间。

一、环境

系统:Centos 6.5

ntp_client IP:192.168.0.117

ntp_server IP:192.168.0.124

二、安装ntp服务

root@fenfa ~]# yum install ntp -y
[root@fenfa ~]# chkconfig --add ntpd
[root@fenfa ~]# chkconfig ntpd on

三、配置/etc/ntp.conf文件:

server:

[root@fenfa ~]# vim /etc/ntp.conf 

   # For more information about this file, see the man pages
# ntp.conf(), ntp_acc(), ntp_auth(), ntp_clock(), ntp_misc(), ntp_mon(). 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 notrap nopeer noquery #默认的client拒绝所有的操作
restrict - 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 - :: # Hosts on local network are less restricted.
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap #允许集群192.1680.0网段连接同步时间,拒绝client修改服务器时间
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
22 #server 0.centos.pool.ntp.org iburst #默认配置,同步网络时间
23 #server 1.centos.pool.ntp.org iburst
24 #server 2.centos.pool.ntp.org iburst
25 #server 3.centos.pool.ntp.org iburst 27 server 127.127.1.0 #本地时间
28 fudge 127.127.1.0 stratum 1 #时间服务器的层次。设为0则为顶级 #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 # Specify the key identifier to use with the ntpdc utility.
#requestkey # Specify the key identifier to use with the ntpq utility.
#controlkey # Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

注:红色字体的地方为新增或修改的部分

client:

[root@nfs ~]# vim /etc/ntp.conf 

# For more information about this file, see the man pages
# ntp.conf(), ntp_acc(), ntp_auth(), ntp_clock(), ntp_misc(), ntp_mon(). 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 notrap nopeer noquery
restrict - 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 - :: # Hosts on local network are less restricted.
restrict 192.168.0.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 .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst
#server .centos.pool.ntp.org iburst server 192.168.0.124 profer #时间服务器地址
#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 # Specify the key identifier to use with the ntpdc utility.
#requestkey # Specify the key identifier to use with the ntpq utility.
#controlkey # Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstat

四、设置client主机与时间服务器时间的同步

  • serverd端从启ntp服务
  • client端更改系统时间
  • 执行同步命令:ntpdate -u 192.168.0.124
[root@fenfa x86_64]# service ntpd restart
关闭 ntpd: [确定]
正在启动 ntpd: [确定]
[root@nfs ~]# date
2019年 08月 19日 星期一 :: CST
[root@nfs ~]# date -s --
2018年 08月 19日 星期日 :: CST
[root@nfs ~]# date
2018年 08月 19日 星期日 :: CST
[root@nfs ~]# ntpdate -u 192.168.0.124
Aug :: ntpdate[]: step time server 192.168.0.124 offset 31614767.907398 sec
[root@nfs ~]# date
2019年 08月 19日 星期一 :: CST

可以在client机器上编写一个定时脚本:

[root@nfs ~]# crontab -l
####ntpd Synchronize every minute
-/ * * * * /usr/sbin/ntpdate -u 192.168.0.124 >/dev/null >&

修改/etc/ntp/stpe-tickers文件,内容如下(当ntpd服务启动时,会自动与该文件中记录的上层NTP服务进行时间校对

[root@nfs ~]# cat /etc/ntp/step-tickers
# List of servers used for initial synchronization.
server 192.168.0.124 prefer

ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。

linux 内网时间同步配置的更多相关文章

  1. Linux内网渗透

    Linux虽然没有域环境,但是当我们拿到一台Linux 系统权限,难道只进行一下提权,捕获一下敏感信息就结束了吗?显然不只是这样的.本片文章将从拿到一个Linux shell开始,介绍Linux内网渗 ...

  2. FtpServer穿透内网访问配置踩笔记

    FtpServer穿透内网访问配置踩笔记 引言 FtpServer是服务器文件远程管理常用方式. 以前在局域网配置Ftp服务器以及使用公网上的Ftp服务均未碰到问题,固未对Ftp传输进行深入了解. 然 ...

  3. Linux内网时钟同步问题(ntp和chrony)

    我们都知道时钟同步可以使用外网服务器,在内网内不能连接外网的时候也需要时钟同步,那怎么进行呢? 选择内网的一台稳定的服务器作为时钟源,然后让其他机器都来同步这台机器即可. 注:其实ntp服务和chro ...

  4. Linux内网环境DNS修改域名指向,JAVA应用程序能否实时切换的问题总结

    公司内网环境中许多调用资源(数据库.web接口等)都是通过内网DNS服务来进行域名-IP的映射. 但经常出现DNS映射修改完毕后,应用中连接的资源迟迟没有变更. 以前一直笼统的认为是linux的dns ...

  5. 记录一次坎坷的linux内网渗透过程瞎折腾的坑

    版权声明:本文为博主的原创文章,未经博主同意不得转载. 写在前面 每个人都有自己的思路和技巧,以前遇到一些linux的环境.这次找来一个站点来进行内网,写下自己的想法 目标环境 1.linux  2. ...

  6. 配置B类内网 和 配置A类内网

    首先 A 类网 对应的 子网掩码是255.0.0.0 B 类网 对应的 子网掩码是255.255.0.0 C 类网 对应的 子网掩码是255.255.255.0 一般来说 10 开头的都是 A 类网  ...

  7. CentOS7设置内网时间同步

    1.yum 安装 NTP服务器 [root@master ~]# yum -y install ntp 2.启动ntpd服务 [root@master ~]# systemctl start ntpd ...

  8. linux内网机器访问外网代理设置squid

    公司一般出于安全考虑, 在同一局域网中只有一台机器可以访问外网,运维进行了整体的限制, 但是在后面的工作中,需要在机器上安装一些软件,及命令,所以其他的机器需要访问外网来简化工作, 但又不能打乱原有运 ...

  9. frp内网穿透配置

    frps配置 --------------------------------------------------------------------------------------------- ...

随机推荐

  1. Python10个图像处理工具

    原文地址:https://cloud.tencent.com/developer/article/1498116 译者 | 小韩 来源 | towardsdatascience [磐创AI导读]:本篇 ...

  2. mysql 如何减少InnoDB关闭时间

    原文连接: https://www.percona.com/blog/2009/04/15/how-to-decrease-innodb-shutdown-times/ 有时,运行InnoDB的MyS ...

  3. 爬虫中Requests模块

    Requests: 让 HTTP 服务人类 虽然Python的标准库中 urllib2 模块已经包含了平常我们使用的大多数功能,但是它的 API 使用起来让人感觉不太好,而 Requests 自称 “ ...

  4. Zookeeper 安装与简单使用

    一.安装Zookeeper 其实Zookeeper的安装特别简单,也不能算安装了,只需要将Zookeeper下载后解压,就完成了安装操作. 下载地址:http://zookeeper.apache.o ...

  5. Cannot start service WMSvc on computer '.'.

    批处理,管理员权限执形 taskkill /im wmsvc.exe /f net stop WMSVC net start WMSVC pause

  6. python调用kafka服务(使用kafka-python库)

    试验环境: CDH 5.15.1 CentOS 7 Python 3.7.0 kafka 1.1.1 kafka-python :https://pypi.org/project/kafka-pyth ...

  7. 机动车驾驶(1)--- 禁令标志汇总 by John

    以下是普通标志牌(新车安全)

  8. [LeetCode] 34. Search for a Range 搜索一个范围(Find First and Last Position of Element in Sorted Array)

    原题目:Search for a Range, 现在题目改为: 34. Find First and Last Position of Element in Sorted Array Given an ...

  9. rabbitmq设置消息优先级、队列优先级配置

    1.首先在consume之前声明队列的时候,要加上x-max-priority属性,一般为0-255,大于255出错  -----配置队列优先级 配置成功后rabbitmq显示: 2.在向exchan ...

  10. springboot获取上下文ApplicationContext

    在springboot主程序里改成 public static void main(String[] args) { // SpringApplication.run(SpringbootAPP.cl ...