如何搭建NTP时间同步服务器

sudo timedatectl set-timezone Asia/Shanghai

①安装NTPD服务端

rpm -qa |grep ntp

检测是否已经安装,如未安装执行yum安装服务

yum install ntp

②关闭防火墙或开放端口

service iptables stop 
chkconfig iptables off
iptables -A INPUT -p tcp --dport 123 -j ACCEPT
iptables -A INPUT -p udp --dport 123 -j ACCEPT

③修改配置文件/etc/ntp.conf

​ 添加如下内容

​restrict 192.168.100.0 mask 255.255.255.0 nomodify notrap
​server 127.127.1.0 # localclock
​fudge 127.127.1.0 stratum 10

​注释或删除服务器

#server 0.centos.pool.ntp.org iburst
​#server 1.centos.pool.ntp.org iburst
​#server 2.centos.pool.ntp.org iburst
​#server 3.centos.pool.ntp.org iburst

④修改配置文件/etc/sysconfig/ntpd 使硬件时间与系统时间同步

添加如下内容

SYNC_HWLOCK=yes

⑤重启NTPD服务并设置开机启动

service ntpd restart
chkconfig ntpd on

⑥验证NTP服务启动状态

查看ntpd服务的端口情况

ss -tunlp|grep ntp

确认本地NTP与上层NTP服务器是否通联

ntpstat

查看本地NTP需进行同步的公网NTP服务器状态

ntpq -p

 

手动指定时间 date -s "20110315 15:12:23"

如何确认我们的NTP服务器已经更新了自己的时间呢?

ntpstat

查看节点同步状态 ntpq -p

点赞

发表评论

电子邮件地址不会被公开。必填项已用 * 标注