【Hadoop】部署NTP时间同步服务器

1. 查看机器的Linux版本

查看集群内所有服务器的linux版本,确保相同,不要跨大版本。

[root@bigdata111 ~]# cat /etc/redhat-release
CentOS Linux release 7.2.1511 (Core)

2.设置时区

集群内所有机器,设置一下时区;

[root@bigdata111 ~]# timedatectl set-timezone Asia/Shanghai

3.查看是否安装NTP服务

集群内所有机器,查看是否安装ntp服务;

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

4.安装NTP服务

集群内所有机器,如果没有安装ntp服务,则执行以下命令安装;

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

5.查看NTP服务状态

集群内所有机器,执行查看ntp服务状态命令,确定处于服务停止状态;

[root@bigdata111 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

6.修改主节点/主服务器的NTP配置文件;

找到集群的主节点配置NTP文件,编辑完毕,保存退出;

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


#找到如下内容注释掉
# 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
#添加以下内容,同步本地时间,ip写自己的
server 127.127.1.0 iburst

7.主节点同步网络时间

同步网络时间,此处以同步 阿里云的ntp为例;(注意:此操作只有在ntp服务停止的情况下执行,否则报错)

[root@bigdata111 ~]# ntpdate ntp1.aliyun.com
14 Oct 18:01:43 ntpdate[3909]: adjust time server 120.25.115.20 offset -0.020002 sec

8.启动主节点的NTP服务并设置开机启动

[root@bigdata111 ~]# systemctl start ntpd.service
[root@bigdata111 ~]# systemctl enable ntpd.service

9.查看主节点的NTP服务状态

确保主节点的NTP服务状态是 active(running) 状态,才能执行下一步;

[root@bigdata111 ~]# 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 一 2019-10-14 18:03:22 CST; 1min 31s ago
 Main PID: 3916 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─3916 /usr/sbin/ntpd -u ntp:ntp -g

10月 14 18:03:22 bigdata111 ntpd[3916]: Listen and drop on 1 v6wildcard :: UDP 123
10月 14 18:03:22 bigdata111 ntpd[3916]: Listen normally on 2 lo 127.0.0.1 UDP 123
10月 14 18:03:22 bigdata111 ntpd[3916]: Listen normally on 3 eno16777736 192.168.1.111 UDP 123
10月 14 18:03:22 bigdata111 ntpd[3916]: Listen normally on 4 lo ::1 UDP 123
10月 14 18:03:22 bigdata111 ntpd[3916]: Listen normally on 5 eno16777736 fe80::20c:29ff:fec9:1f12 UDP 123
10月 14 18:03:22 bigdata111 ntpd[3916]: Listening on routing socket on fd #22 for interface updates
10月 14 18:03:22 bigdata111 ntpd[3916]: 0.0.0.0 c016 06 restart
10月 14 18:03:22 bigdata111 ntpd[3916]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
10月 14 18:03:22 bigdata111 ntpd[3916]: 0.0.0.0 c011 01 freq_not_set
10月 14 18:03:23 bigdata111 ntpd[3916]: 0.0.0.0 c514 04 freq_mode

10.查看主节点是否同步;

如果没有同步,则关闭防火墙或者开放123端口;

[root@bigdata111 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*LOCAL(0)        .LOCL.           5 l   16   64   37    0.000    0.000   0.000

11.修改从机的NTP配置文件

修改其他机器的NTP配置文件,确保NTP服务是在停止状态进行该操作;(根据中文注释操作)修改完毕保存退出;

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

# 注释掉如下内容
# 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
#配置上游时间服务器为本地的ntpd Server服务器(写自己主服务器的IP地址即可)
server 192.168.1.111
#配置允许上游时间服务器主动修改本机的时间(写自己主服务器的IP地址即可)
restrict 192.168.1.111 nomodify notrap noquery

12.从机同步主服务器的时间

从机同步主服务器的时间。(IP就写自己上面配置的主服务器的IP)

扫描二维码关注公众号,回复: 7466440 查看本文章
[root@bigdata112 ~]# ntpdate -u 192.168.1.111
14 Oct 18:14:23 ntpdate[4608]: adjust time server 192.168.1.111 offset -0.000193 sec

13.启动从机的NTP服务&配置开机启动NTP

从机启动NTP服务和配置开机启动;

[root@bigdata112 ~]# systemctl start ntpd.service
[root@bigdata112 ~]# systemctl enable ntpd.service

13.查看从机的NTP服务状态

[root@bigdata112 ~]# 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 一 2019-10-14 21:51:50 CST; 4min 17s ago
  Process: 860 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 862 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─862 /usr/sbin/ntpd -u ntp:ntp -g

10月 14 21:51:49 bigdata112 ntpd[862]: Listen normally on 2 lo 127.0.0.1 UDP 123
10月 14 21:51:49 bigdata112 ntpd[862]: Listen normally on 3 lo ::1 UDP 123
10月 14 21:51:49 bigdata112 ntpd[862]: Listening on routing socket on fd #20 for interface updates
10月 14 21:51:49 bigdata112 ntpd[862]: 0.0.0.0 c016 06 restart
10月 14 21:51:49 bigdata112 ntpd[862]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
10月 14 21:51:49 bigdata112 ntpd[862]: 0.0.0.0 c011 01 freq_not_set
10月 14 21:51:50 bigdata112 systemd[1]: Started Network Time Service.
10月 14 21:51:55 bigdata112 ntpd[862]: Listen normally on 4 eno16777736 192.168.1.112 UDP 123
10月 14 21:51:55 bigdata112 ntpd[862]: Listen normally on 5 eno16777736 fe80::20c:29ff:fe15:e831 UDP 123
10月 14 21:51:55 bigdata112 ntpd[862]: new interface(s) found: waking up resolver

14.查看从机的NTP服务是否同步

[root@bigdata112 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*bigdata111      LOCAL(0)         6 u   17   64   17    0.527    0.035   0.007

至此,所有的NTP操作就全部完毕了。

猜你喜欢

转载自www.cnblogs.com/ShadowFiend/p/11674525.html