【笔记】集群时间同步(CentOS篇)

前言

通过ntp命令,配置集群时间同步,实现内网时间同步

配置主机

  • 配置hadoop102

确保 ntp 服务关闭状态

  • 为防止端口占用,在配置前应关闭ntp服务

查看 ntp 服务状态

1
service ntpd status

停止 ntp 服务

1
2
service ntpd stop
chkconfig ntpd off

确认关闭状态

1
chkconfig --list ntpd

开始配置

  • ntp所有命令应在root权限下使用

  • hadoop102配置中心服务器,hadoop103hadoop104hadoop102上拉去时间

配置 ntp.conf 文件

去除注释
  • 为以下内容去除注释
/etc/ntp.conf
1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
添加注释
  • 为以下内容添加注释
/etc/ntp.conf
1
2
3
4
#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
添加当前节点
  • 在任意位置添加当前节点
/etc/ntp.conf
1
2
server 127.127.1.0
fudge 127.127.1.0 stratum 10

配置 ntpd 文件

同步硬件时钟
  • 添加以下内容
/etc/sysconfig/ntpd
1
SYNC_HWCLOCK=yes

重启 ntp 服务

1
service ntpd start

确认 ntp 服务状态

1
service ntpd status

设置 ntp 服务开机启动

1
chkconfig ntpd on

配置从机

  • 配置hadoop103hadoop104

添加计划任务

1
crontab -e

配置计划任务

  • 每隔1分钟同步时间
1
*/1 * * * * /usr/sbin/ntpdate hadoop102

完成

参考文献

哔哩哔哩——zhvsvd