ntp时间服务器
一.环境准备
两台虚拟机
192.168.30.139 # 服务端
192.168.30.143 # 客户端
二.服务端配置:
1、安装ntp 服务
# 192.168.30.139
[root@hadoop1 opt]# yum install -y ntp
# 192.168.30.143
[root@hadoop2 opt]# yum install -y ntp
2、服务并设置开机启动
[root@hadoop1 opt]# service ntpd start
# 正在启动 ntpd: [确定]
[root@hadoop1 opt]# chkconfig ntpd on
3、 查看端口是否启动
[root@hadoop1 ~]# netstat -anput| grep 123
udp 0 0 192.168.30.139:123 0.0.0.0:* 8239/ntpd
udp 0 0 127.0.0.1:123 0.0.0.0:* 8239/ntpd
udp 0 0 0.0.0.0:123 0.0.0.0:* 8239/ntpd
udp 0 0 fe80::20c:29ff:fea8:b66b:123 :::* 8239/ntpd
udp 0 0 ::1:123 :::* 8239/ntpd
udp 0 0 :::123 :::* 8239/ntpd
4、修改配置文件:
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
#允许192.168.30.0网段进行访问
restrict 192.168.30.0 mask 255.255.255.0
server 127.127.1.0
fudge 127.127.1.0 stratum 10
server 0.centos.pool.ntp.org iburst
server 1.centos.pool.ntp.org iburst
server 2.centos.pool.ntp.org iburst
server 3.centos.pool.ntp.org iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
5、 重启ntpd服务
[root@hadoop1 ~]# service ntpd restart
关闭 ntpd: [确定]
正在启动 ntpd: [确定]
三、客户端配置
1、 在192.168.30.143进行如上的一样操作
客户端不需要重启。。。
四、验证操作
1、测试之前,要检测是否防火墙、selinux 都关闭!!!
#防火墙关闭
[root@hadoop1 opt]# service iptables stop
#selinux关闭
[root@hadoop1 opt]# cat /etc/selinux/config |grep -v ^#
SELINUX=disabled
SELINUXTYPE=targeted
2、时间同步
[root@hadoop1 opt]# date
2017年 12月 17日 星期日 03:33:13 CST
# 设置hadoop2上时间与hadoop1上有明显区别
[root@hadoop2 ~]# date -s '2017-12-10 15:14:23'
2017年 12月 10日 星期日 15:14:23 CST
#执行同步指令
[root@hadoop2 ~]# ntpdate 192.168.30.139
17 Dec 03:35:11 ntpdate[4405]: step time server 192.168.30.139 offset 562786.980472 sec
[root@hadoop2 ~]# date
2017年 12月 17日 星期日 03:35:12 CST
五、添加到定时任务中
# 每天零点同步信息
[root@hadoop2 ~]# crontab -e
0 0 * * * ntpd 192.168.30.139
还没有评论,来说两句吧...