NTP时间服务器

服务端部署

安装所需软件包

[root@test ~]# yum -y install ntp ntpdate

编辑NTP主配置文件,添加NTP服务器(对于大陆地区的服务器)并同步BIOS时间。

对于位于中国大陆地区IDC机房的服务器,由于CentOS/RHEL默认的ntp服务器无法访问,因此要设置中国大陆地区自己的ntp服务器;
对于位于中国大陆地区以外的IDC机房的服务器,可以使用CentOS/RHEL默认的ntp服务器(但一定要检查确保可以访问);
修改如下:

cat <<  EOF >> /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
server ntp1.aliyun.com  iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp.sjtu.edu.cn iburst
server  s1a.time.edu.cn iburst
server ntp7.aliyu.com
fudge 127.0.0.1 stratum 10 includefile /etc/ntp/crypto/pw keys /etc/ntp/keys restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap disable monitor EOF

说明 :只允许制定网段的客户机进行时间同步。如果允许任何IP的客户机都可以进行时间同步,就修改为"restrict default nomodify"

重启ntpd服务器

[root@test ~]# service  ntpd  start  
[root@test ~]# ckconfig --add  ntpd    
[root@test ~]# ckconfig   ntpd  on   
=========#centos6 版本==============

[root@test ~]# systemctl start ntpd 
[root@test ~]# systemctl enable ntpd
========= #centos7.x版本以上==========

服务端设置任务计划

服务端可以设置定期在线同步一次时间

[root@test ~]# crontab -e
0 * * * *  /usr/sbin/ntpdate ntp1.aliyun.com > /dev/null 2>&1

客户端配置ntpdate方法 

安装ntpdate软件包

[root@test ~]# yum -y install  ntpdate  

配置任务计划

命令行手动执行一次验证是否可用:
[root@test2 ~]# ntpdate  上面部署ntp时间服务器ip             #是上面ntp服务器的ip地址
21 Jun 16:45:35 ntpdate[2323]: adjust time server 上面部署ntp时间服务ip   offset 0.319548 sec
配置自动同步
[root@test2 ~]# crontab -l
#服务器时间同步
*/5 * * * *  /usr/sbin/ntpdate 上面部署ntp时间服务器ip > /dev/null 2>&1

centos7.x 防火墙配置

#开放NTP端口
firewall-cmd --add-port=123/udp --permanent

#重载防火墙规则
firewall-cmd --reload

centos6.x 至5.x配置防火墙方法

[root@localhost ~]# iptables -A INPUT -p udp -m udp  --dport 123 -j ACCEPT
[root@localhost ~]# service iptables save

公共NTP服务器

阿里云NTP时间同步服务器 

Unix类系统:time1-7.aliyun.com
Windows: time.pool.aliyun.com

ntp1.aliyun.com
ntp2.aliyun.com
ntp3.aliyun.com
ntp4.aliyun.com
ntp5.aliyun.com
ntp6.aliyun.com
ntp7.aliyun.com 

国内各个大学公开ntp时间服务器地址

ntp.sjtu.edu.cn 202.120.2.101 (上海交通大学网络中心NTP服务器地址)
s1a.time.edu.cn	北京邮电大学
s1b.time.edu.cn	清华大学
s1c.time.edu.cn	北京大学
s1d.time.edu.cn	东南大学
s1e.time.edu.cn	清华大学
s2a.time.edu.cn	清华大学
s2b.time.edu.cn	清华大学
s2c.time.edu.cn	北京邮电大学
s2d.time.edu.cn	西南地区网络中心
s2e.time.edu.cn	西北地区网络中心
s2f.time.edu.cn	东北地区网络中心
s2g.time.edu.cn	华东南地区网络中心
s2h.time.edu.cn	四川大学网络管理中心
s2j.time.edu.cn	大连理工大学网络中心
s2k.time.edu.cn CERNET桂林主节点
s2m.time.edu.cn 北京大学

全球ntp时间服务网址

http://www.ntp.org.cn/pool.php

 

posted @ 2019-03-14 23:03  Boks  阅读(420)  评论(0)    收藏  举报