如何搭建ntp时间服务器(搭建时间同步服务器)(新手如何入门pytorch)
1. NTP服務簡介
NTP(Network Time Protocol,網絡時間協議)是用來使網絡中的各個計算機時間同步的一種協議。它的用途是把計算機的時鐘同步到世界協調時UTC,其精度在局域網內可達0.1ms,在互聯網上絕大多數的地方其精度可以達到1-50ms。
NTP服務器就是利用NTP協議提供時間同步服務的。
2. NTP服務搭建
2.1. 環境準備
使用VMware虛擬化安裝linux系統并將網絡環境設置為NAT,可以連上外網
| 主機名稱 | IP地址 | 系統版本 | 角色 |
|---|---|---|---|
| linux-node1 | 192.168.66.11 | CentOS 7 | NTP服務器 |
| linux-node2 | 192.168.66.12 | CentOS 7 | 客戶端 |
注意:關閉系統selinux和防火墻
2.2. 安裝NTP服務
查看系統是否安裝 ntp服務
~]# rpm -qa ntp
ntp-4.2.6p5-28.el7.centos.x86_64
若沒有安裝可以使用 YUM 命令進行安裝即可
~]# yum -y install ntp
2.3. 配置NTP服務
ntp 服務器默認是不運行客戶端進行時間同步的,所有我們需要配置文件設置允許。NTP服務的默認配置文件是/etc/ntp.conf
~]# cp /etc/ntp.conf{,_$(date +%Y%m%d%H)}
~]# vim /etc/ntp.conf
………省略內容………
#restrict default kod nomodify notrap nopeer noquery 注釋此行內容
# nomodify 客戶端不可以修改時間參數但是可以同步時間服務器,添加以下內容
restrict default nomodify
以下為 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
添加新的時間同步源
server time1.aliyun.com
………省略內容………
2.4. 啟動NTP服務
客戶端先將系統優化是定時任務自動同步時間服務器的定時任務注釋,如果不注釋的話可能會
沖突
提示:本地的 ntp 時間服務器會跟互聯網的時間服務器沖突,只能選擇一個進行同步。
~]# crontab -l
# time sync by albert at 2019-02-10
#*/5 * * * * /usr/sbin/ntpdate time1.aliyun.com &>/dev/null
~]# systemctl enable ntpd.service
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
~]# systemctl start ntpd.service
# 查看ntp服務器的詳細狀態
~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
203.107.6.88 10.165.84.13 2 u 28 64 1 15.767 708.472 0.000
# 顯示網絡時間同步狀態
# 使用ntpstat 命令查看時間同步狀態,這個一般需要5-10分鐘后才能成功連接和同步。所以,服務器啟動后需要稍等下.
# 剛啟動的時候,一般是:
~]# ntpstat
unsynchronised
time server re-starting
polling server every 8 s
# 連接并同步后:
3. 客戶機時間同步
客戶機要等幾分鐘再與新啟動的 ntp 服務器進行時間同步,否則會提示 no server suitable for synchronization found 錯誤。
~]# ntpdate 192.168.66.11
14 Feb 11:27:59 ntpdate[6528]: no server suitable for synchronization found
客戶端同步時間的方法:
~]# ntpdate 192.168.66.11
14 Feb 11:37:25 ntpdate[1453]: step time server 192.168.66.11 offset 0.880807 sec
# 將命令放入計劃任務即可
~]# crontab -l
*/5 * * * * /usr/sbin/ntpdate 192.168.66.11 &>/dev/null
4. 注意事項
當我們搭建 NTP 服務器的時候一定要先將后面優化的時間同步定時任務注釋,不然會產生沖突
常見錯誤 1:No association ID's returned
檢查網絡是否連通:ping www.baidu.com
常見錯誤 2:
~]# ntpdate 192.168.66.11
Error resolving 192.168.66.11: Servname not supported for ai_socktype (-8)
14 Feb 11:37:25 ntpdate[1411]: Can't find host 192.168.66.11: Servname not supported for ai_socktype (-8)
14 Feb 11:37:25 ntpdate[1411]: no servers can be used, exiting
客戶機要等幾分鐘再與新啟動的 ntp 服務器進行時間同步,否則會提示 no server suitable for synchronization found 錯誤。
可能原因:客戶端缺少什么配置文件
檢查客戶端是否可以與互聯網的時間服務器同步,若不行,就是客戶端的問題!排查客戶端故障
總結
以上是生活随笔為你收集整理的如何搭建ntp时间服务器(搭建时间同步服务器)(新手如何入门pytorch)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 高亮显示 html_友达10.1寸超低温
- 下一篇: 微软放弃工业元宇宙!传团队已经完全解散