一、搭建时间服务器
1.需要在每台机器上安装一个命令 ntp
yum install -y ntp
2.以hadoop01服务器作为时间服务器
需要对时间服务器进行配置
配置在/etc/ntp.conf
ps:如果通过vi明令发现这ntp.conf是空文件,那么在确定有ntp.conf.rpmnew文件的前提下
删除当前空文件 rm -rf /etc/ntp.conf
将ntp.conf.rpmnew文件移动到当前目录下成为ntp.conf
mv /etc/ntp.conf.rpmnet /etc/ntp.conf
3.在编辑这个即可 vi /etc/ntp.conf
在文件中第18行的位置,会出现时间同步的 范围
在配置文件语句的下面添加相同语句
restrict 10.211.55.0 mask 255.255.255.0 nomodify notrap
自己IP地址(当服务器的IP) 除了当前这个网段都不允许修改
这个0的作用代表整个IP端都能访问
10.211.55.0~255
配置文件中从 23~26行结束 所有server服务都要停止
#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
在这4个时间服务的前面添加# 代表被注释 不会执行
在这4个时间同步服务的下面添加
server 127.127.1.0 --- > 本地时间同步点
保存退出文件即可
4.需要启动NTP服务
service ntpd [start|stop|restart]
重启NTP服务
service ntpd restart
5.其他节点 可以对当前服务器进行同步时间
ps:需要关闭其他节点 ntpd服务 service ntpd stop
以后再同不时间 不链接外网的前提下
ntpdate 时间服务器的IP地址即可
-------------------------------------------------------
二、时间同步命令
1.同步到上海服务器
[root@esx4 ~]# ntpdate ntp.api.bz
21 Sep 14:39:09 ntpdate[24744]: the NTP socket is in use, exiting
[root@esx4 ~]# service ntpd stop
Shutting down ntpd: [ OK ]
[root@esx4 ~]# ntpdate ntp.api.bz
21 Sep 15:22:43 ntpdate[25723]: step time server 114.80.81.1 offset 2312.159684 sec
---------------------------------------------------
2.同步ntp服务器时间
[root@root ~]# yum install -y ntpdate
执行:ntpdate
[root@root ~]# ntpdate 120.24.81.91
或
[root@root ~]# ntpdate pool.ntp.org
date命令查看当前时间:
[root@root ~]# date
关闭ntpdate服务
service ntpd stop
http://www.pool.ntp.org是NTP的官方网站,在这上面我们可以找到离我们国家的NTP Server cn.pool.ntp.org.它有3个服务器地址:
服务器一: 1.cn.pool.ntp.org
服务器二: 2.asia.pool.ntp.org
服务器三: 3.asia.pool.ntp.org(直接用域名有时有问题,可以先Ping出他们的IP,然后用IP地址同步)
3.同步当前windows主机时间
[root@root ~]#ntpdate time.windows.com