NTP和NTPD设置

ntp客户端安装

#yum install ntp -y

手动时间同步

#/usr/sbin/ntpdate pool.ntp.org
26 Feb 17:45:00 ntpdate[14681]: adjust time server 85.199.214.100 offset 0.004657 sec

添加计划任务

#vim /etc/crontab

SHELL=/bin/bash
PATH=/sbin:/bin:/usr/sbin:/usr/bin
MAILTO=root


# For details see man 4 crontabs


# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name  command to be executed
0  0  *  *  * /usr/sbin/ntpdate pool.ntp.org &&  /usr/sbin/hwclock --systohc 


注:ntp使用的是udp 123端口 在防火墙上一定要放开

#firewall-cmd --zone=public --add-port=123/udp --permanent

#firewall-cmd --reload


Ntp服务器的安装配置

ntpd安装

#yum install ntp -y

#systemctl start ntpd
您在 /var/spool/mail/root 中有新邮件
#systemctl status ntpd
● ntpd.service - Network Time Service
   Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled; vendor preset: disabled)
   Active: active (running) since 日 2017-02-26 17:53:24 CST; 7s ago
  Process: 14877 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
 Main PID: 14878 (ntpd)
   CGroup: /system.slice/ntpd.service
           └─14878 /usr/sbin/ntpd -u ntp:ntp -g


2月 26 17:53:24 ftp ntpd[14878]: Listen and drop on 1 v6wildcard :: UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 2 lo 127.0.0.1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 3 ens160 10.1.41.54 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 4 lo ::1 UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listen normally on 5 ens160 fe80::250:56ff:fe85:598c UDP 123
2月 26 17:53:24 ftp ntpd[14878]: Listening on routing socket on fd #22 for interface updates
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c016 06 restart
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
2月 26 17:53:24 ftp ntpd[14878]: 0.0.0.0 c011 01 freq_not_set
2月 26 17:53:31 ftp ntpd[14878]: 0.0.0.0 c614 04 freq_mode

查看ntp服务器有无和上层ntp连通

#ntpstat
synchronised to NTP server (51.15.41.135) at stratum 3 
   time correct to within 165 ms
   polling server every 64 s

 检查时间服务器的同步状态

#ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
*ntp3.itcomplian 5.103.128.88     2 u   20   64  377  206.590    4.816   0.801
+ntp4.flashdance 77.40.226.114    2 u   24   64  361  261.990   24.804   5.351
+ntp3.flashdance 194.58.202.148   2 u   27   64  173  234.689   17.706   1.152

到客户端去测试

#ntpdate 10.1.41.54
26 Feb 17:55:37 ntpdate[12641]: adjust time server 10.1.41.54 offset -0.009717 sec


OK ntp的教程完成



  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值