Error[8]: Undefined offset: 8, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

Linux/CentOS系统同步网络时间的2种方法详解

由于硬件的原因,机器或多或少的跟标准时间对不上,一个月的误差几秒到几分钟不等。对于服务器来说时间不准,会有很多麻烦。例如,支付的时候,无法下单,游戏无法登录等。

方法一:用 ntpdate从时间服务器更新时间

如果系统没有 ntpdate 命令,可在线安装:

yum -y install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下

[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:42:19 CST
[root@snsgou-pc src]# ntpdate time.nist.gov 
20 May 22:42:38 ntpdate[26759]: step time server 131.107.13.100 offset 2.117558 sec
[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:43:17 CST

上面的情况表示跟网络时间同步成功。

我们可以用定时任务来定期同步时间

用 crontab -e 命令进入crontab编辑状态,追加如下定时任务文本

*/10 * * * * ntpdate time.nist.gov  #域名或IP

表示 每隔十分钟同步一次。推荐几个时间服务器:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

方法二:用ntp搭建自己的时间服务器

当我们自己搭建时间服务器就不用crontab来定时去跑。

1、安装时间服务器ntp

yum install ntp

2、配置ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if(
[root@localhost ~]# /etc/init.d/ntpd start
!~ /^$/ &&
[root@localhost ~]# netstat -upnl |grep ntpd  //查看时程
 
[root@localhost ~]# ntpq -pn  //查看同步的服务器IP
 remote      refid   st t when poll reach  delay  offset jitter
==============================================================================
 50.77.217.185  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.90.158.4  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.71.100.89  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.134.1.10  .INIT.     16 u  -  64  0  0.000  0.000  0.000
*127.127.1.0   .LOCL.     10 l  18  64 377  0.000  0.000  0.001
 
[root@localhost ~]# ntpstat  //同步的结果
synchronised to local net at stratum 11
 time correct to within 12 ms
 polling server every 512 s
!~ /^#/) {print [+++]}}' restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包 restrict 127.0.0.1 //给于本机所有权限 restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限 server time.nist.gov prefer //设置时间服务器,加prefer表示优先 server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 driftfile /var/lib/ntp/drift keys /etc/ntp/keys

3、启动ntp

[+++]

4、查看并测试

[+++]

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

when:几秒前曾做过时间同步更新的 *** 作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

以上即是本文要讲的Linux系统同步网络时间的2种方法,希望对大家有所帮助。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 9, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

Linux/CentOS系统同步网络时间的2种方法详解

由于硬件的原因,机器或多或少的跟标准时间对不上,一个月的误差几秒到几分钟不等。对于服务器来说时间不准,会有很多麻烦。例如,支付的时候,无法下单,游戏无法登录等。

方法一:用 ntpdate从时间服务器更新时间

如果系统没有 ntpdate 命令,可在线安装:

yum -y install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下

[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:42:19 CST
[root@snsgou-pc src]# ntpdate time.nist.gov 
20 May 22:42:38 ntpdate[26759]: step time server 131.107.13.100 offset 2.117558 sec
[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:43:17 CST

上面的情况表示跟网络时间同步成功。

我们可以用定时任务来定期同步时间

用 crontab -e 命令进入crontab编辑状态,追加如下定时任务文本

*/10 * * * * ntpdate time.nist.gov  #域名或IP

表示 每隔十分钟同步一次。推荐几个时间服务器:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

方法二:用ntp搭建自己的时间服务器

当我们自己搭建时间服务器就不用crontab来定时去跑。

1、安装时间服务器ntp

yum install ntp

2、配置ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if(
[root@localhost ~]# /etc/init.d/ntpd start
!~ /^$/ &&
[root@localhost ~]# netstat -upnl |grep ntpd  //查看时程
 
[root@localhost ~]# ntpq -pn  //查看同步的服务器IP
 remote      refid   st t when poll reach  delay  offset jitter
==============================================================================
 50.77.217.185  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.90.158.4  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.71.100.89  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.134.1.10  .INIT.     16 u  -  64  0  0.000  0.000  0.000
*127.127.1.0   .LOCL.     10 l  18  64 377  0.000  0.000  0.001
 
[root@localhost ~]# ntpstat  //同步的结果
synchronised to local net at stratum 11
 time correct to within 12 ms
 polling server every 512 s
!~ /^#/) {print }}' restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包 restrict 127.0.0.1 //给于本机所有权限 restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限 server time.nist.gov prefer //设置时间服务器,加prefer表示优先 server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 driftfile /var/lib/ntp/drift keys /etc/ntp/keys

3、启动ntp

[+++]

4、查看并测试

[+++]

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

when:几秒前曾做过时间同步更新的 *** 作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

以上即是本文要讲的Linux系统同步网络时间的2种方法,希望对大家有所帮助。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
Error[8]: Undefined offset: 10, File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 121
File: /www/wwwroot/outofmemory.cn/tmp/plugin_ss_superseo_model_superseo.php, Line: 473, decode(

Linux/CentOS系统同步网络时间的2种方法详解

由于硬件的原因,机器或多或少的跟标准时间对不上,一个月的误差几秒到几分钟不等。对于服务器来说时间不准,会有很多麻烦。例如,支付的时候,无法下单,游戏无法登录等。

方法一:用 ntpdate从时间服务器更新时间

如果系统没有 ntpdate 命令,可在线安装:

yum -y install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下

[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:42:19 CST
[root@snsgou-pc src]# ntpdate time.nist.gov 
20 May 22:42:38 ntpdate[26759]: step time server 131.107.13.100 offset 2.117558 sec
[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:43:17 CST

上面的情况表示跟网络时间同步成功。

我们可以用定时任务来定期同步时间

用 crontab -e 命令进入crontab编辑状态,追加如下定时任务文本

*/10 * * * * ntpdate time.nist.gov  #域名或IP

表示 每隔十分钟同步一次。推荐几个时间服务器:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

方法二:用ntp搭建自己的时间服务器

当我们自己搭建时间服务器就不用crontab来定时去跑。

1、安装时间服务器ntp

yum install ntp

2、配置ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if(
[root@localhost ~]# /etc/init.d/ntpd start
!~ /^$/ &&
[root@localhost ~]# netstat -upnl |grep ntpd  //查看时程
 
[root@localhost ~]# ntpq -pn  //查看同步的服务器IP
 remote      refid   st t when poll reach  delay  offset jitter
==============================================================================
 50.77.217.185  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.90.158.4  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.71.100.89  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.134.1.10  .INIT.     16 u  -  64  0  0.000  0.000  0.000
*127.127.1.0   .LOCL.     10 l  18  64 377  0.000  0.000  0.001
 
[root@localhost ~]# ntpstat  //同步的结果
synchronised to local net at stratum 11
 time correct to within 12 ms
 polling server every 512 s
!~ /^#/) {print }}' restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包 restrict 127.0.0.1 //给于本机所有权限 restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限 server time.nist.gov prefer //设置时间服务器,加prefer表示优先 server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 driftfile /var/lib/ntp/drift keys /etc/ntp/keys

3、启动ntp

4、查看并测试

[+++]

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

when:几秒前曾做过时间同步更新的 *** 作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

以上即是本文要讲的Linux系统同步网络时间的2种方法,希望对大家有所帮助。

)
File: /www/wwwroot/outofmemory.cn/tmp/route_read.php, Line: 126, InsideLink()
File: /www/wwwroot/outofmemory.cn/tmp/index.inc.php, Line: 166, include(/www/wwwroot/outofmemory.cn/tmp/route_read.php)
File: /www/wwwroot/outofmemory.cn/index.php, Line: 30, include(/www/wwwroot/outofmemory.cn/tmp/index.inc.php)
LinuxCentOS系统同步网络时间的2种方法详解_软件运维_内存溢出

LinuxCentOS系统同步网络时间的2种方法详解

LinuxCentOS系统同步网络时间的2种方法详解,第1张

Linux/CentOS系统同步网络时间的2种方法详解

由于硬件的原因,机器或多或少的跟标准时间对不上,一个月的误差几秒到几分钟不等。对于服务器来说时间不准,会有很多麻烦。例如,支付的时候,无法下单,游戏无法登录等。

方法一:用 ntpdate从时间服务器更新时间

如果系统没有 ntpdate 命令,可在线安装:

yum -y install ntp

安装完了之后,你不要做什么配置,也不需要,直接测试一下

[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:42:19 CST
[root@snsgou-pc src]# ntpdate time.nist.gov 
20 May 22:42:38 ntpdate[26759]: step time server 131.107.13.100 offset 2.117558 sec
[root@snsgou-pc src]# date
2015年 05月 20日 星期三 22:43:17 CST

上面的情况表示跟网络时间同步成功。

我们可以用定时任务来定期同步时间

用 crontab -e 命令进入crontab编辑状态,追加如下定时任务文本

*/10 * * * * ntpdate time.nist.gov  #域名或IP

表示 每隔十分钟同步一次。推荐几个时间服务器:

time.nist.gov
time.nuri.net
0.asia.pool.ntp.org
1.asia.pool.ntp.org
2.asia.pool.ntp.org
3.asia.pool.ntp.org

方法二:用ntp搭建自己的时间服务器

当我们自己搭建时间服务器就不用crontab来定时去跑。

1、安装时间服务器ntp

yum install ntp

2、配置ntp

[root@localhost ~]# cat /etc/ntp.conf |awk '{if(
[root@localhost ~]# /etc/init.d/ntpd start
!~ /^$/ &&
[root@localhost ~]# netstat -upnl |grep ntpd  //查看时程
 
[root@localhost ~]# ntpq -pn  //查看同步的服务器IP
 remote      refid   st t when poll reach  delay  offset jitter
==============================================================================
 50.77.217.185  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.90.158.4  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.71.100.89  .INIT.     16 u  -  64  0  0.000  0.000  0.000
 202.134.1.10  .INIT.     16 u  -  64  0  0.000  0.000  0.000
*127.127.1.0   .LOCL.     10 l  18  64 377  0.000  0.000  0.001
 
[root@localhost ~]# ntpstat  //同步的结果
synchronised to local net at stratum 11
 time correct to within 12 ms
 polling server every 512 s
!~ /^#/) {print }}' restrict default ignore //默认不允许修改或者查询ntp,并且不接收特殊封包 restrict 127.0.0.1 //给于本机所有权限 restrict 192.168.1.0 mask 255.255.255.0 notrap nomodify //给于局域网机的机器有同步时间的权限 server time.nist.gov prefer //设置时间服务器,加prefer表示优先 server 0.asia.pool.ntp.org server 1.asia.pool.ntp.org server 2.asia.pool.ntp.org server 127.127.1.0 # local clock fudge 127.127.1.0 stratum 10 driftfile /var/lib/ntp/drift keys /etc/ntp/keys

3、启动ntp

4、查看并测试

remote:即NTP主机的IP或主机名称。注意最左边的符号,如果由“+”则代表目前正在作用钟的上层NTP,如果是“*”则表示也有连上线,不过是作为次要联机的NTP主机。

refid:参考的上一层NTP主机的地址

st:即stratum阶层

when:几秒前曾做过时间同步更新的 *** 作

poll:下次更新在几秒之后

reach:已经向上层NTP服务器要求更新的次数

delay:网络传输过程钟延迟的时间

offset:时间补偿的结果

jitter:Linux系统时间与BIOS硬件时间的差异时间

以上即是本文要讲的Linux系统同步网络时间的2种方法,希望对大家有所帮助。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/903276.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-15
下一篇 2022-05-15

发表评论

登录后才能评论

评论列表(0条)

保存