時間篇之centos7修復ntpq: read: Connection refused


 關於ntp同步時間, 由於是解決問題,所以理論性內容不多。

 關於UTC
NTP要提供准確的時間,就必須有准確的時間來源,那可以用格林尼治時間嗎?答案是否定的。 因為格林尼治時間是以地球自轉為基礎的時間計量系統,但是地球每天的自轉是有些不規則的, 而且正在緩慢加速,因此,格林尼治時間已經不再被作為標准時間使用。 新的標准時間,是由原子鍾報時的國際標准時間UTC(Universal Time Coordinated,世界協調時)。 而NTP獲得UTC的時間來源可以是原子鍾、天文台、衛星,也可以從Internet上獲取。

  關於Stratum

  在NTP中,定義了時間按照服務器的等級傳播,
  按照離外部UTC源遠近將所有的服務器歸入不同的Stratum(層)中,
  例如把通過GPS(Global Positioning System,全球定位系統)取得發送標准時間的服務器叫Stratum-1的NTP服務器,
  而Stratum-2則從Stratum-1獲取時間,Stratum-3從Stratum-2獲取時間,
  以此類推,但Stratum層的總數限制在15以內。
  所有這些服務器在邏輯上形成階梯式的架構相互連接,
  而Stratum-1的時間服務器是整個系統的基礎,

  計算機主機一般同多個時鍾服務器連接,利用統計學的算法過濾來自不同服務器的時間,以選擇最佳的路徑和來源以便校正主機時間。
  即使在主機長時間無法與某一時鍾服務器聯系的情況下,NTP服務依然可以有效運轉。

 

系統采樣

[root@ht8 ~]# cat /etc/redhat-release 
CentOS Linux release 7.9.2009 (Core)
[root@ht8 ~]# uname -r
3.10.0-1160.45.1.el7.x86_64

一、ntpd(ntp服務之一)

查看同步情況

[root@ht8 ~]# ntpq -p
ntpq: read: Connection refused

[root@ht8 ~]# ntpstat
Unable to talk to NTP daemon. Is it running?

基本上用這兩條命令就可以斷定,ntpd是沒有運行的,當然還可以用下面的命令

[root@ht8 ~]# ps -ef | grep ntpd
root 116397 94921 0 17:45 pts/1 00:00:00 grep --color=auto ntpd

查看ntpd配置文件(注意 /etc/sysconf/ntpd 這個文件是啟動命令的配置文件)

[root@ht8 ~]# cat /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

  #其中parameter的參數主要有:
  #ignore   : 拒絕所有類型的ntp連接
  #nomodify : 客戶端不能使用ntpc與ntpq兩支程式來修改服務器的時間參數
  #noquery  : 客戶端不能使用ntpq、ntpc等指令來查詢服務器時間,等於不提供ntp的網絡校時
  #notrap   : 不提供trap這個遠程時間登錄的功能
  #notrust  : 拒絕沒有認證的客戶端
  #nopeer   : 不與其他同一層的ntp服務器進行時間同步 

  restrict [address] mask [netmask_ip] [parameter]

# 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).
使用的上層internet ntp服務器
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

啟動ntpd

[root@ht8 ~]# systemctl restart ntpd

[root@ht8 ~]# ps -ef | grep ntpd
ntp      116593      1  0 17:47 ?        00:00:00 /usr/sbin/ntpd -u ntp:ntp -g
root     116601  94921  0 17:47 pts/1    00:00:00 grep --color=auto ntpd

//啟動之后馬上查下同步情況,使用ntpstat命令檢查NTP狀態

[root@ht8 ~]# ntpstat
unsynchronised
polling server every 64 s

//需要等待5-10分鍾,如果還沒有變成synchronised,則需要進行相關的其他修復工作。

