linux 内网时间同步配置

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

一、环境

系统:Centos 6.5

ntp_client IP:192.168.0.117

ntp_server IP:192.168.0.124

二、安装ntp服务

[email protected] ~]# yum install ntp -y
[[email protected] ~]# chkconfig --add ntpd
[[email protected] ~]# chkconfig ntpd on

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

server:

[[email protected] ~]# vim /etc/ntp.conf 

  1 # For more information about this file, see the man pages
  2 # ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
  3
  4 driftfile /var/lib/ntp/drift
  5
  6 # Permit time synchronization with our time source, but do not
  7 # permit the source to query or modify the service on this system.
  8 restrict default kod nomodify notrap nopeer noquery #默认的client拒绝所有的操作
  9 restrict -6 default kod nomodify notrap nopeer noquery
 10
 11 # Permit all access over the loopback interface.  This could
 12 # be tightened as well, but to do so would effect some of
 13 # the administrative functions.
 14 restrict 127.0.0.1 #允许本机地址一切的操作
 15 restrict -6 ::1
 16
 17 # Hosts on local network are less restricted.
 18 restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap  #允许集群192.1680.0网段连接同步时间,拒绝client修改服务器时间19
 20 # Use public servers from the pool.ntp.org project.
 21 # 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
 26
 27 server 127.127.1.0  #本地时间
 28 fudge 127.127.1.0 stratum 1 #时间服务器的层次。设为0则为顶级
 29
 30 #broadcast 192.168.1.255 autokey        # broadcast server
 31 #broadcastclient                        # broadcast client
 32 #broadcast 224.0.1.1 autokey            # multicast server
 33 #multicastclient 224.0.1.1              # multicast client
 34 #manycastserver 239.255.254.254         # manycast server
 35 #manycastclient 239.255.254.254 autokey # manycast client
 36
 37 # Enable public key cryptography.
 38 #crypto
 39
 40 includefile /etc/ntp/crypto/pw
 41
 42 # Key file containing the keys and key identifiers used when operating
 43 # with symmetric key cryptography.
 44 keys /etc/ntp/keys
 45
 46 # Specify the key identifiers which are trusted.
 47 #trustedkey 4 8 42
 48
 49 # Specify the key identifier to use with the ntpdc utility.
 50 #requestkey 8
 51
 52 # Specify the key identifier to use with the ntpq utility.
 53 #controlkey 8
 54
 55 # Enable writing of statistics records.
 56 #statistics clockstats cryptostats loopstats peerstats

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

client:

[[email protected] ~]# vim /etc/ntp.conf 

# 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).
  3
  4 driftfile /var/lib/ntp/drift
  5
  6 # Permit time synchronization with our time source, but do not
  7 # permit the source to query or modify the service on this system.
  8 restrict default kod nomodify notrap nopeer noquery
  9 restrict -6 default kod nomodify notrap nopeer noquery
 10
 11 # Permit all access over the loopback interface.  This could
 12 # be tightened as well, but to do so would effect some of
 13 # the administrative functions.
 14 restrict 127.0.0.1
 15 restrict -6 ::1
 16
 17 # Hosts on local network are less restricted.
 18 restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
 19
 20 # Use public servers from the pool.ntp.org project.
 21 # 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
 26
 27 server 192.168.0.124 profer #时间服务器地址28
 29 #broadcast 192.168.1.255 autokey        # broadcast server
 30 #broadcastclient                        # broadcast client
 31 #broadcast 224.0.1.1 autokey            # multicast server
 32 #multicastclient 224.0.1.1              # multicast client
 33 #manycastserver 239.255.254.254         # manycast server
 34 #manycastclient 239.255.254.254 autokey # manycast client
 35
 36 # Enable public key cryptography.
 37 #crypto
 38
 39 includefile /etc/ntp/crypto/pw
 40
 41 # Key file containing the keys and key identifiers used when operating
 42 # with symmetric key cryptography.
 43 keys /etc/ntp/keys
 44
 45 # Specify the key identifiers which are trusted.
 46 #trustedkey 4 8 42
 47
 48 # Specify the key identifier to use with the ntpdc utility.
 49 #requestkey 8
 50
 51 # Specify the key identifier to use with the ntpq utility.
 52 #controlkey 8
 53
 54 # Enable writing of statistics records.
 55 #statistics clockstats cryptostats loopstats peerstat

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

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

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

[[email protected] ~]# crontab -l
####ntpd  Synchronize every 1 minute
00-59/60 * * * * /usr/sbin/ntpdate -u 192.168.0.124 >/dev/null 2>&1

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

