CentOS 6.5_学习笔记_NTP服务器搭建
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了CentOS 6.5_学习笔记_NTP服务器搭建,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3419字,纯文字阅读大概需要5分钟。
内容图文
![CentOS 6.5_学习笔记_NTP服务器搭建](/upload/InfoBanner/zyjiaocheng/1329/27929d12e9144d318f8f18c03e96414f.jpg)
NTP 服务器用于时间同步,局域网内可搭建一台 NTP 服务器,其余客户端连接 NTP 服务器获取时间,使所有客户端的时间保持一致.
1 服务器配置
------ 1.1 安装 ntp 服务
[root@ ~]#: yum install ntp ntpdate -y
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
...
Complete! # 安装完成
------ 1.2 修改配置文件
[root@ ~]#: cp /etc/ntp.conf /etc/ntp.conf.bak20190903 # 备份
[root@ ~]#: vi /etc/ntp.conf # 清空原有,输入以下:
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict -6 ::1
server 127.127.1.0 # local clock,本地时钟
server pool.ntp.org # 网络时钟
fudge 127.127.1.0 stratum 10
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
# 保存退出
------ 1.3 添加 iptables 规则
允许 ntp 服务器监听 udp 端口 123
[root@ ~]#: cp /etc/sysconfig/iptables /etc/sysconfig/iptables.bak20190913 # 备份
[root@ ~]#: vi /etc/sysconfig/iptables # 添加 -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
1 # Firewall configuration written by system-config-firewall
2 # Manual customization of this file is not recommended.
...
12 -A FORWARD -j REJECT --reject-with icmp-host-prohibited
13 -A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT # 添加于此
14 COMMIT
# 保存退出
------ 1.4 重启 iptables
[root@ ~]#: /etc/init.d/iptables restart
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
iptables:应用防火墙规则: [确定]
------ 1.5 开启 ntp 服务
[root@ ~]#: /etc/init.d/ntpd start
正在启动 ntpd: [确定]
------ 1.6 查看 ntp 服务器
[root@ ~]#: ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*LOCAL(0) .LOCL. 10 l 17 64 1 0.000 0.000 0.000 # 本地 ntp 服务器(自身)
sv1.ggsrv.de 205.46.178.169 2 u 17 64 1 387.291 0.780 0.000 # 上层 ntp 服务器
2 客户端配置
------ 2.1 客户端安装 ntp 服务
[root@ ~]#: yum install ntp ntpdate -y
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
base | 3.7 kB 00:00
...
Complete! # 安装完成
------ 2.2 修改配置文件
[root@ ~]#: cp /etc/ntp.conf /etc/ntp.conf.bak20190903 # 备份
[root@ ~]#: vi /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 192.168.10.61 # NTP 服务器IP
restrict 192.168.10.61 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
# 保存退出
------ 2.3 手动同步时间
[root@ ~]#: ntpdate -d 192.168.10.61 # ntp 服务器IP
3 Sep 13:11:08 ntpdate[1594]: ntpdate 4.2.6p5@1.2349-o Wed Dec 19 20:24:13 UTC 2018 (1)
Looking for host 192.168.10.61 and service ntp
...
transmit(192.168.10.61)
192.168.10.61: Server dropped: no data # 报错 no data
server 192.168.10.61, port 123
...
3 Sep 13:11:12 ntpdate[1594]: no server suitable for synchronization found # 报错,没有合适的服务器
排错: 在 ntp 服务器上关闭 iptables
[root@ ~]#: /etc/init.d/iptables stop # 此行在服务器上操作
iptables:将链设置为政策 ACCEPT:filter [确定]
iptables:清除防火墙规则: [确定]
iptables:正在卸载模块: [确定]
再次手动同步时间
[root@ ~]#: ntpdate -d 192.168.10.61
3 Sep 13:18:06 ntpdate[1606]: ntpdate 4.2.6p5@1.2349-o Wed Dec 19 20:24:13 UTC 2018 (1)
Looking for host 192.168.10.61 and service ntp
...
server 192.168.10.61, port 123
...
3 Sep 13:18:06 ntpdate[1606]: adjust time server 192.168.10.61 offset -0.008476 sec
可以正常使用.
虽然在 ntp 服务器上添加了防火墙规则,但还是不允许客户机获取时间,原因未知...
原文:https://www.cnblogs.com/mail8611/p/11452097.html
内容总结
以上是互联网集市为您收集整理的CentOS 6.5_学习笔记_NTP服务器搭建全部内容,希望文章能够帮你解决CentOS 6.5_学习笔记_NTP服务器搭建所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。