Centos7.4 集群ntp时间同步配置

一、实现功能

CDH集群搭建的时候,通过NTP配置时钟同步,从而可以使集群时间一致,保证集群运行基本条件。

二、环境

Centos7.4

三、配置ntp服务器

1.查看系统是否安装ntp

rpm -qa | grep ntp

2.安装ntp和ntpdate

yum -y install ntp ntpdate

3.查看是否已安装完成

[root@cdh1 ~]# rpm -qa | grep ntp        
ntp-4.2.6p5-29.el7.centos.x86_64
ntpdate-4.2.6p5-29.el7.centos.x86_64

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

5.启动ntp服务并且设置开机启动

systemctl start ntpd
systemctl enable ntpd

6.查看状态

[root@cdh1 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
   Active: active (running) since Tue 2020-02-11 19:38:22 CST; 19s ago
 Main PID: 1491 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─1491 /usr/sbin/ntpd -u ntp:ntp -g

Feb 11 19:38:22 cdh1 ntpd[1491]: Listen and drop on 1 v6wildcard :: UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 2 lo 127.0.0.1 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 3 ens33 192.168.0.108 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 4 lo ::1 UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listen normally on 5 ens33 fe80::e37b:3e48:9646:7eff UDP 123
Feb 11 19:38:22 cdh1 ntpd[1491]: Listening on routing socket on fd #22 for interface updates
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c016 06 restart
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Feb 11 19:38:22 cdh1 ntpd[1491]: 0.0.0.0 c011 01 freq_not_set
Feb 11 19:38:23 cdh1 ntpd[1491]: 0.0.0.0 c514 04 freq_mode

7. 查看是否同步

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 #允许本地时间服务器主动修改本机的时间

【cdh集群】
#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 192.168.0.108 #配置本地ntp服务器为时间同步服务器
restrict 192.168.0.108 nomodify notrap noquery #允许本地时间服务器主动修改本机的时间

5.手动同步一下

systemctl stop ntpd
ntpdate 10.2.31.25
systemctl start ntpd
【cdh集群】
[root@cdh2 ~]# systemctl stop ntpd
[root@cdh2 ~]# ntpdate 192.168.0.108
11 Feb 21:55:26 ntpdate[1266]: adjust time server 192.168.0.108 offset -0.000086 sec
[root@cdh2 ~]# systemctl start ntpd

6.检测与本地ntpd Server同步

ntpdate -u 10.2.31.25

centos7.4
[root@cdh3 ~]#  ntpdate -u 192.168.0.108
11 Feb 21:50:09 ntpdate[1215]: adjust time server 192.168.0.108 offset -0.140448 sec

7.启动ntp并且设置开机启动

systemctl start ntpd
systemctl enable ntpd

8.查看同步状态

ntpq -p

备注:服务器初次启动,大概要等3-5min,然后时间会自动同步,偏差会逐渐缩小

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值