linux配置ntp服务器,linux中ntp时钟服务器怎么配
其实linux配置ntp服务器的问题并不复杂,但是又很多的朋友都不太了解linux中ntp时钟服务器怎么配,因此呢,今天小编就来为大家分享linux配置ntp服务器的一些知识,希望可以帮助到大家,下面我们一起来看看这个问题的分析吧!
linux怎么添加ntp服务器
个人linux系统比如ubuntu、deepin等都已经安装了,只需要勾选同步网络时间即可。
如果是服务器可以参考:
[root@localhost/]# yum install ntp-y
2.修改NTP配置文件,添加NTP服务器的网络位置/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).
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 default nomodify notrap nopeer noquery
# 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
# Use public servers from the pool.ntp.org project.Please consider joining the pool(http://www.pool.ntp.org/join.html).
server 192.168.1.1 iburst#目标服务器网络位置
#server 1.CentOS.pool.ntp.org iburst#一下三个是CentOS官方的NTP服务器,我们注释掉
#server 2.centos.pool.ntp.org iburst
#server 3.centos.pool.ntp.org iburst
#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.
#crypto
includefile/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.
disable monitor
保存退出
3.启动服务并设置开启自启
[root@localhost/]# systemctl start ntpd.service#启动服务
[root@localhost/]# systemctl enable ntpd.service#设置为开机启动
Linux系统下的NTP配置
第一步,选择最好的NTP服务地址
具体命令为ntpdate-q IP地址或域名
广东地区NTP优选结果如下:
①time4.cloud.tencent.com
②server time.asia.apple.com
③server cn.ntp.org.cn
④server ntp.aliyun.com
⑤server cn.pool.ntp.org
检查BIOS主板时间的命令
hwclock-r
NTP服务启停命令
sudo systemctl start/stop ntpd
检查查看ntp服务器有无和上层ntp连通
ntpstat
查看ntp服务器与上层ntp的状态
ntpq-pn
===server选项格式===
server host [ key n ] [ version n ] [ prefer ] [ mode n ] [ minpoll n ] [ maxpoll n ] [ iburst ]
其中host是上层NTP服务器的IP地址或域名,随后所跟的参数解释如下所示:
◆ key:表示所有发往服务器的报文包含有秘钥加密的认证信息,n是32位的整数,表示秘钥号。
◆ version:表示发往上层服务器的报文使用的版本号,n默认是3,可以是1或者2。
◆ prefer:如果有多个server选项,具有该参数的服务器优先使用。
◆ mode:指定数据报文mode字段的值。
◆ minpoll:指定与查询该服务器的最小时间间隔为2的n次方秒,n默认为6,范围为4-14。
◆ maxpoll: 指定与查询该服务器的最大时间间隔为2的n次方秒,n默认为10,范围为4-14。
◆ iburst:当初始同步请求时,采用突发方式接连发送8个报文,时间间隔为2秒。
===同步硬件时钟===
ntp服务,默认只会同步系统时间。
如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件,
在/etc/sysconfig/ntpd文件中,添加【SYNC_HWCLOCK=yes】这样,就可以让硬件时间与系统时间一起同步。
允许BIOS与系统时间同步,也可以通过hwclock-w命令。
hwclock命令用来查询和设置硬件时钟。
hwclock-r读取并打印硬件时钟
hwclock-s将硬件时钟同步到系统时钟
hwclock-w 将系统时钟同步到硬件时钟
系统时钟与硬件时钟
在Linux中有硬件时钟与系统时钟等两种时钟。硬件时钟是指主机板上的时钟设备,也就是通常可在BIOS画面设定的时钟。系统时钟则是指kernel中的时钟。当Linux启动时,系统时钟会去读取硬件时钟的设定,之后系统时钟即独立运作。所有Linux相关指令与函数都是读取系统时钟的设定。
参考文档:
Linux服务器NTP客户端配置——https://www.cnblogs.com/paul8339/p/10059364.html
NTP服务、客户端配置详解——https://blog.51cto.com/u_11392081/1784080
linux中ntp时钟服务器怎么配
执行ntpdate xxx.xxx.xxx.xxx(ntp服务器地址)。
Linux下配置NTP服务器
配置方法:
1、ntp服务安装
NTP服务在RHEL5.x中式默认安装的软件包,可用rpm-qa|grep
ntp检查是否安装,如果未安装可使用如下命令安装与删除NTP服务器软件包
#使用rpm方式安装
rpm-ivh ntp-4.2.2p1-8.el5.i386.rmp
#使用yum方式安装
yum-y install ntp.i*
#使用rpm方式删除
rpm-e ntp-4.2.2pl-8.el5.i386.rpm
#使用yum方式删除
yum-y remove ntp.i*
2、ntp服务配置
在ntp服务安装完成后,需要修改ntp服务配置文件。ntp服务主配置文件/etc/ntp.conf
2.1 ntp服务的启动、暂停
NTP属于system
V服务,其启动、暂停相关命令如下:
#启动
service ntpd
start
#停止
Service ntpd
stop
#重新加载
service ntpd
reload
#查看当前启动状态
service ntpd
status
2.2 ntp服务自动加载
设置ntp服务下一次开机运行状态可通过命令配置
#在运行级别2、3、4、5上设置为自动运行
chkconfig
ntpd on
#在运行级别2、3、4、5上设置为不自动运行
chkconfig
ntpd off
#在运行级别3、5上设置为自动运行
chkconfig
ntpd--level 35 on
#在运行级别3、5上设置为不自动运行
chkconfig
ntpd--level 35 off
2.3配置信息
配置ntp,将Internet上的时间服务器作为内部标准时间来源,过程如下
1)修改/etc/ntp.conf文件
restrict default kod nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict-6::1
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
#指定Internet上的时间服务器
restrict 207.46.232.182 mask 255.255.255.255 nomodify notrap noquery
server 207.46.232.182
server 127.127.1.0
fudge 127.127.1.0 stratum 10
keys/etc/ntp/keys
#指定NTP服务器日志文件
logfile/var/log/ntp
2)修改/etc/ntp/stpe-tickers文件,内容如下(当ntpd服务启动时,会自动与该文件中记录的上层NTP服务进行时间校对)
207.46.232.182
127.127.1.0
3)修改/etc/sysconfig/ntpd文件,内容如下:
#允许BIOS与系统时间同步,也可以通过hwclock-w命令
SYNC_HWCLOCK=yes
4)在配置完成并重新启动服务后,可通过ntpstat
命令显示本机上一次与上层ntp服务器同步时间的情况,也可以使用ntpq-p查看本机与上层ntp服务器通信情况,
2.4图形界面配置NTP
图形界面下直接用system-config-date,在“Network Time Protocol”选项页指定NTP服务器后勾选“Synchronize system clock before startingservice”,将ntpd服务设置为自动运行即可。
2.5客户端访问
1)Linux客户端可通过图形界面进行配置,也可以通过ntpdate命令立即与NTP服务器及行时间校对。
ntpdate 192.168.0.10
2)Windows客户端,只需双击任务栏右下角的时钟,选择“Internet时间”选项页,输入NTP服务IP地址或FQDN,并勾选“自动与Internet时间服务器同步”即可。
Windows默认7天自动更新一次,可通过修改注册表HKEY_LOCAL_MACHINE\SYSTEM
\CurrentControlSet\services\W32Time\TimeProviders\NtpClient\SpecialPollInterval默认单位为妙,修改后重新启动即可生效。
OK,关于linux配置ntp服务器和linux中ntp时钟服务器怎么配的内容到此结束了,希望对大家有所帮助。