[root@ht8 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
time.cloudflare 10.28.10.82 3 u 25 64 1 188.141 1.044 1.328
+sv1.ggsrv.de 192.53.103.103 2 u 56 64 1 238.556 24.391 0.657
+electrode.felix 85.10.240.253 3 u 23 64 1 225.203 -33.220 0.545
*111.230.189.174 100.122.36.196 2 u 54 64 1 40.311 0.088 0.156

//這里注意,配置文件/etc/ntp.conf 並沒有動,用的是默認的時間服務器

查下時間情況

[root@ht8 ~]# date  //北京時間
Wed Mar  9 17:50:19 CST 2022

[root@ht8 ~]# date -R  //UTC時間
Wed, 09 Mar 2022 17:50:38 +0800

 

查下硬件時間

[root@ht8 ~]# hwclock  -r
Wed 09 Mar 2022 04:55:08 PM CST  -0.333306 seconds
//明顯和系統時間不一致,這里先不修復。

 設置開啟開機啟動,這里是必須

[root@ht8 ~]#  chkconfig --list ntpd   //centos6命令

Note: This output shows SysV services only and does not include native
      systemd services. SysV configuration data might be overridden by native
      systemd configuration.

      If you want to list systemd services use 'systemctl list-unit-files'.
      To see services enabled on particular target use
      'systemctl list-dependencies [target]'.

error reading information on service ntpd: No such file or directory
[root@ht8 ~]# systemctl list-unit-files    //centos7命令
UNIT FILE                                     STATE   
proc-sys-fs-binfmt_misc.automount             static  
dev-hugepages.mount                           static  
dev-mqueue.mount                              static  
proc-fs-nfsd.mount                            static  
proc-sys-fs-binfmt_misc.mount                 static  
sys-fs-fuse-connections.mount                 static  
sys-kernel-config.mount                       static  
sys-kernel-debug.mount                        static  
tmp.mount                                     disabled
var-lib-nfs-rpc_pipefs.mount                  static  
brandbot.path                                 enabled 
systemd-ask-password-console.path             static  
systemd-ask-password-plymouth.path            static  
systemd-ask-password-wall.path                static  
run-117537.scope                              static  
session-10691.scope                           static  
session-10696.scope                           static  
abrt-ccpp.service                             enabled 
abrt-oops.service                             enabled 
abrt-pstoreoops.service                       disabled
abrt-vmcore.service                           enabled 
abrt-xorg.service                             enabled 
abrtd.service                                 enabled 
arp-ethers.service                            disabled
atd.service                                   enabled 
auditd.service                                enabled 
auth-rpcgss-module.service                    static  
autovt@.service                               enabled 
blk-availability.service                      disabled
brandbot.service                              static  
calico-node.service                           enabled 
chrony-dnssrv@.service                        static  
chrony-wait.service                           disabled

[root@ht8 ~]# systemctl list-unit-files | grep ntpd
ntpd.service                                  disabled
ntpdate.service                               disabled

//采用

[root@ht8 ~]# chkconfig --list  //這個顯示的列表

Note: This output shows SysV services only and does not include native
systemd services. SysV configuration data might be overridden by native
systemd configuration.

If you want to list systemd services use 'systemctl list-unit-files'.
To see services enabled on particular target use
'systemctl list-dependencies [target]'.

cloud-set-guest-password 0:off 1:off 2:off 3:on 4:on 5:on 6:off
netconsole 0:off 1:off 2:off 3:off 4:off 5:off 6:off
network 0:off 1:off 2:on 3:on 4:on 5:on 6:off
vmware-tools 0:off 1:off 2:on 3:on 4:on 5:on 6:off

//啟用命令

[root@ht8 ~]# chkconfig --level 345 ntpd on
Note: Forwarding request to 'systemctl enable ntpd.service'.
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

//最終得使用這個命令. 與centos6的命令有差異,要注意
[root@ht8 ~]# systemctl enable ntpd.service

再次查看ntpstat,發現提示有變化.

[root@ht8 ~]# ntpstat
unsynchronised
  time server re-starting
   polling server every 8 s

//再次查看同步服務器情況 [root@ht8
~]# ntpq -p remote refid st t when poll reach delay offset jitter ============================================================================== *ntp5.flashdance 194.58.202.148 2 u 49 64 1 160.406 22.470 5.562 stratum2-1.ntp. 194.190.168.1 2 u 48 64 1 138.787 -1.059 4.869 de-user.deepini 46.4.19.10 3 u 48 64 1 291.627 60.306 9.838 makaki.miuku.ne 210.23.25.77 2 u 46 64 1 250.315 -63.342 5.452

等待2分鍾之后,出現同步成功

[root@ht8 ~]# ntpstat 
synchronised to NTP server (193.182.111.14) at stratum 3 //
   time correct to within 1082 ms  //毫秒是一種較為微小的時間單位,是一秒的千分之一
   polling server every 64 s  
ntpd服務,默認只會同步系統時間。
如果想要讓ntp同時同步硬件時間,可以設置/etc/sysconfig/ntpd 文件,在/etc/sysconfig/ntpd文件中,
添加 SYNC_HWCLOCK=yes 這樣,就可以讓硬件時間與系統時間一起同步。

[root@ht8 ~]# cat /etc/sysconfig/ntpd
# Command line options for ntpd
OPTIONS="-g"  

//上面是默認的配置

和下面的等同
[root@ht8 ~]# vi /etc/sysconfig/ntpd
OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"

