Linux系统下使用NTP服务器的教程详解
时间:2022-11-16 11:35:46
众所周知,Linux系统下的NTP服务器指的是网络时间同步协议,其作用就是同步网络时间和Linux系统中的时间,使得Linux时间更加精确。但是很多用户不知道如何使用,下面我们就一起来看看Linux系统下使用NTP服务器的教程详解。
一、ntp配置文件
1. /etc/ntp.conf
NTP服务的主要配置文件,不同的Linux版本文件所在的目录可能会不同。
2. /usr/share/zoneinfo
规定了各主要时区的时间设定文件。/usr/share/zoneinfo/Asia/Shanghai 为中国大陆地区的时区设定文件。
3. /etc/sysconfig/clock
时区设置文件
4. /etc/localtime
本地系统的时间设定文件
[root@linuxidc1 ~]# grep -v “^#” /etc/ntp.conf
restrict default kod nomodify notrap nopeer noquery//对于默认的client拒绝所有的操作
restrict -6 default kod nomodify notrap nopeer noquery //针对ipv6的设置
restrict 127.0.0.1 //允许本机地址一切的操作
restrict -6 ::1
server 0.rhel.pool.ntp.org //设置上层服务器做同步ip地址
server 1.rhel.pool.ntp.org
server 2.rhel.pool.ntp.org
server 127.127.1.0 //local地址
fudge 127.127.1.0 stratum 10 //这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0
driftfile /var/lib/ntp/drift //记录上次的NTP server与上层NTP server联接所花费的时间
keys /etc/ntp/keys
参数:
ignore:关闭所有的 NTP 联机服务
nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。
notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网
noquery :不提供客户端的时间查询
[page]
二、具体配置
[root@linuxidc1 ~]# vim /etc/ntp.conf
3 restrict default kod nomodify notrap nopeer noquery
4 #restrict -6 default kod nomodify notrap nopeer noquery
5 restrict default nomodify
6 restrict 192.168.8.0 mask 255.255.255.0 nomodify
11 restrict 127.0.0.1
18 #server 0.rhel.pool.ntp.org
19 #server 1.rhel.pool.ntp.org
20 #server 2.rhel.pool.ntp.org
21 server 192.168.8.70
31 server 127.127.1.0 # local clock
32 fudge 127.127.1.0 stratum 10
[root@linuxidc1 ~]# /etc/init.d/ntpd restart
Shutting down ntpd: [ OK ]
Starting ntpd: [ OK ]
客户端测试
注:客户端的/etc/hosts里需要加上ntp服务器的ip地址和主机名
[root@linuxidc2 ~]# ntpdate 192.168.8.70
2 Mar 00:35:44 ntpdate[11181]: no server suitable for synchronization found
注:在ntp server上启动ntp服务后,ntp server自身或者与其server的同步的需要一个时间段,这个过程可能是5分钟,在这个时间之内在客户端运行ntpdate命令进行同步时会产生 no server suitable for synchronization found的错误。
查看同步的过程
[root@linuxidc1 ~]# watch ntpq -p
注:LOCAL的这个就是与自身同步的ntp server。reach这个值,在启动ntp server服务后,这个值就从0开始不断增加,当增加到17的时候,从0到17是5次的变更,每一次是poll的值的秒数,是64秒*5=320秒的时间。
客户端测试
[root@linuxidc2 ~]# ntpdate 192.168.8.70
2 Mar 00:40:51 ntpdate[11184]: adjust time server 192.168.8.70 offset -0.000031 sec
[root@linuxidc2 ~]# date
Sat Mar 2 01:00:13 CST 2013
服务器端
[root@linuxidc1 ~]# date
Sat Mar 2 01:00:15 CST 2013
[root@linuxidc1 ~]#
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
centos环境变量如何设置安全问题?
![](https://img.aspxhome.com/file/2023/2/a286581_0s.jpg)
Win10玩饥荒闪退怎么回事?Win10电脑开启饥荒出现闪退解决方法
![](https://img.aspxhome.com/file/2023/25/a216915_0s.png)
Win7开机自检出现Floopy disk fail错误解决方法
Win7不能新建Word文档提示“内存不足”的解决方法
![](https://img.aspxhome.com/file/2023/4/a303148_0s.jpg)
安装软件提示无法访问windows installer服务怎么办
![](https://img.aspxhome.com/file/2023/1/a273768_0s.jpg)
excel表格内建立图表的教程
reader_sl.exe - reader_sl进程有什么用.
Excel数据分列方法讲解
![](https://img.aspxhome.com/file/2023/9/37549_0s.jpg)
手机wps插入表格的方法步骤
Win10怎么隐藏任务栏的图标?Win10隐藏任务栏的图标方法
![](https://img.aspxhome.com/file/2023/1/a279637_0s.jpg)
如何修改ppt撤销次数
电脑浏览网页提示Flash版本过低怎么办?
![](https://img.aspxhome.com/file/2023/6/a326103_0s.jpg)
Excel 2019 如何显隐功能区
![](https://img.aspxhome.com/file/2023/1/a141101_0s.jpg)
Win10还原系统失败怎么办?电脑还原失败的解决方法
![](https://img.aspxhome.com/file/2023/26/a221688_0s.png)
WPS演示办公—PPT幻灯片转换成JPG图片集
你也会画EXCEL地图!
![](https://img.aspxhome.com/file/2023/8/a142238_0s.jpg)
Wps如何快速创建表格文件超链接?Wps快速创建表格文件超链接的方法
![](https://img.aspxhome.com/file/2023/5/a182265_0s.gif)
word九宫格图片怎么做?用word做九宫格图片方法教程
![](https://img.aspxhome.com/file/2023/30/a268041_0s.jpg)
爱奇艺怎么切换账号?账户切换方法简介
![](https://img.aspxhome.com/file/2023/7/a331569_0s.jpg)
在Word中搜索相关法律法规的方法
![](https://img.aspxhome.com/file/2023/6/17956_0s.jpg)