CentOS 6.5_学习笔记_NTP服务器搭建

 

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 [email protected] 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 [email protected] 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 服务器上添加了防火墙规则,但还是不允许客户机获取时间,原因未知...

 

 

 

猜你喜欢

转载自www.cnblogs.com/mail8611/p/11452097.html