Fedora 25 NTP服务器配置
一、安装ntp服务
yum install -y ntp
二、设置时区
1、查看系统提供的时区信息
[root@localhost ~]# ls -F /usr/share/zoneinfo/
Africa/ Brazil/ Egypt GB-Eire HST Japan Navajo posixrules Turkey zone.tab
America/ Canada/ Eire GMT Iceland Kwajalein NZ PRC UCT Zulu
Antarctica/ CET EST GMT0 Indian/ Libya NZ-CHAT PST8PDT Universal
Arctic/ Chile/ EST5EDT GMT-0 Iran MET Pacific/ right/ US/
Asia/ CST6CDT Etc/ GMT+0 iso3166.tab Mexico/ Poland ROC UTC
Atlantic/ Cuba Europe/ Greenwich Israel MST Portugal ROK WET
Australia/ EET GB Hongkong Jamaica MST7MDT posix/ Singapore W-SU
在这里面可以找到自己所在城市的time zone文件,例如北京时间就是这个文件
[root@localhost ~]# ls -F /usr/share/zoneinfo/Asia/Shanghai
/usr/share/zoneinfo/Asia/Shanghai
查看每个time zone当前的时间可以使用zdump命令
[root@localhost ~]# zdump Japan
Japan Thu Feb 16 12:01:34 2017 JST
若要修改系统时区可以使用如下方法
[root@localhost ~]# rm -rf /etc/localtime
[root@localhost ~]# ln -sf /usr/share/zoneinfo/posix/Asia/Shanghai /etc/localtime
[root@localhost ~]# ll /etc/localtime
lrwxrwxrwx. 1 root root 35 Feb 16 2017 /etc/localtime -> ../usr/share/zoneinfo/Asia/Shanghai
[root@localhost ~]# date
Thu Feb 16 11:05:24 CST 2017
三、同步硬件时间和系统时间
首先明确一个概念:
在计算机上有两个时钟,一个是硬件时钟(RTC),一个是系统时钟(System Clock)
硬件时钟(RTC)是指嵌在主板上的特殊的电路,他的存在就是平时我们关机后还可以计算时间的原因。
系统时钟(System Clock)是操作系统的kernel用来计算时间的时钟,它从1970年1月1日00:00:00 UTC时间到目前为止秒数总和的值 在Linux下系统时间在开机的时候会和硬件时间同步(synchronization),之后也就各自独立运行了
既然两个时钟独立运行,时间久了就会产生误差,
[root@localhost ~]# date
Thu Feb 16 11:13:04 CST 2017
[root@localhost ~]# hwclock --show
2017-02-16 11:13:05.679891+8:00
通过hwclock –show 命令我们可以查看机器上的硬件时间(always in local time zone), 我们可以看到它和系统时间还是有一定的误差的, 那么我们就需要把他们同步
如果我们想要把硬件时间设置成系统时间我们可以运行以下命令
[root@localhost ~]# hwclock --hctosys
反之,我们也可以把系统时间设置成硬件时间
[root@localhost ~]# hwclock --systohc
那么如果想设置硬件时间我们可以开机的时候在BIOS里设定.也可以用hwclock命令
[root@localhost ~]# hwclock --set --date="mm/dd/yy hh:mm:ss"
如果想要修改系统时间那么用date命令就最简单了
[root@localhost ~]# date -s "dd/mm/yyyy hh:mm:ss"
四、修改ntp.conf的配置
vim /etc/ntp.conf
配置示例:
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
# 将自己主机的bios芯片震荡频率与上层的Time server频率比较,将误差记录在这个文件里
# 注意: driftfile 后面接的文件需要使用完整的路径文件名,不能是链接文件,并且文件的权限需要设定成 ntpd守护进程可以写入。
# 格式:driftfile 文件名driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.# 格式:restrict [IP] mask [netmask_IP] [parameter]# Parameter 的参数主要如下:
# ignore :拒绝所有类型的NTP联机。
# nomodify: 客户端不能使用ntpc 与ntpq 这两个程序来修改服务器的时间参数,但客户端可透过这部主机来进行网络校时;
# noquery:客户端不能够使用ntpc 与ntpq 等指令来查询时间服务器,不提供NTP的网络校时。
# notrap:不提供trap 这个运程事件登入的功能。
# notrust:拒绝没有认证的客户端。
# Kod:kod技术可以阻止“Kiss of Death “包对服务器的破坏。
# Nopeer:不与其他同一层的NTP服务器进行时间同步。
# 如果没有在parameter的地方加上任何参数的话,那么表示这个ip或网络不受任何限制# 表示默认拒绝所有IP的时间同步
#restrict default nomodify notrap nopeer noquery
# 允许任何ip的客户机都可以进行时间同步
restrict default nomodify# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions.
# 允许本机环回地址可以进行时间同步
restrict 127.0.0.1
restrict ::1# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# 允许192.168.159.0/24网段的客户机都可以进行时间同步
restrict 192.168.159.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).# 利用server 设定上层NTP服务器
# 格式:server [IP or hostname] [prefer]
# perfer:表示优先级最高
# burst :当一个运程NTP服务器可用时,向它发送一系列的并发包进行检测。
# iburst :当一个运程NTP服务器不可用时,向它发送一系列的并发包进行检测。
# 注:默认情况小15分钟后才会与上层NTP服务器进行时间校对。server 210.72.145.44 prefer
server time1.aliyun.com iburst
server time2.aliyun.com iburst
server time3.aliyun.com iburst
server time4.aliyun.com iburst# 设置本地服务器为根时间服务器
server 127.127.1.0
# 这行是时间服务器的层次。设为0则为顶级,如果要向别的NTP服务器更新时间,请不要把它设为0
fudge 127.127.1.0 stratum 6#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.
#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
# 认证可以使用此时间源的客户端
keys /etc/ntp/keys# Specify the key identifiers which are trusted.
#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.
#requestkey 8# Specify the key identifier to use with the ntpq utility.
#controlkey 8# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc
# monlist command when default restrict does not include the noquery flag. See
# CVE-2013-5211 for more details.
# Note: Monitoring will not be disabled with the limited restriction flag.
# 防御NTP放大攻击和NTP反射
disable monitor
五、启动ntpd服务,并配置开机启动
[root@localhost ~]# systemctl restart ntpd
[root@localhost ~]# systemctl enable ntpd
[root@localhost ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since Thu 2017-02-16 11:36:29 CST; 12s ago
Main PID: 2819 (ntpd)
Tasks: 1 (limit: 19660)
CGroup: /system.slice/ntpd.service
└─2819 /usr/sbin/ntpd -u ntp:ntp -g
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listen normally on 4 ens34 192.168.139.135 UDP 123
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listen normally on 5 virbr0 192.168.122.1 UDP 123
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listen normally on 6 ens33 fe80::20c:29ff:febf:9bc9 UDP 123
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listen normally on 7 lo ::1 UDP 123
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listen normally on 8 ens34 fe80::15cc:96ee:f841:b516 UDP 123
Feb 16 11:36:29 admin.example.local ntpd[2819]: Listening on routing socket on fd #25 for interface updates
Feb 16 11:36:29 admin.example.local ntpd[2819]: 0.0.0.0 c016 06 restart
Feb 16 11:36:29 admin.example.local ntpd[2819]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
Feb 16 11:36:29 admin.example.local ntpd[2819]: 0.0.0.0 c011 01 freq_not_set
Feb 16 11:36:31 admin.example.local ntpd[2819]: 0.0.0.0 c614 04 freq_mode
六、查看ntp服务运行状况
# watch ntpq -p
各列的释义:
列值 | 释义 |
---|---|
remote | 它指的就是本地机器所连接的远程NTP服务器 |
refid | 它指的是给远程服务器(e.g. 193.60.199.75)提供时间同步的服务器 |
st | 远程服务器的层级别(stratum). 由于NTP是层型结构,有顶端的服务器,多层的Relay Server再到客户端. 所以服务器从高到低级别可以设定为1-16. 为了减缓负荷和网络堵塞,原则上应该避免直接连接到级别为1的服务器的. |
t | 这个…..我也不知道啥意思^_^ |
when | 我个人把它理解为一个计时器用来告诉我们还有多久本地机器就需要和远程服务器进行一次时间同步 |
poll | 本地机和远程服务器多少时间进行一次同步(单位为秒). 在一开始运行NTP的时候这个poll值会比较小,那样和服务器同步的频率也就增加了,可以尽快调整到正确的时间范围.之后poll值会逐渐增大,同步的频率也就会相应减小 |
reach | 这是一个八进制值,用来测试能否和服务器连接.每成功连接一次它的值就会增加 |
delay | 从本地机发送同步要求到服务器的round trip time |
offset | 这是个最关键的值, 它告诉了我们本地机和服务器之间的时间差别.offset越接近于0,我们就和服务器的时间越接近 |
jitter | 这是一个用来做统计的值. 它统计了在特定个连续的连接数里offset的分布情况. 简单地说这个数值的绝对值越小我们和服务器的时间就越精确 |
在这里会发现两个问题:
1. 我们连接的是0.fedora.pool.ntp.org为什么和remote server不一样?
2. 那个最前面的+和*都是什么意思呢?
第一个问题不难理解,因为NTP提供给我们的是一个cluster server所以每次连接的得到的服务器都有可能是不一样。同样这也告诉我们了在指定NTP Server的时候应该使用hostname而不是IP。
第二个问题和第一个相关,既然有这么多的服务器就是为了在发生问题的时候其他的服务器还可以正常地给我们提供服务.那么如何知道这些服务器的状态呢? 这就是第一个记号会告诉我们的信息
标记 | 释义 |
---|---|
* | 它告诉我们远端的服务器已经被确认为我们的主NTP Server,我们系统的时间将由这台机器所提供 |
+ | 它将作为辅助的NTP Server和带有号的服务器一起为我们提供同步服务. 当号服务器不可用时它就可以接管 |
- | 远程服务器被clustering algorithm认为是不合格的NTP Server |
x | 远程服务器不可用 |
Fedora 25 NTP服务器配置相关推荐
- php7降到5.6,如何在Fedora 25上从php 7降级到5.6
我在服务器上安装了Fedora 25,需要将php从7降级到5.6. 我做了以下事情: dnf remove php dnf remove php-common wget https://rpms.r ...
- 如何在Raspberry Pi上安装Fedora 25
2016年10月,宣布了Fedora 25 Beta的发布,以及对Raspberry Pi 2和3的最初支持 . 一个月后发布了Fedora 25的最终"通用"版本,从那时起,我一 ...
- 虚拟机fedora共享_开源虚拟现实,用于电子测试的新电路板,Fedora 25,以及更多新闻
虚拟机fedora共享 在本周的开源新闻摘要中,我们介绍了开源虚拟现实,用于电子测试的新电路板,Fedora 25等. 2016年11月20日至28日的开源新闻摘要 开源虚拟现实平台在Steam上启动 ...
- 如何在树莓派上安装Fedora 25
了解 Fedora 第一个官方支持树莓派的版本 2016 年 10 月,Fedora 25 Beta 发布了,随之而来的还有对 树莓派 2 和 3 的初步支持.Fedora 25 的最终"通 ...
- linux时间同步负数,Ubuntu 18.04 Bionic Beaver Linux上的NTP服务器配置
目的 目的是在Ubuntu 18.04 Bionic Beaver Linux上配置NTP服务器 操作系统和软件版本 操作系统:-Ubuntu 18.04仿生海狸 软件:-ntpd 4.2.8或更高版 ...
- linux面板切换快捷键,Fedora 25 Gnome常用快捷键、快捷操作
Fedora 25 Gnome快捷键.快捷操作--时用时查,不用记住快捷键也能大大提高办公效率. 每个操作系统都会有很多快捷键可用,Fedora系统作为非常流行的linux发行版,也有非常多快捷键,大 ...
- fedora linux搜狗输入法,在Linux系统 Fedora 25 安装 搜狗拼音输入法
题记:因为使用fedora 25默认的输入法感受不太习惯,因此折腾想更换成搜狗输入法,致使以前的输入法也不能用了,查了半天资料终于弄好了.架构 1.查看已安装的输入法oracle 要在当前用户状态下查 ...
- win2003修改ntp服务器,win2003设置ntp服务器配置
win2003设置ntp服务器配置 内容精选 换一换 以NTP服务器.DNS服务器的操作系统均为SUSE为例:登录Linux弹性云服务器.执行以下命令,切换至root用户.sudo su -sudo ...
- Linux系统如何安装PDF编辑器,Fedora 25 下安装开源PDF文件编辑工具 PDF Mod
PDF文件具有非常好的跨平台属性,无论你在哪个平台用哪个PDF阅读器打开,其格式是永远不变的.但是缺点也很明显,文本文件或者图文混排文件,要想再次编辑就有很大难度了. Document viewer作 ...
最新文章
- Git创建本地分支并关联远程分支
- 干货丨计算机视觉必读:目标跟踪、网络压缩、图像分类、人脸识别等
- Two Sum [easy] (Python)
- 【独家】百度移动云高级美女产品经理:O2O日趋火爆,下个估值过亿的上门美业将花落谁家?...
- 推荐《求医不如求己》,实用
- Visual Studio 2008的注册方法(解除试用90天)
- 随机邻域嵌入_图嵌入(Graph embedding)综述
- 下一代 Windows 将至,是全新的 Windows 11 还是 Windows 10 的延续?
- Asp.Net Core Mvc上Json序列化首字母大小写的问题
- InstallShield 模块详解
- 35KV,110KV变电所设计,供配电电气部分设计
- 计算机网络毕业设计选题背景,毕业设计论文选题依据与背景
- 【软件安装使用】pano2vr教程
- Java项目中这样打印错误日志,排查问题更高效
- Djano3.0使用-CBV使用实例
- 应用程序“Parallels Desktop“无法打开MAC电脑打不开
- 单片机STM8S测量电压电路_纸张计数测量显示装置+【2019年电赛F题国一获奖作品】...
- EChat(简易聊天项目)三、聊天界面UI实现
- 脚本语言、编程语言、中间件
- springmvc笔记回顾——持续更新