一、 实现功能
CDH集群搭建的时候,通过NTP配置时钟同步,从而可以使集群时间一致,保证集群运行基本条件。
二、 环境
Centos7.4
三、 配置ntp服务器
1. 查看系统是否安装ntp
rpm -qa | grep ntp
2. 安装ntp和ntpdate
yum -y install ntp ntpdate
3. 查看是否已安装完成
rpm -qa | grep ntp
4. 配置ntp服务器
vim /etc/ntp.conf
注释
#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
在下面再添加一行,代表本机作为服务器
#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
server 127.127.1.0 iburst
6.启动ntp服务并且设置开机启动
systemctl start ntpd
systemctl enable ntpd
7.查看状态
systemctl status ntpd
8. 查看是否同步
ntpq -p
备注:ntp服务器启动后,可能要等3-5min,才能检测到启动服务
四、 客户端配置
1. 查看系统是否安装ntp
rpm -qa | grep ntp
2. 安装ntp和ntpdate
yum -y install ntp ntpdate
3. 查看是否已安装完成
rpm -qa | grep ntp
4. 配置ntp服务器
vim /etc/ntp.conf
修改
#注释掉其他时间服务器
#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
server 10.2.31.25 #配置本地ntp服务器为时间同步服务器
restrict 10.2.31.25 nomodify notrap noquery #允许本地时间服务器主动修改本机的时间
5.手动同步一下
systemctl stop ntpd
ntpdate 10.2.31.25
systemctl start ntpd
6.检测与本地ntpd Server同步
ntpdate -u 10.2.31.25
7.启动ntp并且设置开机启动
systemctl start ntpd
systemctl enable ntpd
8.查看同步状态
ntpq -p
备注:服务器初次启动,大概要等3-5min,然后时间会自动同步,偏差会逐渐缩小