Linux NTP 服务器时间自动同步配置

本文以 CentOS 7.x 为准,由于系统默认时间同步服务器都在国外在某种原因下无法及时同步时间,最好的选择就是设置国内时间服务器地址进行同步。不用想了,当然国内某些云厂商提供的免费时间服务器是首选

开干

1. 编辑配置文件

sudo vim /etc/ntp.conf

找到服务器地址位置添加 阿里云免费NTP地址 ,大概是这样的

 19 # Use public servers from the pool.ntp.org project.
 20 # Please consider joining the pool (http://www.pool.ntp.org/join.html).
 21 server ntp.aliyun.com iburst
 22 server ntp1.aliyun.com iburst
 23 server ntp2.aliyun.com iburst
 24 server ntp3.aliyun.com iburst
 25 server ntp4.aliyun.com iburst
 26 server ntp5.aliyun.com iburst
 27 server ntp6.aliyun.com iburst
 28 server ntp7.aliyun.com iburst
 29 server 1.centos.pool.ntp.org iburst
 30 server 2.centos.pool.ntp.org iburst
 31 server 3.centos.pool.ntp.org iburst
 32 server 4.centos.pool.ntp.org iburst

2. 如果第一步发现没有这个配置文件则进行如下安装

yum install ntp

3. 设置开机启动

# 设置开机启动
systemctl enable ntpd

# 查看时间校准服务状态
systemctl status ntpd

systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since 六 2024-08-31 07:29:46 CST; 22min ago
 Main PID: 30806 (ntpd)
    Tasks: 2
   Memory: 1.7M
   CGroup: /system.slice/ntpd.service
           ├─30806 /usr/sbin/ntpd -u ntp:ntp -g -x
           └─30812 /usr/sbin/ntpd -u ntp:ntp -g -x

831 07:29:46 react-master ntpd[30806]: 0.0.0.0 c011 01 freq_not_set
831 07:29:46 react-master ntpd[30812]: signal_no_reset: signal 17 had flags 4000000
831 07:29:49 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org
831 07:29:53 react-master ntpd[30806]: 0.0.0.0 c614 04 freq_mode
831 07:30:51 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org
831 07:32:53 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org
831 07:36:56 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org
831 07:44:58 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org
831 07:45:27 react-master ntpd[30806]: 0.0.0.0 0612 02 freq_set ntpd -3.804 PPM
831 07:45:27 react-master ntpd[30806]: 0.0.0.0 0615 05 clock_sync

如果发现类似于这种的提示

831 07:30:51 react-master ntpd_intres[30812]: host name not found: 4.centos.pool.ntp.org

到配置文件 /etc/ntp.conf 中把相应的的服务器地址干掉就行!

4. 查看时间校准服务状态

ntpstat
synchronised to NTP server (84.16.67.12) at stratum 2
   time correct to within 622 ms
   polling server every 128 s

5. 查看NTP服务对等端的列表信息

这个操作是一个补充信息一般上面几步搞定就ok了

ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+203.107.6.88    10.137.55.181    2 u  629   64    0   26.341   -0.657   1.998
+120.25.115.20   10.137.53.7      2 u  598   64    0   37.088   -2.084   1.903
*tock.ntp.infoma .GPS.            1 u   72  128   17  353.763   -2.483 127.698
-ntp8.flashdance 194.58.202.20    2 u   31  128  377  393.844  -31.926 182.117
-time.cloudflare 10.129.8.7       3 u   22  128  377  266.988  -15.992 162.749

如果服务器在云厂商托管,记得使用云厂商提供的专业的内网服务!

  • 10
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值