关于ubuntu18.04:Ubuntu-1804-ntp-的入门配置

8次阅读

共计 2122 个字符,预计需要花费 6 分钟才能阅读完成。

配置前的几个留神点

自己应用 root 权限做测试,权限不够自行 sudo

零碎时钟设置

# 零碎工夫查看
date
-------------------------------------------------------------
# 零碎工夫设置
date -s "YYYY-MM-DD hh:mm:ss"
e.g.
date -s "2020-10-15 10:20:15"

硬件时钟

# 硬件时钟查看
hwclock 
-----------------------------------------------------------
# 硬件时钟同步零碎时钟(改了硬件时钟)hwclock -w
-----------------------------------------------------------
# 零碎时钟同步硬件时钟(改了零碎时钟)hwclock -h

Ubuntu 自带的工夫同步行为

Ubuntu 自身自带 ntp 来更新工夫,如有必要,须要自行敞开

# 敞开自带的更新性能
timedatectl set-ntp no  # yes 为开启(不胜利就 yes/no 重复几次)-----------------------------------------------------------
# 查看 timedatectl 性能是否胜利敞开
timedatectl status
# 后果       
       System clock synchronized: no
systemd-timesyncd.service active: no
                 RTC in local TZ: no

ntp 配置

ntp 装置

# serve(提供同步工夫) 端
sudo apt-get install ntp  
-----------------------------------------------------------
# client(申请同步) 端
sudo apt-get install ntpdate

集群中提供同步(serve)配置

1. 配置 ntp.conf 文件

vim /etc/ntp.conf
-----------------------------------------------------------
文件两头(批改)# Clients from this (example!) subnet have unlimited access, but only if
# cryptographically authenticated.
restrict 192.168.50.0 mask 255.255.255.0 nomodify notrip

文件任意地位(增加)server 127.127.1.0
fudge 127.127.1.0 stratum 10

2. 启动 ntp 服务

/etc/init.d/ntp restart

3. 查看服务是否正确启动

watch ntpq -p
-------------------------------------------------------------------------------
后果相似于:remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp.ubuntu.com  .POOL.          16 p    -   64    0    0.000    0.000   0.000
 LOCAL(0)        .LOCL.          10 l  150   64   74    0.000    0.000   0.000
+golem.canonical 134.71.66.21     2 u    4   64   75  319.753    8.247  25.024
 alphyn.canonica 132.163.96.1     2 u    3   64   17  277.850   30.059  30.159
*pugot.canonical 17.253.108.125   2 u    6   64   57  298.084   31.296  35.446
+chilipepper.can 17.253.108.253   2 u   13   64   37  313.275   16.580  32.254

集群中申请同步(client)配置

1. 应用 ntpdate 申请服务(服务启动须要一段时间)

ntpdate hadoop0(服务对应域名 /ip)
------------------------------------------------------------------------------------------
16 Oct 23:15:49 ntpdate[6920]: adjust time server 192.168.50.100 offset 0.088294 sec

2. 应用 crontab 实现定时同步申请工作

crontab -e
*/1 * * * * /usr/sbin/ntpdate hadoop0

可能呈现的问题

16 Oct 22:59:49 ntpdate[2392]: no server suitable for synchronization found
# 这很可能是服务还未启动好,须要急躁期待 5 -10 分钟
# 除此之外,还有可能是防火墙 / 配置文件存在 notrust 属性
# restrict 192.168.50.0 mask 255.255.255.0 notrust
正文完
 0