部署ntp服务

为什么要这么做?

在我们的服务器集群中,有三种问题是最难排查的:

  1. 因为selinux造成的问题
  2. 因为防火墙造成的
  3. 因为时间不同造成的

所以在整个集群中时间的同步尤其重要,我们不能让数据库等服务器暴露在公网,同时我们也需要校对时间,所以我们需要配置一个时间同步服务

本机环境:

[root@m02 ~]# cat /etc/redhat-release 
CentOS Linux release 7.4.1708 (Core) 
[root@m02 ~]# uname -r
3.10.0-693.el7.x86_64

安装ntp服务:

[root@m02 ~]# yum install -y ntp
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.aliyun.com
 * epel: mirrors.aliyun.com
 * extras: mirrors.aliyun.com
 * updates: mirrors.aliyun.com
Package ntp-4.2.6p5-25.el7.centos.2.x86_64 already installed and latest version
Nothing to do
[root@m02 ~]# rpm -qa ntp
ntp-4.2.6p5-25.el7.centos.2.x86_64

配置ntp:/etc/ntp.conf

两个关键点:

第一个位置:用来设置网段和子网掩码以及权限

第二个位置:ntp服务需要同步的上级服务

 启动ntp服务:

[root@m02 ~]# systemctl start ntpd
[root@m02 ~]# systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-11-16 09:17:03 CST; 6h ago
 Main PID: 1575 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─1575 /usr/sbin/ntpd -u ntp:ntp -g

Nov 16 11:30:11 m02 ntpd[1575]: new interface(s) found: waking up resolver
Nov 16 11:34:30 m02 ntpd[1575]: Deleting interface #10 eth0, fe80::8a2a:ff08:cb95:36c5...secs
Nov 16 11:34:34 m02 ntpd[1575]: Listen normally on 11 eth0 fe80::8a2a:ff08:cb95:36c5 UDP 123
Nov 16 11:34:34 m02 ntpd[1575]: new interface(s) found: waking up resolver
Nov 16 12:02:35 m02 ntpd[1575]: Deleting interface #11 eth0, fe80::8a2a:ff08:cb95:36c5...secs
Nov 16 12:02:38 m02 ntpd[1575]: Listen normally on 12 eth0 fe80::8a2a:ff08:cb95:36c5 UDP 123
Nov 16 12:02:38 m02 ntpd[1575]: new interface(s) found: waking up resolver
Nov 16 15:11:31 m02 ntpd[1575]: Deleting interface #12 eth0, fe80::8a2a:ff08:cb95:36c5...secs
Nov 16 15:11:34 m02 ntpd[1575]: Listen normally on 13 eth0 fe80::8a2a:ff08:cb95:36c5 UDP 123
Nov 16 15:11:34 m02 ntpd[1575]: new interface(s) found: waking up resolver
Hint: Some lines were ellipsized, use -l to show in full.

 查看同步链接(监视ntp)

[root@m02 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 182.92.12.11    .XFAC.          16 u   5h 1024    0    0.000    0.000   0.000
 173.255.215.209 .XFAC.          16 u    - 1024    0    0.000    0.000   0.000
 202.108.6.95    .XFAC.          16 u   5h 1024    0    0.000    0.000   0.000
 61.216.153.105  .XFAC.          16 u    - 1024    0    0.000    0.000   0.000
 212.47.249.141  .XFAC.          16 u   6h 1024    0    0.000    0.000   0.000

 ntp的工作状态:

[root@m02 ~]# ntpstat 
synchronised to unspecified at stratum 3 
   time correct to within 292 ms
   polling server every 256 s

 客户端测试:

[root@m01 ~]# ntpdate 172.16.1.62
16 Nov 09:23:36 ntpdate[1270]: step time server 172.16.1.62 offset -2.630123 sec
[root@m01 ~]# ntpdate -d 172.16.1.62
16 Nov 09:24:04 ntpdate[1271]: ntpdate 4.2.6p5@1.2349-o Mon Feb  6 07:22:46 UTC 2017 (1)
Looking for host 172.16.1.62 and service ntp
host found : 172.16.1.62
transmit(172.16.1.62)
原文地址:https://www.cnblogs.com/ExzaiTin/p/7845033.html