计算机网络/计算机科学与应用/系统/运维/开发

ntp同步linux服务器网络时间

NTP 网络时间协议Network Time Protocol,网络同步计算机系统之间的时钟,可使组织中的全部服务器保持同步,以准确时间执行基于时间的做业,NTP 客户端会将其时钟与 NTP 服务器同步


两种同步方式:

第一种是 安装 ntpd

一、使用命令 ntpq -p 查看状态

[root@VM-4-2-centos ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*169.254.0.79    9.20.184.92      2 u  208 1024  377    2.633   -0.066   0.475
+169.254.0.80    9.20.184.92      2 u 1047 1024  377    1.614    0.053   0.328
+169.254.0.81    9.20.184.92      2 u   35 1024  377    1.573    0.940   0.965
-169.254.0.82    9.20.184.92      2 u  462 1024  377    1.571    0.984   0.950
+169.254.0.83    9.20.184.92      2 u  788 1024  377    1.386    0.503   0.531


安装ntp

# 安装NTP
yum install ntp -y


启动ntp服务

# systemctl start ntpd
# systemctl enable ntpd


查看ntp服务

# systemctl status ntpd


二、修改ntp.conf配置文件

[root@a /]# vim /etc/ntp.conf
[root@a /]# grep server /etc/ntp.conf 
# Use public servers from the pool.ntp.org project.
#server 0.centos.pool.ntp.org iburst
server ntp.aliyun.com iburst
#broadcast 192.168.1.255 autokey# broadcast server
#broadcast 224.0.1.1 autokey# multicast server
#manycastserver 239.255.254.254# manycast server

 

重启ntp服务

# systemctl restart ntpd


检查同步状态

# ntpq -p


第二种ntpdate 

ntpdate同步时间,输入命令 ntpdate pool.ntp.org

# ntp校准命令 pool.ntp.org 时钟同步器
# ntpdate pool.ntp.org 
# 查看服务器时间
# ntpdate


三、查看状态

[root@VM-4-2-centos ~]# timedatectl
      Local time: Thu 2023-05-18 16:22:46 CST
  Universal time: Thu 2023-05-18 08:22:46 UTC
        RTC time: Thu 2023-05-18 08:22:46
       Time zone: Asia/Shanghai (CST, +0800)
     NTP enabled: no
NTP synchronized: yes
 RTC in local TZ: no
      DST active: n/a


所谓坚持,就是从种子种下到开花结果需要等待的时间。

评论

^