各个节点实现时间同步
有三台虚拟机, tt-hadoop1为主, tt-hadoop2 和 tt-hadoop3 为从
要实现从节点的date永远和主节点的date保持一致
1> 在tt-hadoop1检查ntp包是否安装
命令: rpm -qa|grep ntpd
![](https://img.haomeiwen.com/i13093055/1879e852ead2ce41.png)
如图所示,说明有ntp包
2> 修改配置文件
在 /etc/目录下找到ntp.conf
![](https://img.haomeiwen.com/i13093055/8cc30b1d0a0dd57b.png)
a. 在ntp.conf中添加以下内容
restrict 192.168.11.0 mask 255.255.255.0 nomodify notrap
b. 注释以下四行内容
#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
c. 去掉以下注释(如果没有,直接手动添加)
server 127.127.1.0
fudge 127.127.1.0 stratum 10
![](https://img.haomeiwen.com/i13093055/72d90e485e1fa4e4.png)
3> 启动ntp
命令: service ntpd start
查看ntp状态
命令(三个都可): service ntpd status
ntpstat
ntpq -p
![](https://img.haomeiwen.com/i13093055/53218f6e9dbd7dea.png)
![](https://img.haomeiwen.com/i13093055/1121b1c5ca0e545b.png)
设置ntp为开机自启
命令: chkconfig ntpd on
4> 查看ntp的启动路径 命令:which ntpdate
![](https://img.haomeiwen.com/i13093055/21c6460ff284e895.png)
在从机上执行 ntpdate tt-hadoop1,就实现了时间的同步,但为了方便,而不是每次开启虚拟机都执行这个语句才能同步,所以写一个脚本
命令: crontab -e (-e为编辑,-l为查看)
写入以下内容,如图所示
0-59/1 * * * * /usr/sbin/ntpdate tt-hadoop1
![](https://img.haomeiwen.com/i13093055/27a3a00bfa9afe0d.png)
也可以设置BIOS与系统时间同步
a> 查看
![](https://img.haomeiwen.com/i13093055/2a97b2c5694d6be1.png)
b> 编辑 在[OPTIONS]前添加以下内容
vi /etc/sysconfig/ntpd
SYNC_HWCLOCK=yes
c> 测试
ntpstat
sudo ntpq -p
网友评论