您的位置:首页 > 运维架构 > Linux

NTP(时间)服务器安装&配置&初体验(CentOS)

2016-01-28 18:19 661 查看

介绍

参考wikipedia:Network Time Protocol (NTP) is a networking protocol for clock synchronization between computer systems over packet-switched, variable-latency data networks。

参考百度百科:NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

环境

2台Centos 7

1个用作NTP服务端:192.168.1.101

1个用作NTP客户端:192.168.1.102

系统版本均如下:

[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core


安装

执行命令

yum -y install ntp


查看安装后的服务: (ntp的服务名称是ntpd。)

service ntpd status


可以看到如下输出:服务还未启动

[root@localhost ~]# service ntpd status
Redirecting to /bin/systemctl status  ntpd.service
ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; disabled)
Active: inactive (dead) since Thu 2016-01-28 17:49:27 CST; 1s ago
Process: 16123 ExecStart=/usr/sbin/ntpd -u ntp:ntp $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 16124 (code=exited, status=0/SUCCESS)


启动服务

service ntpd start


配置

配置文件:
/etc/ntp.conf


修改允许其他主机通过本ntp服务器查询、同步

配置文件中默认只允许本机进行查询,如下

restrict 127.0.0.1
restrict ::1


将上面的内容按照下面的格式进行修改

restrict [ip] mask [mask] [parameter]


例如

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap


其中parameter可以是如下值

ignore:居然所有类型的ntp连接

nomodify:不允许客户端修改服务器的时间参数,但是允许客户端透过这部主机进行时间校验。

noquery:不允许客户端进行时间校验。

notrap:不提供trap时间登录

notrust:拒绝没有认证的客户端

修改上游NTP服务器地址(如果默认的可以访问,则可以跳过此配置)

关于上有NTP服务器的配置是
server [hostname]
字段

server 0.centos.pool.ntp.org iburst
....
....


照葫芦画瓢,按照上面的格式即可增加自己的上有NTP服务器地址

重启服务

service ntpd restart


测试验证

在客户端进行如下操作

安装ntpdate(如果已安装,则跳过此步骤)

安装方式与安装ntp相同,但安装后默认不启动ntpd服务,只是为了安装一个ntpdate

yum install ntp


修改本机时间

将本机时间修改为一个过去的时间

[root@localhost ~]# date -s 20000101
Sat Jan  1 00:00:00 HKT 2000

[root@localhost ~]#


同步时间

通过命令
ntpdate -u [hostname-of-server]
进行时间同步,例如:

[root@localhost ~]# ntpdate -u 192.168.1.101
28 Jan 18:10:41 ntpdate[15174]: step time server 192.168.1.101 offset 507319821.530152 sec
[root@localhost ~]#


可以看到已经修复了时间。

参考

参考1

参考2

参考3
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息