温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

怎么在各种Linux系统的服务器上设置时间同步

发布时间:2021-08-03 18:33:28 来源:亿速云 阅读:116 作者:chen 栏目:系统运维

本篇内容主要讲解“怎么在各种Linux系统的服务器上设置时间同步”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“怎么在各种Linux系统的服务器上设置时间同步”吧!

独立主机

rm -rf /etc/localtime

ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改时区到东8区。

date -R #查看的时区设置。

接下来调整系统时间与时间服务器同步

Debian系统安装NTP校时包:

   

代码如下:

apt-get install ntpdate #安装ntp

CentOS系统安装NTP校时包:

   

代码如下:

yum -y install ntpdate ntp #安装ntp

Ubuntu系统安装NTP校时包:

   

代码如下:

sudo apt-get install -y ntpdate ntp

修改/etc/ntp.conf

vi /etc/ntp.conf    就会看到以下内容:

   

代码如下:

server 0.centos.ntp.org</p> <p>    server time.windows.com</p> <p>    server time.nist.gov

这是默认的ntp同步服务器,大家可以自己改,全球ntp服务器地址:http://www.pool.ntp.org/

我改成了:

   

代码如下:

server cn.pool.ntp.org    //这中国的ntp服务器
   server time-a.nist.gov
   server time.windows.com
   server time.nist.gov

然 后保存退出(vi退出的方法见:http://www.dabu.info/personal-summary-personally-i- carefully-collected-must-be-familiar-with-vim-shortcut-key-operation.html)

接着输入下面的命令:

   

代码如下:

ntpdate -d cn.pool.ntp.org #调试查看时间差异</p> <p>    ntpdate cn.pool.ntp.org #同步时间</p> <p>    date -R # 检查时间是否同步

修改 ntp 的配置文件

代码如下:

vi /etc/sysconfig/ntpd</p> <p>    SYNC_HWCLOCK=yes #同步独立主机的硬件时钟</p> <p> </p> <p>#配置开机启动ntp服务,定期同步时间</p> <p>    chkconfig --levels 235 ntpd on #启动ntp同步</p> <p>    /etc/init.d/ntpd start

XEN VPS

最好是安装ntp服务,这样可以解决vps在重启后时间不准的问题。有时候,依靠母鸡的硬件时钟,总是差七八分钟。实在没辙了。而已很多的web服务,如Google Authenticator等,如果时间不同步,会导致无法验证的地步,自然就网站都登陆不上了。

代码如下:

rm -rf /etc/localtime</p> <p>ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改时区到东8区。</p> <p>date -R #查看的时区设置。

接下来调整系统时间与时间服务器同步

Debian系统安装NTP校时包:

   

代码如下:

apt-get install ntpdate #安装ntp

CentOS系统安装NTP校时包:

   

代码如下:

yum -y install ntpdate ntp #安装ntp

Ubuntu系统安装NTP校时包:

   

代码如下:

sudo apt-get install -y ntpdate ntp

修改/etc/ntp.conf

vi /etc/ntp.conf    就会看到以下内容:

   

代码如下:

server 0.centos.ntp.org</p> <p>    server time.windows.com</p> <p>    server time.nist.gov

这是默认的ntp同步服务器,大家可以自己改,全球ntp服务器地址:http://www.pool.ntp.org/

我改成了:

   

代码如下:

server cn.pool.ntp.org    //这中国的ntp服务器
   server time-a.nist.gov
   server time.windows.com
   server time.nist.gov

然 后保存退出(vi退出的方法见:http://www.dabu.info/personal-summary-personally-i- carefully-collected-must-be-familiar-with-vim-shortcut-key-operation.html)

接着输入下面的命令:

代码如下:

ntpdate -d cn.pool.ntp.org #调试查看时间差异</p> <p>    ntpdate cn.pool.ntp.org #同步时间</p> <p>    date -R # 检查时间是否同步</p> <p> </p> <p>#配置开机启动ntp服务,定期同步时间</p> <p>    chkconfig --levels 235 ntpd on #启动ntp同步</p> <p>    /etc/init.d/ntpd start</p> <p> </p> <p>#先设置XEN 的VPS使用和系统无关的时间模式</p> <p>    echo 1 > /proc/sys/xen/independent_wallclock

然后尝试上面独立主机的配置方法即可。通过配置时间正确后,编辑系统配置文件,让配置永久生效。

代码如下:

vi /etc/sysctl.conf</p> <p>    xen.independent_wallclock=1 #在文件中增加并且保存

OpenVZ VPS

(Burst VPS 采用)

OpenVZ的VPS直接从物理机读取时间不允许对主机进行时间修改,你只需修改时区。我还没用过openvz vps,所以,不清楚能否用ntp服务不,可以试试安装ntp service 看。如果可以的话,请告诉我。

代码如下:

rm -rf /etc/localtime</p> <p>ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime #修改时区到东8区。</p> <p>date -R #查看时间和时区

此时如果时间和时区都正确,配置成功,时间如果不对,需要联系主机服务商的技术支持,让他们把母鸡(物理机)时间同步,你的VPS时间就会正常。

到此,相信大家对“怎么在各种Linux系统的服务器上设置时间同步”有了更深的了解,不妨来实际操作一番吧!这里是亿速云网站,更多相关内容可以进入相关频道进行查询,关注我们,继续学习!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI