一.环境准备
xuegod63.cn 服务端 xuegod64.cn 客户端 二.服务端配置:
1. 安装ntp 服务
[iyunv@xuegod63 ~]# yum install -y ntp 2. 开启ntpd服务并设置开机启动
[iyunv@xuegod63 ~]# service ntpd start 正在启动 ntpd: [确定] [iyunv@xuegod63 ~]# chkconfig ntpd on 3. 查看端口是否启动
[iyunv@xuegod63 ~]# netstat -anput| grep 123 udp 0 0 172.16.30.39:123 0.0.0.0:* 2107/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 2107/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 2107/ntpd udp 0 0fe80::5054:ff:fee4:1f53:123 :::* 2107/ntpd udp 0 0 ::1:123 :::* 2107/ntpd udp 0 0 :::123 :::* 2107/ntpd 4. 同步时间:
[iyunv@xuegod63 ~]# ntpdate0.centos.pool.ntp.org(因为开启了ntpd服务同步时间报错) 24 May 11:30:47 ntpdate[2116]: the NTP socketis in use, exiting [iyunv@xuegod63 ~]# service ntpd stop 关闭 ntpd: [确定] [iyunv@xuegod63 ~]# ntpdate0.centos.pool.ntp.org 24 May 11:31:40 ntpdate[2128]: adjust timeserver 202.112.29.82 offset -0.018094 sec 5. 修改配置文件:
[iyunv@xuegod63 ~]# vim /etc/ntp.conf restrict 127.0.0.1 restrict -6 ::1 restrict 192.168.1.0 mask 255.255.255.0 #允许192.168.1.0网段进行访问 server 127.127.1.0 #本地时钟地址 fudge 127.127.1.0 stratum 10 #本地127.127.1.0为第10层 6. 重启ntpd服务
[iyunv@xuegod63 ~]# /etc/init.d/ntpd restart 关闭 ntpd: [失败] 正在启动ntpd: [确定] 7. 测试:
测试之前,要检测是否防火墙、selinux 都关闭!!! 服务端: [iyunv@xuegod63 ~]# date 2016年 05月 24日 星期二 15:54:55 CST [iyunv@xuegod63 ~]# date -s "2016-05-2415:30" #设置时间 2016年 05月 24日 星期二 15:30:00 CST [iyunv@xuegod63 ~]# clock –w #同时同步到硬件 [iyunv@xuegod63 ~]# date 2016年 05月 24日 星期二 15:30:14 CST [iyunv@xuegod63 ~]# service ntpd restart 关闭 ntpd: [确定] 正在启动 ntpd: [确定] [iyunv@xuegod63 ~]# date 2016年 05月 24日 星期二 15:30:29 CST 三.客户端测试:
[iyunv@xuegod64 ~]# ntpdate 172.16.30.39 24 May 15:30:37 ntpdate[15939]: step timeserver 172.16.30.39 offset -1504.826538 sec [iyunv@xuegod64 ~]# date Tue May 24 15:30:40 CST 2016 常见的错误: 25 Apr 15:30:17 ntpdate[11520]: noserver suitable for synchronization found 其实,这不是一个错误。而是由于每次重启NTP服务器之后大约要3-5分钟客户端才能与server建立正常的通讯连接。当此时用客户端连接服务端就会报这样的信息。一般等待几分钟就可以了。
|