linux ntp 时间同步

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/wangshuminjava/article/details/84292915

linux ntp 时间同步

2016年10月26日 18:43:26 leys123 阅读数:9219 标签: ntpntpdate时间同步 更多

个人分类: linux

一:外网同步时间

1.查看ntpd服务状态

[root@cdh sbin]# service ntpd status 

ntp: unrecognized service

说明 ntpd没有安装。

2.查看是否存在ntp的yum源

[root@cdh sbin]# yum list |grep ntp

3.如果有显示出yum源则安装ntp服务

[root@cdh sbin]# yum -y install ntp; 

首先启动ntp服务:service ntpd start 即可,并设置ntp服务,开机自启动:chkconfig ntpd on。

4.同步时间:(在每台服务器上执行,或者建一个crontab定时)

[root@cdh sbin]# ntpdate asia.pool.ntp.org

二:内网同步时间

1.内网时搭建时间服务器,,,把cdh做为时间服务器。修改cdh1中的/etc/ntp.conf

增加 

restrict default kod nomodify notrap nopeer noquery

restrict -6 default kod nomodify notrap nopeer noquery

restrict default ignore

restrict 172.16.1.0 mask 255.255.255.0 nomodify notrap #172.16.1.0为本集群的ip段,只允许本ip段同步此ntp服务器

server 127.127.1.0 #local clock   

保存,退出。

2.service ntpd restart;

3.使用watch ntpq -p命令查看:

当reach达到7及以上时,就可以去其他节点上执行ntpdate cdh,不然会报如下提示:

.

3.在其他节点机器上也需要检查ntp服务是否存在(service ntpd status ),无则安装yum -y install ntp;

假如其他节点都不能连外网,则需要拷贝cdh这个节点机器下的/usr/sbin/ntpdate到其他节点的/usr/sbin/下,并执行chmod u+x  ntpdate;

4.然后在每台机器(除了cdh1之外的)上去同步cdh1上的时间,ntpdate cdh(每个节点机器上都要运行此句)。

猜你喜欢

转载自blog.csdn.net/wangshuminjava/article/details/84292915