Ubuntu20.04 Ntp服务安装及验证

最近需要在Ubuntu20.04 安装Ntp服务,以下是个人安装步骤,提供参考:

安装NTP服务

步骤一:更新并安装ntp

sudo apt-get update

sudo apt-get install ntp

步骤二:查看是否安装成功

sntp --version  

sntp 4.2.8p12@1.3728-o (1)

步骤三:修改ntp.conf配置文件,并添加如下配置

sudo vi /etc/ntp.conf

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

server 0.uk.pool.ntp.org iburst
server 1.uk.pool.ntp.org iburst
server 2.uk.pool.ntp.org iburst
server 3.uk.pool.ntp.org iburst

server 127.127.1.0 #local clock
fudge 127.127.1.0 stratum 10

步骤四:重启ntp服务

sudo systemctl restart ntp

步骤五:查看ntp服务状态

sudo systemctl status ntp
● ntp.service - Network Time Service
     Loaded: loaded (/lib/systemd/system/ntp.service; enabled; vendor preset: enabled)
     Active: active (running) since Thu 2022-05-05 16:45:10 CST; 56min ago
       Docs: man:ntpd(8)
    Process: 2244581 ExecStart=/usr/lib/ntp/ntp-systemd-wrapper (code=exited, status=0/SUCCESS)
   Main PID: 2244589 (ntpd)
      Tasks: 2 (limit: 38340)
     Memory: 820.0K
     CGroup: /system.slice/ntp.service
             └─2244589 /usr/sbin/ntpd -p /var/run/ntpd.pid -g -u 128:134

505 16:45:10 ubuntu ntpd[2244589]: Listening on routing socket on fd #22 for interface updates
505 16:45:10 ubuntu ntpd[2244589]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
505 16:45:10 ubuntu ntpd[2244589]: kernel reports TIME_ERROR: 0x2041: Clock Unsynchronized
505 16:45:42 ubuntu ntpd[2244589]: Soliciting pool server 91.189.94.4
505 16:45:42 ubuntu ntpd[2244589]: Soliciting pool server 91.189.89.198
505 16:45:43 ubuntu ntpd[2244589]: Soliciting pool server 91.189.89.199
505 16:45:44 ubuntu ntpd[2244589]: Soliciting pool server 91.189.91.157
505 16:46:52 ubuntu ntpd[2244589]: Soliciting pool server 2001:67c:1560:8003::c8
505 16:47:59 ubuntu ntpd[2244589]: Soliciting pool server 2001:67c:1560:8003::c7
505 16:49:11 ubuntu ntpd[2244589]: Soliciting pool server 91.189.91.157

ntp服务客户端测试

说明:以下验证流程中,192.168.10.142是用来测试ntp的客户端,下载及验证都是在客户端,192.168.10.213 为ntp server的IP地址,
步骤一. 下载客户端

sudo apt install ntpdate

步骤二.在host文件中指定NTP服务的ip和主机名

sudo vi /etc/hosts

#添加以下配置
192.168.10.213    NTP-server-host

步骤三:使用ntpdate + 主机名 检查是否同步

sudo ntpdate NTP-server-host

如果成功同步的话,会在ntp客户端看到与ntp服务的时间差。
Ubuntu20.04 Ntp服务安装及验证_第1张图片

你可能感兴趣的:(linux,linux)