时间同步(linux)

来源:互联网 发布:美工钢笔 编辑:程序博客网 时间:2024/04/28 14:05
linux集群时间同步


说明:由于hadoop集群对时间要求很高,所以集群内主机要经常同步。本文档适合ubuntu、redhat系列。


注:很多内容是在网上摘录,然后试验后总结,如有疑问可留言探讨。


 
1.设置主机时间准确(任意机器都可)。//如果不需要同步网络时间则可以省略这一步


1.1查看本机时间和时区(date)


1.2设置时区(tzselect ;选择后执行cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime)(这里是redhat的修改时区,ubuntu较简单,命令网上查找)


1.3修改时间(date -s 00:00:00或者网络同步:apt-get install ntpdate ; ntpdate cn.pool.ntp.org)


1.4写入硬盘时间(hwclock -w)


这样主机时间设置完毕。


2.时间同步(主机)


配置主机环境(yum install ntp  )(用ubuntu做主机也可,设置参考ubuntu时间同步)


?vi /etc/ntp.conf


在后面加上


server 127.127.1.0


Fudge 127.127.1.0 stratum 10


?关闭防火墙: #service iptables stop


?重新启动服务:


service ntpd stop(ubuntu是service ntp stop)


service ntpd start


开机启动
chkconfig ntpd on
chkconfig ntpdate on


这样主机准备完毕。


3.其他机器同步


自启动服务
chkconfig ntpdate on


?等待大概五分钟,再到其他机上同步该机器时间(先确保时区一样,否则同步以后时间也是有时区差的)


ntpdate IP地址(主机的)


Date查看时间是否同步完成。


4.根据需要,这里可以让分机器定时自动同步时间


4.1.yum install crontabs(atp-get)


4.2.crontab -e 编辑内容: * */12 * * * /usr/sbin/ntpdate 172.72.103.228(每12个小时更新一次,也可特定时间更新一次,格式可网上查找)


4.3保存退出即可,可以到/var/spool/mail/下查看记录
0 0
原创粉丝点击