最近遇到一个问题,由于两台服务器时间的问题,经常导致用户登录由于时间差问题而报错,再三百度,最后整理了一下修改linux定时同步的操作(本方法适用于有自己时间服务器,没有的只限于借鉴)

首先确认,我们的服务是否已经安装了ntp服务

如果没有安装,需要先安装ntp服务

安装完ntp之后,编辑ntp.conf

vi /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 kod nomodify notrap nopeer noquery
restrict -6 default kod 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 -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).
server 127.0.0.1
#server 1.centos.pool.ntp.org
#server 2.centos.pool.ntp.org #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 # Undisciplined Local Clock. This is a fake driver intended for backup
# and when no outside source of synchronized time is available.
# local clock
#fudge 127.127.1.0 stratum 10 # 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

  在文件中 可以看到修改标出来的ip地址,改为自己的时间服务器地址,也可以是域名

修改后保存退出

命令行输入

crontab -e

  设置定时任务,其这里设置的是

* * */1 * * /usr/sbin/ntpdate 127.0.0.1 >> /home/logs/ntpd.log

 同样修改ip地址 
然后创建日志文件夹用来存放日志

mkdir /home/logs

  ok 大功告成,过几分钟在日志文件夹可以看到日志文件,浏览会发现,时间差不超过0.01s .一般来说是够用了的

linux设置自动同步服务器时间的更多相关文章

  1. Linux 自动同步服务器时间

    200 ? "200px" : this.width)!important;} --> 介绍 Linux服务器运行久时,系统时间就会存在一定的误差,本篇文章就来介绍怎样使服务 ...

  2. linux下自动同步internet时间

    linux下很简单直接一句即可: ntpdate time.nist.gov ntp后面参数为internet时间服务器url或ip即可. 但是ntpdate命令需要root特权,如果做成自动运行每次 ...

  3. centos自动同步服务器时间

    原文:https://my.oschina.net/yysue/blog/1628733 1.安装ntpdate yum install ntpdate -y 2.测试是否正常 ntpdate cn. ...

  4. linux通过ntpd同步服务器时间,

    ntpd得rpm包下载地址:https://pkgs.org/download/ntp 比如我得服务器版本是centos7 x86的,那选择我点击的这一个: 下拉到最下面就有安装包下载了,我选择的是二 ...

  5. linux设置时区同步时间

    linux设置时区同步时间 一.运行tzselect sudo tzselect 在这里我们选择亚洲 Asia,确认之后选择中国(China),最后选择北京(Beijing) 如图:   二.复制文件 ...

  6. [Jquery 插件]活动倒计时,可同步服务器时间,倒计时格式随意设置

    活动倒计时,可同步服务器时间,倒计时格式随意设置 使用说明 /* #活动倒计时,可同步服务器时间 startTime:起始时间 endTime:结束时间 format_str:字符模板 speed:倒 ...

  7. javascript小技巧:同步服务器时间、同步倒计时

    之前在网上看到有人提问,如何在页面上同步显示服务器的时间,其实实现方法有几种,可能一般人立马就想到可以使用Ajax每隔一秒去请求服务器,然后将服务器获取到时间显示在页面上,这样虽然能够实现,但存在一个 ...

  8. Linux+Jenkins自动构建服务器包

    何时使用: 测试过程中我们需要持续构建一个软件项目,为避免重复的手动下载.解压操作,我们需要搭建一个能够自动构建的测试环境,当代码有更新时,测试人员只需点一下[构建]即可拉取最新的代码进行测试(也可设 ...

  9. linux设置开机同步时间

    在/etc/init.d/下新建zhjdate脚本,添加如下内容: #!/bin/bash# chkconfig: 345 63 37#chkconfig:345 63 37 (数字345是指在运行级 ...

随机推荐

  1. .net视频截图功能,没测试

    /// <summary> /// @从视频文件截图,生成在视频文件所在文件夹 /// 在Web.Config 中需要两个前置配置项: /// 1.ffmpeg.exe文件的路径 ///  ...

  2. 如何理解AWS 网络,如何创建一个多层安全网络架构

    目录 一.要求 网络架构图 网络各组件关系 二.操作步骤 2.1.网络设置 2.2.安全设置 2.3.创建实例 三.费用 3.1.NAT 网关费用 一.要求 创建一个三层网络架构,服务器只能通过跳板机 ...

  3. Jupter Notebook常用快捷键与常用的魔法命令

    jupter notebook快捷键整理 Part1 1.删除Cell——双击D 2.撤销删除——Z 3.新建Cell——A/B (向上/向下) 4.命令窗口——P 5.运行——Ctrl+Enter ...

  4. 最新 美团java校招面经 (含整理过的面试题大全)

    从6月到10月,经过4个月努力和坚持,自己有幸拿到了网易雷火.京东.去哪儿.美团等10家互联网公司的校招Offer,因为某些自身原因最终选择了美团.6.7月主要是做系统复习.项目复盘.LeetCode ...

  5. ORACLE创建表空间和用户,并分配权限

    注意:如果是创建新的库,首先要先创建表空间,之后才可以创建用户:1.//创建临时表空间 create tablespace NCPZS_DATA datafile '/home/soft/oracle ...

  6. vue 强制刷新组件重新渲染

    实现功能:使用富文本编辑器编写文章,然后把编写成功的文章用子组件显示. 问题描述:父组件给子组件传递数据,子组件第一次调用数据的时候页面渲染是正常的,当数据变化的时候,子组件的页面渲染就失效了. 问题 ...

  7. C#中使用HttpClient来Post数据的内容HttpContent的各种格式

    平时使用各种网络传输的时候基本上是以Json格式进行的, 所以对其他几种格式也是一知半解, 今天静下心对其好好梳理一番. 首先我借鉴了一篇文章(https://segmentfault.com/a/1 ...

  8. Jmeter做HTTP接口测试

    接口测试概述:https://www.cnblogs.com/mawenqiangios/p/7886115.html Jmeter接口测试教程:https://www.cnblogs.com/hou ...

  9. C#xml泛型序列化

    using System; using System.Collections.Generic; using System.IO; using System.Text; using System.Web ...

  10. C# Enum操作

    枚举定义 /// <summary> /// 节点类型 /// </summary> public enum NodeTypeEnum { 企业 = , 人员 = , 人员地址 ...