NTP時間服務

做用vim

實現對不一樣服務器時間的同步校準服務器

NTP時間服務

第一步  安裝

[root@localhost ~]# yum install -y ntp

第二步  設置

進入配置文件測試

[root@localhost mnt]# vim /etc/ntp.conf

而後刪除裏面的全部內容。並插入如下代碼阿里雲

1 server 127.127.1.0   #本機時鐘地址,以本機做爲時間服務器 
2 restrict 127.0.0.1   #容許本機使用時間服務器
3 restrict 192.168.7.3 mask 255.255.255.0    #容許192.168.7.3使用本機的時間服務器

第三部  重啓NTP服務

[root@localhost ~]# systemctl restart ntpd

第四部  檢查NTP服務狀態

[root@localhost /]# ntpstat 
synchronised to local net at stratum 6    #若以unsynchronised開頭則表示未啓動服務
time correct to within 11 ms polling server every 64 s

第五部   客戶端下載NTP客戶端服務

[root@localhost ~]# yum install ntpdate -y

第六步  啓動測試

[root@localhost /]# date
2019年 07月 02日 星期二 14:04:14 CST         #客戶端時間

[root@localhost ~]# date -s "2015-1-1 1:1:1"
2015年 01月 01日 星期四 01:01:01 CST       #修改後的客戶端時間spa

[root@localhost ~]# ntpdate 192.168.7.2    #在客戶端輸入指令,同步到服務器192.168.7.2的時間
2 Jul 14:06:52 ntpdate[4455]: step time server 192.168.7.2 offset 142002257.578532 secrest

[root@localhost ~]# date             #同步成功
2019年 07月 02日 星期二 14:06:53 CSTcode

第七部  開機自啓

[root@localhost /]# systemctl enable ntpd

注意

若出現錯誤可嘗試關閉防火牆等辦法server

[root@localhost /]# systemctl stop firewalld
[root@localhost /]# setenforce 0
setenforce: SELinux is disabled

 

定時同步和同步外網

 定時同步

[root@localhost ~]# crontab -e

*/5 * * * * /usr/sbin/ntpdate 192.168.7.2   #每5分鐘同步一次blog

同步外網

[root@localhost ~]# ntpdate time1.aliyun.com    #阿里雲的時間服務器 2 Jul 14:23:00 ntpdate[4468]: adjust time server 203.107.6.88 offset 0.008185 sec
相關文章
相關標籤/搜索