温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

Linux下的NTP配置

发布时间:2021-08-20 23:48:19 来源:亿速云 阅读:200 作者:chen 栏目:关系型数据库

这篇文章主要讲解了“Linux下的NTP配置”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“Linux下的NTP配置”吧!



安装环境:
Red Hat Enterprise Linux Server release 6.7 (Santiago)

一、检查服务端、客户端的ntp包是否已经安装,默认是安装的:
rpm -qa | grep ntp
rpm -q ntp

二、服务端
1.编辑ntp服务器的配置文件/etc/ntp.conf:
server 127.127.1.0               #把本机作为ntp服务端
fudge 127.127.1.0 stratum 0      #这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0
    
2.重启ntp服务:
service ntp restart(Ubuntu)

service ntpd restart(CentOS、linux)

systemctl restart ntpd(CentOS7.X、redhat linux 7以上)

3.ntp服务器的防火墙放行ntp的123端口:(如果iptable防火墙关闭则不必要做,跳过即可)
/sbin/iptables -I INPUT -p udp --dport 123 -j ACCEPT

/etc/init.d/iptables status

netstat -tlunp | grep ntp

4.检查ntp服务是否开机启动,将其设置为开机启动
chkconfig --list ntpd
chkconfig --level 345 ntpd on

三、客户端ntp client

1.编辑ntp客户端的配置文件/etc/ntp.conf,添加server_ip:
server server_ip

2.启动后,一般需要5-10分钟左右的时候才能与外部时间服务器开始同步时间。可以通过命令查询NTPD服务情况。
service ntpd restart

--查看状态:
ntpq -p

或者
watch "ntpq –p"

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

--如果需要,手工同步,则需要先将client的ntp服务停掉:

servict ntpd stop
ntpdate ntpserver_ip

3.检查ntp服务是否开机启动,将其设置为开机启动
chkconfig --list ntpd
chkconfig --level 345 ntpd on

实例:
客户端:
[root@one ~]#  grep -v ^# /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server 192.168.56.20 prefer
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
[root@one ~]#
[root@one ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 192.168.56.20   .LOCL.           1 u   27   64  177    0.167  2100350 8577226
[root@one ~]#
[root@one ~]#  ntpstat
synchronised to unspecified at stratum 2
   time correct to within 14779 ms
   polling server every 64 s
[root@one ~]#

服务端端server_ip端:
[root@slient ~]#  grep -v ^# /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
server 127.127.1.0
fudge 127.127.1.0 stratum 0
[root@slient ~]#

感谢各位的阅读,以上就是“Linux下的NTP配置”的内容了,经过本文的学习后,相信大家对Linux下的NTP配置这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是亿速云,小编将为大家推送更多相关知识点的文章,欢迎关注!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI