版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/Tiger_lin1/article/details/87809914
NTP时间服务器是用于局域网服务器同步时间使用的,可以保证局域网所有的时间服务器时间服务器的时间保持一致, 某些应用对时间实时
性要求高的必须统一时间。互联网的时间服务器也有很多,例如 ntpdate ntp.fudan.edu.cn 复
旦大学的 NTP 免费提供互联网时间同步。NTP 服务器监听端口为 UDP 的 123,那就需要在本地防火墙开启运行客户端访问 123 端口
centos 6下
vi /etc/sysconfig/iptables 添加如下规则:
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
centos 7下
firewall-cmd --zone=public --add-port=123/udp --permanent
firewall-cmd --reload
NTP 时间服务器配置:
yum -y install ntp ntpdate
修改 ntp.conf 配置文件
grep -n "^[a-z]" /etc/ntp.conf #过滤配置文件
4:driftfile /var/lib/ntp/drift #默认的
9:restrict default nomodify #注释掉地8行,添加这行,表示nomodify客户端可以同步时间。
14:restrict 127.0.0.1 #默认的
15:restrict ::1 #默认的
26:server ntp1.aliyun.com #添加时间源
27:server time.nist.gov #添加时间源
39:includefile /etc/ntp/crypto/pw #以下都是默认的
43:keys /etc/ntp/keys
61:disable monitor
启动时间服务器
systemctl start ntpd
netstat -lnuto|grep 123 #查看端口
udp 0 0 192.168.122.1:123 0.0.0.0:* off (0.00/0/0)
udp 0 0 192.168.3.144:123 0.0.0.0:* off (0.00/0/0)
udp 0 0 127.0.0.1:123 0.0.0.0:* off (0.00/0/0)
udp 0 0 0.0.0.0:123 0.0.0.0:* off (0.00/0/0)
udp6 0 0 fe80::d391:779c:b33:123 :::* off (0.00/0/0)
udp6 0 0 ::1:123 :::* off (0.00/0/0)
udp6 0 0 :::123 :::* off (0.00/0/0)
启动后确认:
#ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*120.25.115.20 10.137.53.7 2 u 12 64 7 32.328 3.748 1.922
203.107.6.88 100.107.25.114 2 u 11 64 7 21.925 0.144 1.553
发现两个可用的时间资源
稍等几分钟后,在客户端同步时间
1、与时间服务器同步时间
ntpdate -d 192.168.3.144
2、设置时间同步脚本
crontab -l
*/5 * * * * ntpdate 192.168.3.144 >/dev/null 2>&1* * * * ntpdate 192.168.56.100 >/dev/null 2>&1
至此,内网的时间服务器就安装完成了,所有的内网服务器都可以到时间服务器来同步时间,不需要到公网上去同步时间了。