做用vim
實現對不一樣服務器時間的同步校準服務器
[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使用本機的時間服務器
[root@localhost ~]# systemctl restart ntpd
[root@localhost /]# ntpstat synchronised to local net at stratum 6 #若以unsynchronised開頭則表示未啓動服務
time correct to within 11 ms polling server every 64 s
[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