1. 检查是否安装ntp
[root@m01 ~]# rpm -qa ntp
ntp-4.2.6p5-10.el6.centos.2.x86_64
若没有安装
yum install -y ntp
2. 配置ntp服务
[root@m01 ~]# sed -i '8c restrict default nomodify' /etc/ntp.conf
[root@m01 ~]# sed -i '22,25d' /etc/ntp.conf
[root@m01 ~]# sed -i '22a server ntp1.aliyun.com' /etc/ntp.conf
3.启动ntp
[root@m01 ~]# /etc/init.d/ntpd start
Starting ntpd: [ OK ]
[root@m01 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
time5.aliyun.co 10.137.38.86 2 u 26 64 1 8.705 4957033 0.015
[root@m01 ~]# ntpstat
注意:
1.启动ntp服务器不要在手动用date修改时间
2.第一个作用是将自己本机的时间同步一下;第二个作用给其他机器提供时间同步
3. ntp服务和ntpdate命令互斥,只能选一个
[root@m01 ~]# ntpdate ntp1.aliyun.com
27 Jul 09:00:49 ntpdate[2753]: the NTP socket is in use, exiting
4. 客户端时间同步操作
[root@lb01 ~]# ntpdate 172.16.1.61
4 Jul 22:28:02 ntpdate[9179]: no server suitable for synchronization found
[root@zyops ~]# ntpdate 10.0.0.61
7Dec 18:40:16 ntpdate[1453]: step time server 10.0.0.61 offset 40.880807 sec
# 将命令放入计划任务即可。
说明:所有内网都是同步这台机器10.0.0.61
[root@lb01 ~]# ntpdate 172.16.1.61
27 Jul 09:14:12 ntpdate[9191]: step time server 172.16.1.61 offset1938838.518972 sec