-
2021-05-09 02:18:37
方法1:
与一个已知的时间服务器同步
ntpdate time.nist.gov
其中 time.nist.gov 是一个时间服务器.
删除本地时间并设置时区为上海
rm -rf /etc/localtime
ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
方法2:
linux自动同步时间
vi /etc/crontab
加上一句:00 0 1 * * root rdate -s time.nist.gov
配置时间服务器配置(192.168.10.1)
1)、# rpm -ivh ntp-4.1.2-4.EL3.1.i386.rpm
2)、# vi /etc/ntp.conf
注释一行:
restrict default ignore
加入一行:restrict 192.168.10.0 mask 255.255.255.0 notrust nomodify notrap
3)、# vi /etc/ntp/step-tickers
加入一行:
pool.ntp.org
这样每次ntpd启动时,会自动连接该国际标准时间服务器;
4)、# service ntpd start
5)、# netstat -an |grep 123
确保该端口以udp方式开放
时间客户端配置(192.168.10.2)
1)、# ntpdate 192.168.10.2
应该显示同步成功
2)、# crond -e
加入 0-59/10 * * * * /usr/sbin/ntpdate 192.168.10.1
每隔10分钟同步一次时间
更多相关内容 -
Linux时间同步的2种方法
2021-01-09 14:37:19如果你的linux系统根本没有ntpdate这个命令 yum install ntp 安装完了之后,你不要做什么配置,也不需要,直接测试一下 [root@localhost ~]# ntpdate time.nist.gov 22 Oct 21:11:43 ntpdate[5014]: ... -
linux时间同步方法
2015-09-02 13:55:19一. 使用ntpdate 命令 二. 使用rdate同步时间 三.使用 Network Time Protocol (NTP) 服务器 -
linux时间同步ntp服务的安装与配置
2021-01-20 15:27:511、安装ntp服务,要使用时间同步、那么服务端与客户端都需要使用如下命令安装NTP软件包 [root@5201351 ~]# yum install ntp -y 2、如果只是作为客户端的话,配置则可以非常简单,编辑/etc/ntp.conf文件,注释掉默认... -
Linux时间同步_ntpd_ntpdate-简单设置.docx
2020-04-21 15:42:12linux时间同步,ntpd、ntpdate, 一.Linux系统时间的设置/ 二.Linux硬件时间的设置 三.系统时间和硬件时间的同步 四.不同机器之间的时间同步 五.ntpd服务的设置 六.ntp服务的启动与观察 -
linux时间同步ntp安装包.zip
2021-05-27 15:32:28多主机协作工作时,各个主机的时间同步很重要,时间不一致会造成很多重要应用的故障,如:加密协议,日志,集群等, 利用NTP(Network Time Protocol) 协议使网络中的各个计算机时间达到同步。 -
linux时间同步ntp.conf配置文件
2021-05-27 15:35:09linux环境下的ntp时间同步,服务器端需要修改配置文件ntp.conf,附件给出了详细的配置信息。 -
linux 时间同步服务 chrony
2022-01-21 10:55:59时间同步 需求: 同步 阿里云时间服务器 ntp.aliyun.com centos 安装 yun install chrony -y ubuntu 安装 apt install chrony -y ubuntu 下 查看安装软件后,该软件配置文件目录 用 whereis chrony 配置文件 主...同步阿里时间服务器和建立私有时间服务器同步
时间同步(同步阿里云时间服务器)
需求:
同步 阿里云时间服务器 ntp.aliyun.comcentos 安装
yun install chrony -y
ubuntu 安装
apt install chrony -y
ubuntu 下 查看安装软件后,该软件配置文件目录 用
whereis chrony
配置文件
主配置文件:/etc/chrony.conf
客户端程序:/usr/bin/chronyc
服务端程序:/usr/sbin/chronyd监听的端口
123/udp:兼容ntp服务监听在udp的123端口上
323/udp:chrony服务本身监听在udp的323端口上如果系统上已经有其他时间服务,那么先停止
systemctl stop ntpdate systemctl disable ntpdate
防火墙设置
如果存在防火墙
Firewalld设置
firewall-cmd --add-service=ntp --permanent firewall-cmd --reload
因NTP使用123/UDP端口协议,所以允许NTP服务即可。
iptables 防火墙设置
iptables -I INPUT -p udp --dport 123 -j ACCEPT iptables -I INPUT -p udp --dport 223 -j ACCEPT service iptables save
具体操作步骤
启动并加入开机自启动
#设置开机启动,并同时启动 systemctl enable chronyd.service --now #重启 systemctl restart chronyd.service #状态 systemctl status chronyd.service
查看当前系统时区:
timedatectl
输出
Local time: 五 2022-01-21 10:59:48 CST Universal time: 五 2022-01-21 02:59:48 UTC RTC time: 六 2022-01-22 03:00:11 Time zone: Asia/Shanghai (CST, +0800) NTP enabled: no NTP synchronized: no RTC in local TZ: no DST active: n/a
查看上海时区
timedatectl list-timezones | grep -E "Asia/Shanghai" 设置时区 timedatectl set-timezone Asia/Shanghai
配置阿里云时间服务器 ntp.aliyun.com
vim /etc/chrony.conf
内容,在 server 下添加
... server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst server 3.centos.pool.ntp.org iburst server ntp.aliyun.com iburst ...
重启服务
systemctl restart chronyd
设置启用NTP时间 自动同步
timedatectl set-ntp yes
手动同步系统时间
chronyc -a makestep
查看同步源
chronyc sources -v
同步源状态
chronyc sourcestats -v
设置硬件时间,硬件时间默认为UTC
如果你需要的可以设置
timedatectl set-local-rtc 1
校准时间服务器
chronyc tracking
私有时间服务器设置
需求:
1.192.168.50.138 这台服务器为时间服务器
2.其他服务器同步 192.168.50.138 这台时间服务器时间服务器配置
vim /etc/chrony.conf
内容
... # 允许指定网络的主机同步时间,不指定就是允许所有,默认不开启。 allow 192.168.50.0/24 ... #当外部时间服务器不可用时,采用本地时间作为同步标准 local stratum 10
重启服务
systemctl restart chronyd
客户端同步
vim /etc/chrony.conf
如果只有一台服务作为时间标准,把默认 4个全部用#号注释
内容... #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst server 192.168.50.138 iburst ...
重启服务
systemctl restart chronyd
查看现有的时间服务器
chronyc sources
查看时间服务器状态
chronyc sourcestats
ntpdate 客户端同步时间
chrony兼容ntpdate,可以直接使用命令同步
ntpdate 192.168.50.138
立即手动同步
chronyc -a makestep
自用批处理命令
我的服务器使用的是 iptables 防火墙,默认是 ntpdate
sed -i 's/server/#server/g' /etc/chrony.conf \ && systemctl stop ntpdate \ && systemctl disable ntpdate \ && iptables -I INPUT -p udp --dport 123 -j ACCEPT \ && iptables -I INPUT -p udp --dport 223 -j ACCEPT \ && systemctl enable chronyd.service --now \ && systemctl status chronyd.service \ && date
最后执行
service iptables save
-
linux时间同步
2019-10-17 11:52:00dpkg-reconfigure tzdata 选择 Asia 选择 Shanghai或Chongqing date -s 按照提示进行选择时区, 然后防止系统重启后时区改变 ...网上同步时间 安装ntpdate工具 apt-get install ntpdate 设置系统时间与...前言
你的Linux服务器每运行一段时间,服务器时间就不准了,不是快就是慢。你经常需要登录服务器手动通过命令来设置服务器时间,这种操作即繁琐又低效。
一台还好,手动同步一下也不费什么时间,如果是好几台呢,那你就得掂量掂量手动同步的工作量了。
服务器时间同步在集群环境,数据库主从备份等场景非常有用,如果服务器时间不一致可能会导致各种各样的问题。那么如何同步时间,保持服务器时间一致在实际生产环境中就显得非常重要。
一、本文解决问题
1、修正时区,将EDT修改为CST。
2、Linux服务器如何进行时钟同步。
3、如何搭建自己的时钟服务器(NTP Server),其它服务器和该时钟服务器同步。
二、修正时区
通常,我们使用date命令可以查看当前服务器时间以及设置当前服务器时间。例如,终端中我们输入date命令,默认会输出如下内容:
[root@localhost ~]# date Thu May 28 03:45:30 EDT 2020
有时候系统默认显示时区不对,显示为EDT时区,正好和北京时间相差12个小时,这时候我们就需要修改一下系统的时区,将其修改为CST时区。
修改方法如下:
mv /etc/localtime /etc/localtime.bak #备份原文件 ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改为 date
输出结果如下:
Thu May 28 15:46:59 CST 2020
这时候时间就显示为正常的北京时间了。
三、同步Linux服务器时间
在Linux系统中同步时间时,你需要了解ntpdate这个命令,默认该命令在主流的Linux发行版中都有安装,默认安装路径/usr/sbin/ntpdate。
以下操作皆在root帐号下进行,如果使用非root帐号,则需要该帐号为sudo用户能进行root权限的操作。
1、安装ntpddate
如果你的Linux系统中没有安装,你可以通过如下命令进行安装:
#centos,redhat系列 yum install ntpdate #debian,ubuntu系列 apt install ntpdate #archlinux系列 pacman -S ntpdate
2、通过ntpdate命令从时钟服务器同步
我们这里选用中国ntp服务器cn.pool.ntp.org来作为时钟同步的来源。为能正常访问到cn.pool.ntp.org,你的Linux系统应该能访问外网才行。
执行命令如下:
ntpdate cn.pool.ntp.org
3、配置crontab自动执行同步
如果每次手动执行,显然是很麻烦的。这里,我们使用crontab定时任务来定期执行ntpdate同步命令,例如我们每10分钟或一小时执行一次,可以通过以下方式实现。首先在命令终端中输入crontab -e命令,然后输入如下命令保存即可。
crontab -e
开始编辑文件内容,输入定时执行命令:
#每10分钟执行一次
*/10 * * * * /usr/sbin/ntpdate cn.pool.ntp.org
或者
#每一个小时执行一次 0 * * * * /usr/sbin/ntpdate cn.pool.ntp.org
四、如何搭建时钟服务器(NTP Server)
1、安装NTP服务
一条命令即可安装,这里以centos7下安装为例。
yum install -y ntp ntpdate
2、配置NTP服务
ntp配置文件的路径是/etc/ntp.conf,修改改配置文件时先进行备份。
cp /etc/ntp.conf /etc/ntp.conf.bak #备份 vim /etc/ntp.conf #vim编辑文件
配置文件中,增加如下内容:
# Hosts on local network are less restricted. restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
这个是用来允许192.168.1.*这个网段的服务器都可以使用该ntp服务器同步时间。这里可以根据你实际情况来设定网段。
同时添加指定一台内网服务器作为本地时钟服务器用于无法链接外网时,其它服务器同步时间是以该服务器为准。
server 192.168.1.2
整体配置后的文件,主要内容如下:
# 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 -6 ::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). #定义上游使用的ntp服务器 server cn.pool.ntp.org prefer #server 0.centos.pool.ntp.org iburst #server 1.centos.pool.ntp.org iburst #server 2.centos.pool.ntp.org iburst #server 3.centos.pool.ntp.org iburst #外部时间服务不可用时,以本地时间作为服务 server 192.168.1.2 fudge 192.168.1.2 stratum 10 #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 ...
3、启动NTP服务
配置文件配置好保存后,我们可以通过以下命令来启动ntp服务。
systemctl start ntpd
服务启动后可以通过ntpstat命令来验证服务是否正常。
[root@localhost ~]# ntpstat synchronised to NTP server (162.159.200.123) at stratum 4 time correct to within 227 ms polling server every 1024 s
4、客户端同步时间
客户端同步时间的方式可以以第三部分中讲到的方式进行同步,即通过ntpdate命令同步。ntpdate 192.168.1.2
可以将该命令作为crontab任务进行定时运行即可完成客户端机器的时间同步。
Ubuntu时间同步
dpkg-reconfigure tzdata
选择 Asia
选择 Shanghai或Chongqing
date -s
按照提示进行选择时区,
然后防止系统重启后时区改变
sudo cp /usr/share/zoneinfo/Asia/ShangHai /etc/localtime
网上同步时间
- 安装ntpdate工具
apt-get install ntpdate
- 设置系统时间与网络时间同步
#cn.pool.ntp.org是位于中国的公共NTP服务器
ntpdate cn.pool.ntp.org
- 将系统时间写入硬件时间
hwclock –systohc
参考链接 :
还在为Linux服务器时间不同步发愁吗,看完你就知道怎么做了 https://mp.weixin.qq.com/s/dx1CrkZxovkuAPNMBWATAg
ubuntu设置系统时间与网络时间同步 :https://blog.csdn.net/qq_38157006/article/details/89952415
-
linux时间同步,ntpd、ntpdate
2020-12-24 10:34:15linux时间同步,ntpd、ntpdate2010-10-13 09:01:02阅读1043 评论0字号:大中小订阅在Windwos中,系统时间的设置很简单,界面操作,通俗易懂。而且设置后,重启,关机都没关系。系统时间会自动保存在Bios的时钟里面,...linux时间同步,ntpd、ntpdate
2010-10-13 09:01:02
阅读1043 评论0字号:大中小订阅
在Windwos中,系统时间的设置很简单,界面操作,通俗易懂。而且设置后,重启,关机都没关系。系统时间会自动保存在Bios的时钟里面,启动计算机的时候,系统会自动在Bios里面取硬件时间,以保证时间的不间断。
但在Linux下,默认情况下,系统时间和硬件时间,并不会自动同步。在Linux运行过程中,系统时间和硬件时间以异步的方式运行,互不干扰。硬件时间的运行,是靠Bios电池来维持,而系统时间,是用CPU tick来维持的。
在系统开机的时候,会自动从Bios中取得硬件时间,设置为系统时间。
一.Linux系统时间的设置
在Linux中设置系统时间,可以用date命令:
//查看时间
[root@localhost ~]# date
2008年 12月 12日星期五 14:44:12 CST
//修改时间[root@localhost ~]# date -set "2013-12-24 00:01"
<== (年/月/日 时:分【:秒】)2009年 01月 01日星期四 00:01:00 CST
//date 有几种时间格式可接受,这样也可以设置时间:
[root@localhost ~]# date
012501012009.30 <== 月日时分年.秒2009年 01月 25日星期日 01:01:30 CST
二.Linux硬件时间的设置
硬件时间的设置,可以用hwclock或者clock命令。其中,clock和hwclock用法相近,只用一个就行,只不过clock命令除了支持x86硬件体系外,还支持Alpha硬件体系。
//查看硬件时间可以是用hwclock,hwclock --show 或者hwclock -r
[root@localhost ~]# hwclock
--show
2008年12月12日星期五 06时52分07秒-0.376932
seconds
//设置硬件时间
[root@localhost ~]# hwclock --set
--date="1/25/09 00:00" <== 月/日/年时:分:秒[root@localhost ~]# hwclock
2009年01月25日星期日 00时00分06秒-0.870868
seconds
[root@localhost ~]#
hwclock -w 根据系统时间设置硬件时间
三.系统时间和硬件时间的同步
同步系统时间和硬件时间,可以使用hwclock命令。
//以系统时间为基准,修改硬件时间
[root@localhost ~]# hwclock
--systohc<== sys(系统时间)to(写到)hc(Hard Clock)[root@localhost ~]# hwclock -w
//以硬件时间为基准,修改系统时间
[root@localhost ~]# hwclock
--hctosys
[root@localhost ~]# hwclock -s
四.不同机器之间的时间同步
为了避免主机时间因为长期运作下所导致的时间偏差,进行时间同步(synchronize)的工作是非常必要的。Linux系统下,一般使用ntp服务器来同步不同机器的时间。一台机器,可以同时是ntp服务器和ntp客户机。在网络中,推荐使用像DNS服务器一样分层的时间服务器来同步时间。
同步时间,可以使用ntpdate命令,也可以使用ntpd服务。
使用ntpdate比较简单。格式如下:
[root@linux ~]# ntpdate [-nv] [NTP
IP/hostname]
[root@linux ~]# ntpdate 192.168.0.2
[root@linux ~]# ntpdate time.ntp.org
但这样的同步,只是强制性的将系统时间设置为ntp服务器时间。如果cpu tick有问题,只是治标不治本。所以,一般配合cron命令,来进行定期同步设置。比如,在crontab中添加:
0 12 * * * * /usr/sbin/ntpdate
192.168.0.1
这样,会在每天的12点整,同步一次时间。ntp服务器为192.168.0.1。
使用ntpd服务,要好于ntpdate加cron的组合。因为,ntpdate同步时间,会造成时间的跳跃,对一些依赖时间的程序和服务会造成影响。比如sleep,timer等。而且,ntpd服务可以在修正时间的同时,修正cpu tick。理想的做法为,在开机的时候,使用ntpdate强制同步时间,在其他时候使用ntpd服务来同步时间。
要注意的是,ntpd有一个自我保护设置: 如果本机与上源时间相差太大, ntpd不运行. 所以新设置的时间服务器一定要先ntpdate从上源取得时间初值, 然后启动ntpd服务。ntpd服务运行后, 先是每64秒与上源服务器同步一次, 根据每次同步时测得的误差值经复杂计算逐步调整自己的时间, 随着误差减小, 逐步增加同步的间隔. 每次跳动, 都会重复这个调整的过程.
五.ntpd服务的设置
ntpd服务的相关设置文件如下:
1./etc/ntp.conf:这个是NTP daemon的主要设文件,也是 NTP 唯一的设定文件。
2./usr
/share/zoneinfo/:在这个目录下的文件其实是规定了各主要时区的时间设定文件,例如北京地区的时区设定文件在 /usr/share/zoneinfo/Asia/Beijing 就是了。这个目录里面的文件与底下要谈的两个文件(clock 与localtime)是有关系的。
3./etc/sysconfig/clock:这个文件其实也不包含在NTP 的 daemon 当中,因为这个是linux的主要时区设定文件。每次开机后,Linux 会自动的读取这个文件来设定自己系统所默认要显示的时间。
4./etc /localtime:这个文件就是“本地端的时间配置文件”。刚刚那个clock 文件里面规定了使用的时间设置文件(ZONE) 为 /usr/share/zoneinfo/Asia/Beijing ,所以说,这就是本地端的时间了,此时, Linux系统就会将Beijing那个文件另存为一份 /etc/localtime文件,所以未来我们的时间显示就会以Beijing那个时间设定文件为准。
5. /etc/timezone:系统时区文件
下面重点说说 /etc/ntp.conf文件的设置。在 NTP Server 的设定上面,其实最好不要对 Internet 无限制的开放,尽量仅提供您自己内部的 Client 端联机进行网络校时就好。此外, NTP Server 总也是需要网络上面较为准确的主机来自行更新自己的时间啊,所以在我们的
NTP Server 上面也要找一部最靠近自己的 Time Server 来进行自我校正。事实上, NTP 这个服务也是 Server/Client 的一种模式。
[root@linux ~]# vi
/etc/ntp.conf
# 1. 关于权限设定部分#权限的设定主要以 restrict 这个参数来设定,主要的语法为:# restrict IP mask netmask_IP
parameter
# 其中 IP 可以是软件地址,也可以是 default ,default 就类似 0.0.0.0
#至于paramter则有:#ignore:关闭所有的 NTP 联机服务#nomodify:表示 Client 端不能更改 Server 端的时间参数,不过,
#Client 端仍然可以透过 Server 端来进行网络校时。#notrust:该 Client 除非通过认证,否则该 Client 来源将被视为不信任网域#noquery:不提供 Client 端的时间查询
#notrap:不提供trap这个远程事件登入
#如果paramter完全没有设定,那就表示该 IP (或网域)“没有任何限制”
restrict default
nomodifynotrapnoquery# 关闭所有的 NTP 要求封包restrict 127.0.0.1 #这是允许本级查询restrict 192.168.0.1 mask 255.255.255.0 nomodify
#在192.168.0.1/24网段内的服务器就可以通过这台NTP Server进行时间同步了# 2. 上层主机的设定#要设定上层主机主要以 server 这个参数来设定,语法为:#server [IP|HOST Name] [prefer]
#Server 后面接的就是我们上层 Time Server 啰!而如果 Server 参数#后面加上perfer的话,那表示我们的 NTP 主机主要以该部主机来作为#时间校正的对应。另外,为了解决更新时间封包的传送延迟动作,#所以可以使用driftfile来规定我们的主机#在与 Time Server 沟通时所花费的时间,可以记录在driftfile #后面接的文件内,例如下面的范例中,我们的 NTP server 与#cn.pool.ntp.org联机时所花费的时间会记录在 /etc/ntp/drift文件内server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server cn.pool.ntp.org
prefer
#其他设置值,以系统默认值即可
server 127.127.1.0 # local clock
fudge 127.127.1.0
stratum 10
driftfile /var/lib/ntp/drift
broadcastdelay 0.008
keys /etc/ntp/keys
总结一下,restrict用来设置访问权限,server用来设置上层时间服务器,driftfile用来设置保存漂移时间的文件。
六.ntp服务的启动与观察
在启动NTP服务前,先对提供服务的这台主机手动的校正一次时间咯。(因为启动服务器,端口会被服务端占用,就不能手动同步时间了)
[root@linux ~] # ntpdate
cn.pool.ntp.org
25 Apr 14:33:51 ntpdate[8310]: step
time server 80.85.129.2 offset 6.655976 sec
然后,启动ntpd服务:
[root@linux ~] # servicentpd
start
或 [root@linux ~] # /etc/init.d/ntpd
start
查看端口:
[root@linux ~] # netstat -ln|grep
123
udp 0 0
192.168.228.153:123 0.0.0.0:*
udp 0 0
127.0.0.1:123 0.0.0.0:*
udp 0 0
0.0.0.0:123 0.0.0.0:*
udp 0 0
:::123 :::*
如何确认我们的NTP服务器已经更新了自己的时间呢?
[root@linux ~] # ntpstat
synchronized to NTP
server(127.127.1.0) at stratum 11
time correct to within
950ms
polling server every 64 s
#改指令可列出NTP服务器是否与上层联机。由上述输出结果可知,时间校正约
#为950*10(-6)秒。且每隔64秒会主动更新时间。
常见的错误:
25 Apr 15:30:17 ntpdate[11520]: no
server suitable for synchronization found
其实,这不是一个错误。而是由于每次重启NTP服务器之后大约要3-5分钟客户端才能与server建立正常的通讯连接。当此时用客户端连接服务端就会报这样的信息。一般等待几分钟就可以了。
[root@linux ~] # ntptrace –n
127.0.0.1
127.0.0.1:stratum 11, offset
0.000000,synch distance 0.950951
222.73.214.125:stratum 2,offset –0.000787,synch distance 0.108575
209.81.9.7:stratum
1,offset 0.000028,synch distance
0.00436,refid ‘GPS’
#这个指令可以列出目前NTP服务器(第一层)与上层NTP服务器(第二层)彼此之间的
#关系
[root@linux ~] # ntpq –p
指令“ntpq -p”可以列出目前我们的NTP与相关的上层NTP的状态,以上的几个字段的意义如下:
remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。
refid:参考的上一层NTP主机的地址
st:即stratum阶层
when:几秒前曾做过时间同步更新的操作
poll:下次更新在几秒之后
reach:已经向上层NTP服务器要求更新的次数
delay:网络传输过程钟延迟的时间
offset:时间补偿的结果
jitter:Linux系统时间与BIOS硬件时间的差异时间
最后提及一点,ntp服务,默认只会同步系统时间。如果想要让ntp同时同步硬件时间,可以设置/etc/sysconfig/ntpd文件。
在/etc/sysconfig/ntpd文件中,添加 SYNC_HWCLOCK=yes 这样,就可以让硬件时间与系统时间一起同步。
---------------------------------------------------------------------------------------------------------------------------------------------------------------------
linux配置时间服务器(ntp)
2007-10-27 16:34
在linux下,我们可以通过自带的NTP(Network Time
Protocol)协议通过网络使自己的系统保持精确的时间。可用的公共时间服务器列表可以从下面的地址获取:http://ntp.isc.org/bin/view/Servers/NTPPoolServersNTP是用来使系统和一个精确的时间源保持时间同步的协议。建议大家在自己管理的网络中建立至少一台时间服务器来同步本地时间,这样可以使得在不同的系统上处理和收集日志和管理更加容易。介绍一下环境:179为本地时间服务器,其他服务器和179同步。179和网上时间服务器同步。一、配置179时间服务器1、首先查询NTP软件版本rpm -qa|grepntpntp-4.1.2-4.EL3.1如果没有可以从linux安装盘上查找,安装此ntp包2、编辑配置文件vi /etc/ntp.conf首先定义服务器server pool.ntp.orgrestrict default
nomodifynotrapnoqueryrestrict 192.168.0.0 mask
255.255.255.0 notrustnomodifynotrap #从192.168.0.1-192.168.0.254的服务器都可以使用我们的NTP服务器来同步时间。注释掉以下一行#restrict default ignore3、启动NTP服务器#chkconfigntpd on#/etc/init.d/ntpd start#/etc/init.d/ntpd stop#/etc/init.d/ntpd restart默认情况下,我们配置的NTP服务器不会去时间源那里同步时间,所以必须修改/etc/ntp/step-tickers文件,加入我们的时间源,这样每次通过/etc/init.d/ntpd来启动服务的时候就会自动更新时间了检查服务器同步状态:ntpq -pntptrace 192.168.0.179如果输出正确,则说明时间服务器成功。每次启动服务器,会自动同步时间。配置LINUX客户端在linux客户端上执行ntpdatentp_server_ip就可以根据时间服务器统一局域网的时间了,将上面的命令放到cron里每天早上3点定期执行,crontab –e 然后输入0 3 * * * /usr/sbin/ntpdate
192.168.0.179
为什么电脑要对时?因为电脑自己的钟不准。破电脑一天慢五分钟也不奇怪。
对时需要对到什么精度?一般家用的电脑时钟误差一分钟完全可以接受。集群服务器配合工作一般需要所有的时钟同步在一秒之内。
和谁同步?一般是和世界各地的 NTP (Network Time
Protocol)服务器同步的。米国标准时间由 NIST 发布,NIST 提供了一些。现代 Windows 操作系统自动和 time.windows.com 对时。Linux 下面一般用来自动选择服务器。中国国家授时中心 NTP 210.72.145.44 是中国权威时间。中国教育网有自己的。如果是集群服务器,一般会在内网配置几个本地 NTP 服务器。
上面这么多 NTP 服务器有没有优劣呢?有的,但是对于一般的应用来说,看不出什么区别。理论上说,NTP 服务器是分等级(Stratum)的,Stratum = 1 的 NTP 服务器是直接和世界标准时钟同步的,包括 GPS 时间、铯原子钟、某些手机网络等。NIST、中国国家授时中心和中国教育网的第一级时间服务器都是这个级别的。Stratum = 2 的 NTP 服务器是和 Stratum = 1 的服务器同步的,性能稍差,但精确度也在毫秒的量级,所以用起来没什么区别。再往下每同步一级,Stratum 就加一。
Windows 2000 开始包含了自动时间同步的服务。Windows XP 上,打开时间设置就有网络对时的设置。默认是每星期和
time.windows.com 对时一次。这个一星期同步一次太长了,可以通过注册表调整,或者用修改。
Linux 下面的ntpd就要灵活多啦。默认配置一般足够好用。下面在 Fedora 下举个例子。配置:
# grep "^server" /etc/ntp.conf
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org
server 127.127.1.0 # local
clock
启动ntpd之后查看状态
# ntpq -pn
remote refid st t when poll
reach delay offset jitter
==============================================================================
64.25.87.54 128.118.25.5 2 u 10 64 17 79.194 -542.89 1.942
64.72.116.51 129.7.1.66 2
u 9 64 17 51.569 -532.23 1.803
64.72.116.50 129.7.1.66 2 u 11 64 17 51.417 -516.70 1.417
64.72.116.45 129.7.1.66 2
u 7 64 17 51.586 -532.36 1.135
*127.127.1.0 LOCAL(0) 10
l 3 64 17 0.000 0.000 0.001
st这列显示自动选的四个 NTP 服务器都是 Stratum = 2。最后一个是本地时钟。前四行的 offset 显示本地时钟和四个 NTP 服务器都有大概 500 毫秒的差距。ntpstat显示目前只和本地时钟同步:
# ntpstat
synchronised to local net at stratum 11
time correct
to within 949 ms
polling
server every 64 s
过一会再看:
# ntpq -pn
remote refid st t when poll
reach delay offset jitter
==============================================================================
+64.25.87.54 128.118.25.5 2 u 56 64 377 78.548 250.871 37.180
+64.72.116.51 129.7.1.66 2 u 58 64 377 51.551 268.538 36.817
*64.72.116.50 129.7.1.66 2 u 58 64 377 51.539 274.497 36.629
+64.72.116.45 129.7.1.66 2 u 49 64 377 51.485 271.750 37.841
127.127.1.0 LOCAL(0) 10 l 44 64 377 0.000 0.000 0.001
# ntpstat
synchronised to NTP server (64.72.116.50) at stratum 3
time correct
to within 263 ms
polling
server every 64 s
本地时钟已经成功和外面的 NTP 服务器同步。ntpq报告中第一列 * 表示目前选择的主同步服务器,标 + 的表示有可能被用来进一步提高同步精度的次要服务器。因为是和
Stratum = 2 的服务器同步,所以本地的ntpd Stratum 就是 3 了。一个细节是ntpq对时钟是慢慢调整的,而不是直接跳好多秒,这样平滑的调整时间可以保证很多程序的流程平稳。不过,如果时钟误差过大,ntpd可能会拒绝调整时间;或者有人也可能希望立刻调正时间,这样的话可以直接执行命令:ntpdate -b
pool.ntp.org(需要停掉ntpd服务执行)。
在我另一个服务器上,配置了好多 NTP 服务器:
# grep "^server" /etc/ntp.conf
server time-a.nist.gov
server time-b.nist.gov
server time.nist.gov
server time.windows.com
server 0.pool.ntp.org
server 1.pool.ntp.org
server 2.pool.ntp.org
server pool.ntp.org
server 127.127.1.0 # local
clock
# ntpq -p
remote refid st t when poll
reach delay offset jitter
==============================================================================
+time-a.nist.gov
.ACTS. 1 u 61 128 377 76.113 -1.046 3.424
*time-b.nist.gov
.ACTS. 1 u 65 128 377 81.063 0.398 1.892
-time.nist.gov .ACTS. 1 u 251 128 356 38.911 1.353 30.226
-time.windows.co
18.26.4.105 2 u 45 128 267 31.218 13.180 6.039
-194.109.64.200 192.87.106.2 2 u 122 128 377 155.132 0.596 38.674
-a.mirror.fizzel
43.75.42.44 3 u 56 128 377 163.391 -11.756 13.006
-enfield.ikk.szt
195.111.99.186 2 u 118 128 377 188.326 -2.520 32.359
+ntp1.esat.net .GPS. 1 u 59 128 377 161.103 -1.321 0.460
LOCAL(0) .LOCL. 10 l 48
-
Linux时间同步.pdf
2020-08-25 22:13:30实现多个linux时间同步,linux时间调整. 笔记不易,希望支持,里面有具体命令和实现效果 小小笔记,攒点分分. -
Linux 时间同步服务命令
2021-05-10 03:51:58Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步。date命令:date ... -
手把手教你搭建Linux时间同步服务器
2021-10-11 18:12:30NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议。它的用途是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在互联网上绝大多数的地方其精度可以达到1-... -
Linux date 时间设置同步命令分享
2020-09-15 04:48:47Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但在做数据库集群分片等复杂操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步。 -
linux时间同步ntp服务.docx
2020-08-15 06:17:00Linux时间同步 Ntp: Network Time Protocol Port123 Protocol: UDP Fun: 同步网络时钟 安装包ntp-version.rpm 1 自动同步网络时间 使用linux自带命令 # ntpdate 如果有明确的IP地址架设内部ntp服务器可以直接写ip... -
基于linux时间同步rpm安装ntp.zip
2019-10-24 19:26:18linux时间同步工具,通过配置第三方ntp服务器进行时间同步操作, -
嵌入式Linux 时间同步 gpsd+chrony
2021-07-30 15:38:15嵌入式Linux时间同步gpsd+chrony 一、基本原理 NMEA中获取UTC时间的yymmddhhmmss,然后使用pps的秒脉冲对串口或者网路传输的延时进行校正。但是其中Linux检测pps信号的延时无法校正,实测Linux外部中断与gpio输出... -
linux时间同步.pdf
2021-09-30 17:52:37linux时间同步.pdf -
Linux时间同步(三台机器)
2021-12-14 18:28:20三台机器master,slave1,slave2进行时间同步,需要配置好IP映射。 1.选择时区(三台都执行) tzselect 2.下载ntp(三台机器都执行) yum install -y ntp 3.master作为ntp服务器,修改ntp配置文件 vim /etc... -
Alpine Linux 时间同步
2019-04-02 10:13:38先安装: apk add chrony (1/2) Installing libcap (2.25-r1) (2/2) Installing chrony (3.2-r2) Executing chrony-3.2-r2.pre-install Executing busybox-1.27.2-r11.trigger OK: 831 MiB in 8... -
详解linux ntp服务器时间同步设置
2021-01-10 00:05:37linux ntp服务器时间同步设置 时间同步这个需求在很多地方都有。比如安装cm和cdh的话,需要ntp时间同步,否则会出现红色警告 这里主要是设置一台服务器作为主服务器,让其他机器同步这台机器的时间,而且是配置的... -
Linux时间同步,ntpdate命令、ntpd服务详解
2020-12-24 10:33:40(因为启动服务器,端口会被服务端占用,就不能手动同步时间了)ntpdate cn.pool.ntp.org然后再启动服务,service ntpd start或/etc/init.d/ntpd start查看端口:netstat -ln|grep 123如何确认我们的NTP服务器已经更新... -
Linux时间同步
2018-01-06 21:01:48有几种方式可以做时间同步的: date命令: date :查看当前时间,结果如下: [root@cdh3 ~]# date Sat Jan 6 20:52:09 CST 2018 date -s 20:50:09 :设置当前时间,结果如下: [root@cdh3 ~] -
Linux时间同步(NTP)
2017-09-05 13:55:09设置NTP服务器不难但是NTP本身是一个很复杂的协议. 这里只是简要地介绍一下实践方法,下面的实验都在RHEL5.5 64位上运行 1.时间和时区 ...这里就有产生了一个如何定义时间的问题. 因为在地球环绕太阳旋转的 -
suselinux时间同步client
2014-09-28 09:25:21suselinux时间同步client,这个事client的配置文档 -
linux 时间同步命令
2019-08-09 16:28:41若要和Internet时间同步,使用ntpdate -u time.nist.gov同步网络时间 说明服务器还没有安装ntpdate,我们使用yum install ntpdate -y 进行安装即可 最后再使用 ntpdate - u time.nist.gov同步网络时间 ... -
linux时间同步服务(chronyd服务)
2020-11-06 12:50:02集群中节点之间需要时间同步,不依赖外部的时间服务NTP,在内部搭建时间服务器。首先保证所有节点都安装了chrony,命令如下:yum install chrony -y。 在提供时间同步服务的服务端节点做如下操作: vim /etc/chrony.... -
linux C 实现时间同步
2018-03-07 17:41:33C源文件,用于Linux实现网络时间同步,同时支持在嵌入式arm linux平台上使用,亲测成功!!!