centos7部署时间同步(ntp)服务器

avatar
作者
猴君
阅读量:3

centos7部署时间同步(ntp)服务器

这里搭建ntp服务器,服务端和客户端,客户端去拉取服务端的时间,为自己所用。

小白教程,一看就会,一做就成。

1.服务端搭建

a.安装ntp

yum -y install ntp*

b.配置文件

vim /etc/ntp.conf

最后加上下面的

#添加常用的授时服务器,允许上层时间服务器主动修改本机时间 server ntp1.aliyun.com server time1.aliyun.com server 127.127.1.0 	# 本地时钟服务器

c.开启服务

#启动 systemctl start ntpd.service #开机自启 systemctl enable ntpd.service #重启 systemctl restart ntpd.service

d.确认NTP同步正常

ntpstat

输出是 synchronised to NTP server 那证明已经连上了NTP服务器,

如果输出是 unsynchronised 开头的 那证明还没有连上NTP服务器,过几分钟再试一下

2.客户端

a.安装ntp服务,只安装就行(不要启动)

yum -y install ntp*

b.同步服务端的时间

/usr/sbin/ntpdate 192.168.220.138 && hwclock --systohc #ip是我的服务端的

c.加定时计划,10分钟执行一次

crontab -e #然后加上下面的 */10 * * * *      /usr/sbin/ntpdate 192.168.220.138 && hwclock --systohc

3.客户端同步出现的问题及解决方法

a.同步时出现下面的

是因为客户端的ntp服务 没关闭(可能是客户端安装ntp时,不小心启动了)

执行

systemctl stop ntpd.service

b.如果出现下图(请忽略ip),就等会再执行

4.完成

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!