//這個ntpd默認的配置文件,我們可以查看下ntpd狀態來查看相關命令

[root@ht8 ~]# ps -aux | grep ntpd
ntp 118877 0.0 0.0 32044 2212 ? Ss 18:02 0:00 /usr/sbin/ntpd -u ntp:ntp -g

[root@ht8 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-03-09 18:02:16 CST; 1h 15min ago
Process: 118876 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 118877 (ntpd)
Tasks: 1
Memory: 632.0K
CGroup: /system.slice/ntpd.service
└─118877 /usr/sbin/ntpd -u ntp:ntp -g   //這里就是默認的命令

Mar 09 18:02:16 ht8.node ntpd[118877]: Listen normally on 9 calic21a2ba7eca fe80::ecee:eeff:feee:eeee UDP 123
Mar 09 18:02:16 ht8.node ntpd[118877]: Listen normally on 10 ens192 fe80::4a0:90ff:fe00:e8e UDP 123
Mar 09 18:02:16 ht8.node ntpd[118877]: Listening on routing socket on fd #27 for interface updates
Mar 09 18:02:16 ht8.node systemd[1]: Started Network Time Service.
Mar 09 18:02:16 ht8.node ntpd[118877]: 0.0.0.0 c016 06 restart
Mar 09 18:02:16 ht8.node ntpd[118877]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Mar 09 18:02:16 ht8.node ntpd[118877]: 0.0.0.0 c011 01 freq_not_set
Mar 09 18:02:23 ht8.node ntpd[118877]: 0.0.0.0 c614 04 freq_mode
Mar 09 18:20:25 ht8.node ntpd[118877]: 0.0.0.0 0612 02 freq_set kernel 10.885 PPM
Mar 09 18:20:25 ht8.node ntpd[118877]: 0.0.0.0 0615 05 clock_sync

//修改如下
[root@ht8 ~]# vi /etc/sysconfig/ntpd

OPTIONS="-g"
SYNC_HWCLOCK=yes

//重啟
[root@ht8 ~]# vsystemctl restart ntpd

[root@ht8 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
a.chl.la 131.188.3.221 2 u 20 64 1 200.347 20.149 13.088
*sv1.ggsrv.de 192.53.103.103 2 u 16 64 1 236.432 46.227 3.277
ntp5.flashdance .INIT. 16 u - 64 0 0.000 0.000 0.000
119.28.183.184 100.122.36.196 2 u 15 64 1 48.528 11.026 0.315

命令“ntpq -p”列出NTP與之相關的上層NTP的狀態,以上的幾個字段的意義如下:

remote:即remote - 本機和上層ntp的ip或主機名,“+”表示優先,“*”表示次優先。

refid:參考的上一層NTP主機的地址

st:即stratum階層

poll:下次更新在幾秒之后

offset:時間補償的結果

[root@ht8 ~]# ntpstat
synchronised to NTP server (144.76.76.107) at stratum 3
time correct to within 1109 ms
polling server every 64 s  //會有一個unsynchronised,等待一會就正常了,因為同步需要一個時間。

//當然我們也可以直接使用hwclock -w 執行下,意思是允許進行時間同步. 或同步BIOS時鍾,強制把系統時間寫入CMOS,命令如下: 
#clock -w

 

二、ntpdate(ntp軟件包里面的另外一個服務)

 查看計划任務

[root@ht8 ~]# crontab -l 0 12 * * * /usr/sbin/ntpdate -u 1.cn.pool.ntp.org
//這個是之前加入的,相當於定時手工執行一次,每天12點。

執行ntpdate,需要先停止ntpd服務,然后執行,執行之后再讓他同步

 
         
[root@ht8 ~]#systemctl stop ntpd 
[root@ht8 ~]#ntpdate -u 1.cn.pool.ntp.org //執行一次.
[root@ht8 ~]#systemctl start ntpd

 查看ntpdate

[root@ht8 ~]# systemctl is-enabled ntpdate
disabled

 

timedatectl status(這個命令幾乎都沒有講解到底這個NTP enabled: no是什么? )

[root@ht8 ~]#  timedatectl status
      Local time: Wed 2022-03-09 20:08:37 CST  //本地時間
  Universal time: Wed 2022-03-09 12:08:37 UTC  //協調世界時,又稱世界統一時間、世界標准時間、國際協調時間。簡稱UTC。協調世界時是以原子時秒長為基礎
        RTC time: Wed 2022-03-09 12:08:37  //硬件時間
       Time zone: Asia/Shanghai (CST, +0800)  //時區,北京時間,東八區
     NTP enabled: no  //沒有啟用ntpdate
NTP synchronized: yes  //啟用了ntpd
 RTC in local TZ: no
      DST active: n/a

 //我們查下下面的命令,看到確實ntpd,ntpdate啟用的情況。
 [root@ht8 ~]# systemctl is-enabled ntpd
 enabled
 [root@ht8 ~]# systemctl is-enabled ntpdate
  disabled

//ntpd服務啟動正常
[root@ht8 ~]# systemctl status ntpd.service
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Wed 2022-03-09 19:21:38 CST; 1h 54min ago
Main PID: 130003 (ntpd)
Tasks: 1
Memory: 644.0K
CGroup: /system.slice/ntpd.service
└─130003 /usr/sbin/ntpd -u ntp:ntp -g

Mar 09 19:21:38 ht8.node ntpd[130003]: Listen normally on 8 ens224 fe80::435:3cff:fe00:b03 UDP 123
Mar 09 19:21:38 ht8.node ntpd[130003]: Listen normally on 9 calic21a2ba7eca fe80::ecee:eeff:feee:eeee UDP 123
Mar 09 19:21:38 ht8.node ntpd[130003]: Listen normally on 10 ens192 fe80::4a0:90ff:fe00:e8e UDP 123
Mar 09 19:21:38 ht8.node ntpd[130003]: Listening on routing socket on fd #27 for interface updates
Mar 09 19:21:38 ht8.node ntpd[130003]: 0.0.0.0 c016 06 restart
Mar 09 19:21:38 ht8.node ntpd[130003]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Mar 09 19:21:38 ht8.node ntpd[130003]: 0.0.0.0 c011 01 freq_not_set
Mar 09 19:21:47 ht8.node ntpd[130003]: 0.0.0.0 c614 04 freq_mode
Mar 09 19:44:09 ht8.node ntpd[130003]: 0.0.0.0 0612 02 freq_set kernel -6.589 PPM
Mar 09 19:44:09 ht8.node ntpd[130003]: 0.0.0.0 0615 05 clock_sync

//ntpdate狀態是沒有激活(激活是systemctl start ntpdate),到目前為止還是用不了ntpdate,但是已設置了enable(啟用是systemctl enable ntpdate.service),
   設置了開機啟動,這兩個概念不同。
 [root@ht8 ~]# systemctl status ntpdate.service
  ● ntpdate.service - Set time via NTP
  Loaded: loaded (/usr/lib/systemd/system/ntpdate.service; disabled; vendor preset: disabled)
  Active: inactive (dead) 

 //我用另一台機器版本一樣的,來做補充,因為這里說的不夠細致,容易誤導。
  //我啟動ntpupdate服務,結果失敗了
  [root@k3master ~]# systemctl start ntpdate.service
  Job for ntpdate.service failed because the control process exited with error code. 
See "systemctl status ntpdate.service" and "journalctl -xe" for details. //查看ntpdate失敗的原因 [root@k3master ~]# systemctl status ntpdate.service ● ntpdate.service - Set time via NTP Loaded: loaded (/usr/lib/systemd/system/ntpdate.service; enabled; vendor preset: disabled) Active: failed (Result: exit-code) since Sun 2022-03-13 23:07:52 CST; 16s ago Process: 48843 ExecStart=/usr/libexec/ntpdate-wrapper (code=exited, status=1/FAILURE) Main PID: 48843 (code=exited, status=1/FAILURE) Mar 13 23:07:21 k3master systemd[1]: Starting Set time via NTP... Mar 13 23:07:52 k3master systemd[1]: ntpdate.service: main process exited, code=exited, status=1/FAILURE Mar 13 23:07:52 k3master systemd[1]: Failed to start Set time via NTP. Mar 13 23:07:52 k3master systemd[1]: Unit ntpdate.service entered failed state. Mar 13 23:07:52 k3master systemd[1]: ntpdate.service failed. //我繼續測試,手工更新一次,發現ntp socket被占用,實際這里就是之前所說的,先要關閉ntpd,然后才能執行 [root@k3master ~]# ntpdate 210.23.25.77 13 Mar 23:08:57 ntpdate[48964]: the NTP socket is in use, exiting //這里是重點,實際和我上一篇centos6操作一樣,也要先停止ntpd,然后在啟動ntpdate,然后才能使用ntpdate命令。 [root@k3master ~]# systemctl stop ntpd //停止ntpd服務,注意不是ntpdate,是ntpd [root@k3master ~]# systemctl start ntpdate.service //啟動ntpdate服務 [root@k3master ~]# systemctl status ntpdate.service //查看ntpdate服務狀態,已正常 ● ntpdate.service - Set time via NTP Loaded: loaded (/usr/lib/systemd/system/ntpdate.service; enabled; vendor preset: disabled) Active: active (exited) since Sun 2022-03-13 23:29:26 CST; 7s ago Process: 49277 ExecStart=/usr/libexec/ntpdate-wrapper (code=exited, status=0/SUCCESS) Main PID: 49277 (code=exited, status=0/SUCCESS) Mar 13 23:12:49 k3master systemd[1]: Starting Set time via NTP... Mar 13 23:29:26 k3master systemd[1]: Started Set time via NTP. [root@k3master ~]# ntpdate 210.23.25.77 //做一次手工同步,成功。 實際這個時候ntpd已經停止了. 13 Mar 23:29:49 ntpdate[49322]: adjust time server 210.23.25.77 offset -0.074604 sec //接着說 timdatectl 這里我們就明顯看出,ntp服務本身是兩個軟件服務,一個是ntpd服務,一個是ntpdate服務 //如果ntpdate開機啟動是disabled,這個命令針對ntpdate也是無效的(必須使用systemctl enable ntpdate啟用后才能對ntpdate進行干預) [root@ht8 ~]# timedatectl set-ntp true //啟用ntpdate [root@ht8 ~]# systemctl enable ntpdate Created symlink from /etc/systemd/system/multi-user.target.wants/ntpdate.service to /usr/lib/systemd/system/ntpdate.service. [root@ht8 ~]# systemctl enable ntpdate.service [root@ht8 ~]# systemctl is-enabled ntpdate enabled //我們再執行 timedatectl set-ntp true, 發現 NTP enabled: yes ,
  //也就是說首先要保證ntpdate本身要啟用,我們才能使用timedatectl干預ntpdate的使用。

 [root@ht8 ~]# timedatectl
Local time: Wed 2022-03-09 21:27:07 CST
Universal time: Wed 2022-03-09 13:27:07 UTC
RTC time: Wed 2022-03-09 13:27:07
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

[root@ht8 ~]# timedatectl set-ntp false  //設置為false以后

//查看timedatectl,發現ntpdate已經關閉.
[root@ht8 ~]# timedatectl
Local time: Wed 2022-03-09 21:28:17 CST
Universal time: Wed 2022-03-09 13:28:17 UTC
RTC time: Wed 2022-03-09 13:28:17
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

//這個是所有資料中幾乎都沒有講到的,都要通過實驗來驗證。

 

 

timedatectl常見操作如下 (centos7之后增加的命令用於systemctl 管理后台應用的)

1、查看當前時間/日期/時區:timedatectl或者timedatectl status
2、查看所有可用時區:timedatectl list-timezones  //直接可以使用
3、設置時區:timedatectl set-timezone “時區信息”  //timedatectl set-timezone “Asia/shagnhai”
4、設置UTC:timedatectl set-timezone UTC  //設置為標准時間
5、設置時間:timedatectl set-time HH:MM:SS //timedatectl set-time 15:58:30
6、設置日期:timedatectl set-time YYYY-MM-DD  //timedatectl set-time 20151120
7、設置日期時間:timedatectl set-time “YYYY-MM-DD HH:MM:SS” //timedatectl set-time '16:10:40 2015-11-20'
8、設置硬件時鍾為本地時間:timedatectl set-local-rtc 1  //直接可使用
9、設置硬件時鍾為UTC時間:timedatectl set-local-rtc 0  //直接可以使用,將硬件時鍾設置為UTC
10、啟動NTP時間同步(啟用NTP服務或者Chrony服務):timedatectl set-ntp true //直接可使用
11、禁用NTP時間同步:timedatectl set-ntp false

[root@ht8 ~]# timedatectl | grep local
RTC in local TZ: no
 

手工執行

如果ntpd不好使的情況下,可以先用 ntpdate -b cn.pool.ntp.org 同步下 #同步時間命令  //cn.pool.ntp.org可以是其他時間服務器地址

  如果想看執行過程可以   ntpdate -d  cn.pool.ntp.org //可以看到同步的整個過程。 
   
  使用該命令請確認已經停止ntpd服務。

修改時區

找到相應的時區文件 /usr/share/zoneinfo/Asia/Shanghai替換當前的/etc/localtime。 
修改/etc/sysconfig/clock文件的內容為: 
ZONE=”Asia/Shanghai” 
UTC=false 
ARC=false

  utc即格林尼治時間,cst即每個國家本地時間(由於我們是中國,所以特指北京時間).

 

更多詳細的信息可以參考:
https://www.eecis.udel.edu/~mills/ntp/html/ntpdsim.html 

 

 timedatectl set-ntp true


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM