部署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)

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM