NTP时间服务,


作用

实现对不同服务器时间的同步校准

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       #修改后的客户端时间

[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 sec

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

第七部  开机自启

[root@localhost /]# systemctl enable ntpd

注意

若出现错误可尝试关闭防火墙等办法

[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分钟同步一次

同步外网

[root@localhost ~]# ntpdate time1.aliyun.com    #阿里云的时间服务器
 2 Jul 14:23:00 ntpdate[4468]: adjust time server 203.107.6.88 offset 0.008185 sec

 

相关内容

    暂无相关文章