NTP同步網絡時間

NTP同步網絡時間


廢話不多說,直接執行如下命令即可
# yum install -y ntpdate
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime;ntpdate -u ntp.api.bz && hwclock -w

時區操作

1. 查看時區
 date "+%Z"
[root@lb-node1 ~]# ll /etc/localtime
lrwxrwxrwx. 1 root root 38 Oct 17 14:26 /etc/localtime -> ../usr/share/zoneinfo/America/New_York
[root@lb-node1 ~]#

如果採用直接cp的方法修改系統時區,那麼就會把它所鏈接的文件修改掉,例如把美國的時區文件內容修改成了上海的時區內容,有可能會導致有些編程語言或程序在讀取系統時區的時候發生錯誤

  • 正確的修改方法是
1. CentOS6+ 、Ubuntu16+ 系統
# cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

2. CentOS7、RHEL7、Scientific Linux 7、Oracle Linux 7系統,最好使用timedatectl命令
# timedatectl list-timezones |grep Shanghai    #查找中國時區的完整名稱
Asia/Shanghai
# timedatectl set-timezone Asia/Shanghai    #其他時區以此類推
或者手動創建軟鏈接
# ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

同步網絡時間

ntp常用服務器:
中國國家授時中心:210.72.145.44
NTP服務器(上海) :ntp.api.bz
美國: time.nist.gov
復旦: ntp.fudan.edu.cn
微軟公司授時主機(美國) :time.windows.com
北京郵電大學 : s1a.time.edu.cn
清華大學 : s1b.time.edu.cn
北京大學 : s1c.time.edu.cn
臺警大授時中心(臺灣):asia.pool.ntp.org

# 同步網絡時間
[root@lb-node2 ~]# ntpdate -u ntp.api.bz
12 Nov 19:47:29 ntpdate[6504]: adjust time server 47.98.146.45 offset 0.045074 sec
[root@lb-node2 ~]#

將系統時間寫入硬件

[root@lb-node1 ~]# hwclock			# 查看硬件時間
Mon 12 Nov 2018 07:55:37 PM CST  -0.866369 seconds
[root@lb-node1 ~]#  hwclock -w			# 同步系統時間到硬件

# hwclock hctosys				# 同步硬件時間到系統
# hwclock systoch    			# 同步系統時間到硬件
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章