配置内网ntp服务

一 . 内网NTP-Server(192.168.1.12)

备份配置文件

cp /etc/ntp.conf /etc/ntp.conf.bak

改配置文件

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).

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 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 ::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 (http://www.pool.ntp.org/join.html).

# 注释掉
# server 0.centos.pool.ntp.org iburst
# server 1.centos.pool.ntp.org iburst
# server 2.centos.pool.ntp.org iburst
# server 3.centos.pool.ntp.org iburst

#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 4 8 42

# Specify the key identifier to use with the ntpdc utility.
#requestkey 8

# Specify the key identifier to use with the ntpq utility.
#controlkey 8

# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats

# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
disable monitor

# 下面2行, 以本地时间作为时间服务
server 127.127.1.0 

fudge 127.127.1.0 stratum 10


开启服务端口:

firewall-cmd  --zone=public --add-port=123/udp --permanent
firewall-cmd --reload

start启动服务,enable 开机启动, status查看状态。


systemctl start ntpd.service
systemctl enable ntpd.service
systemctl status ntpd.service

查看ntpd端口情况

[root@node1 ~]# ss -tlunp |grep ntp
udp    UNCONN     0      0      192.168.1.12:123                   *:*                   users:(("ntpd",pid=114741,fd=19))
udp    UNCONN     0      0      127.0.0.1:123                   *:*                   users:(("ntpd",pid=114741,fd=18))
udp    UNCONN     0      0         *:123                   *:*                   users:(("ntpd",pid=114741,fd=16))
udp    UNCONN     0      0      fe80::8c4a:435d:d7ec:6826%ens33:123                  :::*                   users:(("ntpd",pid=114741,fd=21))
udp    UNCONN     0      0       ::1:123                  :::*                   users:(("ntpd",pid=114741,fd=20))
udp    UNCONN     0      0        :::123                  :::*                   users:(("ntpd",pid=114741,fd=17))

ntpq -p 查看网络中的NTP服务器,同时显示客户端和每个服务器的关系

# ntpq -p

改时间

date -s 18:00:00

二 . 内网NTP-Clients(192.168.1.13)

备份配置文件

cp /etc/ntp.conf /etc/ntp.conf.bak

改配置文件

vim /etc/ntp.conf  

#改成相对应的服务器,把下面的注释掉

server 192.168.1.12 iburst
#server 1.centos.pool.ntp.org iburst
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst

多台ntp的情况

客户端配置
driftfile /var/lib/ntp/drift
server 192.168.8.102 prefer
server 192.168.8.101
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

start启动服务,enable 开机启动, status查看状态。

systemctl start ntpd.service
systemctl enable ntpd.service
systemctl status ntpd.service

查看时间

date

查看网络中的NTP服务器

ntpq -p
[root@node2 /etc]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*node1           LOCAL(0)        11 u   62   64   77    2.050   -2.689   2.395

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 一、项目目标 搭建一个高可用web集群网站 二、项目规划 2.1 ip地址规划 2.2 拓扑图 2.3 相关说明 ...
    夏日之光阅读 3,759评论 0 1
  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,854评论 18 139
  • 本人陆陆续续接触了ELK的1.4,2.0,2.4,5.0,5.2版本,可以说前面使用当中一直没有太多感触,最近使用...
    三杯水Plus阅读 4,118评论 0 12
  • 我和东野圭吾的恋爱状态已经持续了四年,这是我的“初恋”,这种感觉是梦幻的,美妙又令人陶醉。让我深陷其中而不能自拔,...
    残花人阅读 302评论 0 0
  • 运动我喜欢流汗的感觉,特别是大汗淋漓的样子。每次运动完流了汗,神清气爽。 运动,不是别人说跑步好就去跑步,要找到自...
    华花HY阅读 257评论 0 4