[[email protected] ~]# 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 这样,就可以让硬件时间与系统时间一起同步。

原文地址:https://www.cnblogs.com/su-root/p/11380198.html

时间: 2024-08-30 03:02:01

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

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

1.检查机器 在操作中发现访问外网的机器本身不能使用yum 安装软件,故需要配置yum安装源.如果可以的,这步可忽略. [[email protected] test]# lsb_release -a LSB Version:    :core-4.0-amd64:core-4.0-ia32:core-4.0-noarch:graphics-4.0-amd64:graphics-4.0-ia32:graphics-4.0-noarch:printing-4.0-amd64:printing-4.

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

我们都知道时钟同步可以使用外网服务器,在内网内不能连接外网的时候也需要时钟同步,那怎么进行呢? 选择内网的一台稳定的服务器作为时钟源,然后让其他机器都来同步这台机器即可. 注:其实ntp服务和chrony服务本质上差不多,他们之间都可以互相进行同步.不过为了避免不必要的麻烦,一般服务器都只选择同一时钟服务来讲进行同步. 一.ntp服务 安装: yum install ntp 1.服务端设置 修改配置文件cat /etc/ntp.conf 将如下外网的时钟源注释掉(前面加#) 如果这台作为内网时钟

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

写在前面 每个人都有自己的思路和技巧,以前遇到一些linux的环境.这次找来一个站点来进行内网,写下自己的想法 目标环境 1.linux  2.6.32-358  cpu 架构(x86_64)AND发行版 Red Hat Enterprise Linux Server release 6.4 2.DMZ+防火墙+行为监控,外网开放8080 8084 ... 3.服务器有utibadn用户的权限一枚 Shell具体怎么拿到的就不说了,记录下自己比较思路坎坷的一次内网渗透以作回顾: 外网nmap得到

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

公司内网环境中许多调用资源(数据库.web接口等)都是通过内网DNS服务来进行域名-IP的映射. 但经常出现DNS映射修改完毕后,应用中连接的资源迟迟没有变更. 以前一直笼统的认为是linux的dns缓存导致,今天做了一次完整的分析,结果如下: 1.Linux系统的本地DNS的缓存 CentOS系统本身并不包含DNS的缓存机制,除非安装并启动了nscd服务(name server cache daemon). nscd服务启动后会默认为本地的所有dns解析做一层缓存,过期时间默认为3600秒,重

linux外网电子邮件配置

linux第三方电子邮件配置 很多情况下我们需要linux发送一下定时任务执行的日志,或者备份失败的消息日志到我们指定的邮箱,此时需要配置linux的邮件服务postfix 或者用第三方邮件,这里介绍第三方邮件的linux配置方法, 以本人邮箱[email protected]为例: 配置文件/etc/mail.rc 追加以下内容: cat>>/etc/mail.rc<<eof set [email protected] set smtp=smtp.qq.com set smtp-

Android Studio官方推荐内网离线配置

TODO 参考:https://developer.android.com/studio/intro/studio-config 版本:Android Studio 3.5.1 官方离线组件版本:[email protected], gm[email protected] 按照本文下方复制的官方推荐方法配置好后,部分问题就解决了. 接下来会遇到gradle版本问题.自行下载所需的gradle版本.解压到本地目录${GRADLE_ROOT}.打开设置File -> Settings -> Bui

ntp内网时间同步(基于centos6.5)

服务器端: 安装ntp yum install ntp 编辑配置文件 vi /etc/ntp.conf 添加 restrict 192.168.10.0 mask 255.255.255.0 nomodify notrap server time-b.nist.gov 其他server都注释掉 vi /etc/sysconf/iptables 添加iptables规则 -A  INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCE

内网DNS配置

yum install bind bind-chroot [[email protected] named]# cat /etc/named.confoptions {        directory       "/var/named";           }; zone "." IN {        type hint;        file "named.ca";}; zone "localhost" IN { 

内网ntp时间同步配置

选择局域网中的一台机器作为ntp服务器,在ntp server上安装并启动ntpd客户端上要关闭ntpd,安装ntpdateCentOS7上这两个软件都是自带的,只需根据需要打开或者关闭.注意客户端机器的ntpd必须关闭 修改ntp服务器上的/etc/ntp.conf,加上以下的配置: server 127.127.1.0 #local clock fudge 127.127.1.0 stratum 5 后面哪个数字在0-15之间都可以,这样就将这台机器的本地时间作为ntp服务提供给客户端 重启