第一步:首先检查是否有安装ntp:如果没有安装则使用以下命令安装: yum -y install ntp 第二步:设置随机启动: service ntpd start chkconfig
第一步:首先检查是否有安装ntp:如果没有安装则使用以下命令安装:
yum -y install ntp
第二步:设置随机启动:
service ntpd start
chkconfig ntpd on
第三步:同步主节点的服务器时间,这里选用us.pool.ntp.org作为对时中心,ntpdate us.pool.ntp.org。
配置步骤:
a,配置内网NTP-Server(管理节点)
(1) 允许客户机的配置
修改ntp.conf配置文件 vi /etc/ntp.conf
①、第一种配置:允许任何IP的客户机都可以进行时间同步 将restrict default kod nomodify notrap nopeer noquery
这行修改成:
restrict default nomodify
②、第二种配置:只允许10.10.25.*网段的客户机进行时间同步 在restrict default nomodify notrap noquery(表示默认拒绝所有IP的时间同步)之后增加一行: restrict 10.10.25.0 mask 255.255.255.0 nomodify
(2) 同步时间设置
①通过网络同步时间
server 0.centos.pool.ntp.orgserver 1.centos.pool.ntp.orgserver 2.centos.pool.ntp.org
②使用本地时间
server 127.127.1.0 # local clockfudge 127.127.1.0 stratum 10
配置文件完成,保存退出,启动服务,执行如下命令:service ntpd start
检查是否成功,用ntpstat命令查看同步状态,出现以下状态代表启动成功:
synchronised to NTP server (80.241.0.72) at stratum 2 time correct to within 144 mspolling server every 64 s
如果出现异常请等待几分钟,一般等待5-10分钟才能同步。
设置ntp服务,开机自启动:chkconfig ntpd on
b,配置NTP客户端(受管节点)
修改ntp.conf配置文件 vi /etc/ntp.conf
通过 hadoop35.test.com 同步时间
server hadoop35.test.com
配置文件完成,保存退出,启动服务,执行如下命令:service ntpd start
设置ntp服务,开机自启动:chkconfig ntpd on
客户端校验配置
ntpq -p查询上级时间服务器
第四步:ntpstat 查询状态
出现红框字样 即为成功同步时间;
备注:ntpdate -u ip能够快速实现同步当前机器时间到指定ip机器的时间,但是该操作一般不在生产环境上进行,一般采用上面的配置,使用平滑的形式进行时间配置