[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)
5.修改NTP服务器的机器的配置文件,我的是cdh1机器是服务器
[root@cdh1~]# 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
#添加以下内容,同步本地时间
server 127.127.1.0 iburst
6.启动cdh1节点的NTP服务
[root@cdh1~]# systemctl start ntpd.service
7.设置cdh1节点NTP开机启动
[root@cdh1~]# systemctl enable ntpd.service
8.在cdh1查看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-2821:17:35 CST;2min 10s ago
Main PID:72322(ntpd) CGroup:/system.slice/ntpd.service
└─72322/usr/sbin/ntpd -u ntp:ntp -g
Sep 2821:17:35 cdh1 ntpd[72322]: Listen normally on 2 lo 127.0.0.1 UDP 123
Sep 2821:17:35 cdh1 ntpd[72322]: Listen normally on 3 eno16777736 192.168.20.134 UDP 123
Sep 2821:17:35 cdh1 ntpd[72322]: Listen normally on 4 lo ::1 UDP 123
Sep 2821:17:35 cdh1 ntpd[72322]: Listen normally on 5 eno16777736 fe80::20c:29ff:fe45:70d1 UDP 123
Sep 2821:17:35 cdh1 ntpd[72322]: Listening on routing socket on fd #22forinterfaceupdates
Sep 2821:17:35 cdh1 ntpd[72322]:0.0.0.0 c016 06 restart
Sep 2821:17:35 cdh1 ntpd[72322]:0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Sep 2821:17:35 cdh1 ntpd[72322]:0.0.0.0 c011 01 freq_not_set
Sep 2821:17:35 cdh1 systemd[1]: Started Network Time Service.
Sep 2821:17:36 cdh1 ntpd[72322]:0.0.0.0 c514 04 freq_mode
9.cdh1节点查看是否同步:关闭防火墙或者开放123端口
[root@cdh1~]# ntpq -p
remote refid st t when poll
reach delay offset jitter==================================================*LOCAL(0).LOCL.5 l 476470.0000.0000.000
[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-2821:31:26 CST;38s ago Main PID:100613(ntpd)
CGroup:/system.slice/ntpd.service
└─100613/usr/sbin/ntpd -u ntp:ntp -g
Sep 2821:31:26 cdh2 ntpd[100613]: Listen and drop on 1 v6wildcard :: UDP 123
Sep 2821:31:26 cdh2 ntpd[100613]: Listen normally on 2 lo 127.0.0.1 UDP 123
Sep 2821:31:26 cdh2 ntpd[100613]: Listen normally on 3 eno16777736 192.168.20.132 UDP 123
Sep 2821:31:26 cdh2 ntpd[100613]: Listen normally on 4 lo ::1 UDP 123
Sep 2821:31:26 cdh2 ntpd[100613]: Listen normally on 5 eno16777736 fe80::20c:29ff:feb3:f5ad UDP 123
Sep 2821:31:26 cdh2 ntpd[100613]: Listening on routing socket on fd #22forinterfaceupdates
Sep 2821:31:26 cdh2 ntpd[100613]:0.0.0.0 c016 06 restart
Sep 2821:31:26 cdh2 ntpd[100613]:0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Sep 2821:31:26 cdh2 ntpd[100613]:0.0.0.0 c011 01 freq_not_set
Sep 2821:31:26 cdh2 systemd[1]: Started Network Time Service.
14.查看时间是否同步
[root@cdh2~]# ntpq -p
remote refid st t when poll
reach delay offset jitter===================================================
cdh1 LOCAL(0)6
u 146431.0929.1303.475