CM-部署NTP时间同步服务器

Posted on 2020-05-02 16:04  MissRong  阅读(429)  评论(0)    收藏  举报

部署NTP时间同步服务器

1.查看集群服务器的Linux版本,确保相同-三台都要

[root@cdh1 ~]# cat /etc/redhat-release

CentOS Linux release 7.2.1511 (Core)

2.管道符查看服务器是否安装ntp服务(集群的每个节点)-三台都要

[root@cdh1 ~]# rpm -qa | grep ntp

fontpackages-filesystem-1.44-8.el7.noarch

如果没有检测到下面这两个就需要进行安装

ntpdate-4.2.6p5-29.el7.centos.x86_64

ntp-4.2.6p5-29.el7.centos.x86_64

如果没有安装使用以下命令安装(集群每个节点)-三台都要:

[root@cdh1 ~]# yum install ntp ntpdate -y

3.查看NTP服务的状态(集群每个节点)-三台都要

[root@cdh1 ~]# systemctl status ntpd.service

● ntpd.service - Network Time Service   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)  

Active: inactive (dead) 

4.修改NTP服务器的机器的配置文件,我的是cdh机器是服务器-主节点

[root@cdh1 ~]# vi /etc/ntp.conf

#找到如下内容注释掉-这些内容相当于用来同步CentOS系统的。

下面这个是主节点里的配置:

# Please consider joining the pool (http://www.pool.ntp.org/join.html).

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

 

接下来查看主节点时间:

[root@cdh ~]# date

Fri May  1 08:04:24 CST 2020

我这里就和自己计算机的系统时间是统一的。

如果发现不统一的话,

就同步网络时间:

ntpdate ntp1.aliyun.com

然后接着同步本地的时间:

hwclock --systohc

5.启动cdh节点(主节点)的NTP服务

[root@cdh1 ~]# systemctl start ntpd.service

6.设置cdh节点-主节点NTP开机启动

[root@cdh1 ~]# systemctl enable ntpd.service

7.在cdh-主节点查看NTP状态

[root@cdh1 ~]# systemctl status ntpd.service

● ntpd.service - Network Time Service

   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)

   Active: active (running) since Sat 2019-09-28 21:17:35 CST; 2min 10s ago

 Main PID: 72322 (ntpd)

   CGroup: /system.slice/ntpd.service

           └─72322 /usr/sbin/ntpd -u ntp:ntp -g

 

Sep 28 21:17:35 cdh1 ntpd[72322]: Listen normally on 2 lo 127.0.0.1 UDP 123

Sep 28 21:17:35 cdh1 ntpd[72322]: Listen normally on 3 eno16777736 192.168.20.134 UDP 123

Sep 28 21:17:35 cdh1 ntpd[72322]: Listen normally on 4 lo ::1 UDP 123

Sep 28 21:17:35 cdh1 ntpd[72322]: Listen normally on 5 eno16777736 fe80::20c:29ff:fe45:70d1 UDP 123

Sep 28 21:17:35 cdh1 ntpd[72322]: Listening on routing socket on fd #22 for interface updates

Sep 28 21:17:35 cdh1 ntpd[72322]: 0.0.0.0 c016 06 restart

Sep 28 21:17:35 cdh1 ntpd[72322]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM

Sep 28 21:17:35 cdh1 ntpd[72322]: 0.0.0.0 c011 01 freq_not_set

Sep 28 21:17:35 cdh1 systemd[1]: Started Network Time Service.

Sep 28 21:17:36 cdh1 ntpd[72322]: 0.0.0.0 c514 04 freq_mode

 

8.cdh节点-主节点 查看是否同步:关闭防火墙或者开放123端口

 

[root@cdh jdk1.8.0_144]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 5 l 29 64 377 0.000 0.000 0.000

9.如果是集群的话,配置客户机-从节点的NTP服务,修改配置文件

这个过程同理主节点的操作

vi /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

 

#配置上游时间服务器-主节点 为本地的ntpd Server服务器

server 192.168.212.11

#配置允许上游时间服务器主动修改本机的时间

restrict 192.168.212.11 nomodify notrap noquery

10.将客户机-从节点 的时间与服务器的同步下

[root@cdh2 ~]# ntpdate -u 192.168.212.11

9 May 23:25:35 ntpdate[3071]: adjust time server 192.168.212.11 offset 0.000058 sec

11.启动客户端-从节点 的NTP服务&配置开机启动NTP

[root@cdh2 ~]# systemctl start ntpd.service

[root@cdh2 ~]# systemctl enable ntpd.service

12.查看客户机的NTP状态

[root@cdh2 ~]# systemctl status ntpd.service

● ntpd.service - Network Time Service

   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)

   Active: active (running) since Sat 2019-09-28 21:31:26 CST; 38s ago

 Main PID: 100613 (ntpd)

   CGroup: /system.slice/ntpd.service

           └─100613 /usr/sbin/ntpd -u ntp:ntp -g

 

Sep 28 21:31:26 cdh2 ntpd[100613]: Listen and drop on 1 v6wildcard :: UDP 123

Sep 28 21:31:26 cdh2 ntpd[100613]: Listen normally on 2 lo 127.0.0.1 UDP 123

Sep 28 21:31:26 cdh2 ntpd[100613]: Listen normally on 3 eno16777736 192.168.20.132 UDP 123

Sep 28 21:31:26 cdh2 ntpd[100613]: Listen normally on 4 lo ::1 UDP 123

Sep 28 21:31:26 cdh2 ntpd[100613]: Listen normally on 5 eno16777736 fe80::20c:29ff:feb3:f5ad UDP 123

Sep 28 21:31:26 cdh2 ntpd[100613]: Listening on routing socket on fd #22 for interface updates

Sep 28 21:31:26 cdh2 ntpd[100613]: 0.0.0.0 c016 06 restart

Sep 28 21:31:26 cdh2 ntpd[100613]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM

Sep 28 21:31:26 cdh2 ntpd[100613]: 0.0.0.0 c011 01 freq_not_set

Sep 28 21:31:26 cdh2 systemd[1]: Started Network Time Service.

13.查看时间是否同步

 

[root@cdh2 ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
cdh LOCAL(0) 6 u 40 64 1 0.224 0.029 0.000

通过以上操作即可以解决配置hbase或者cdh等集群是的时间不同步问题。

如果从节点的机器时间与主节点时间发生不同步的话,主节点就会自动地修改那个从节点的时间。

博客园  ©  2004-2025
浙公网安备 33010602011771号 浙ICP备2021040463号-3