zoukankan      html  css  js  c++  java
  • CentOS7时间设置及ntp同步配置(转)

    出处:http://www.centoscn.com/CentOS/config/2015/1105/6385.html

    http://www.centoscn.com/CentOS/config/2015/0723/5901.html

    时间设置:

    在CentOS7中timectl命令负责时间管理。

    查看所有时区:

    timedatectl list-timezones

    设置时区:

    timedatectl set-timezone Asia/Shanghai

    设置日期:

    timedatectl set-time YYYY-MM-DD

    设置时间:

    timedatectl set-time HH:MM:SS

    ntp开启和关闭:

    timedatectl set-ntp yes
    timedatectl set-ntp no

    ntp时间同步

    NTP在linux下有两种时钟同步方式,分别为直接同步和平滑同步: 
    直接同步 
    使用ntpdate命令进行同步,直接进行时间变更。如果服务器上存在一个12点运行的任务,当前服务器时间是13点,但标准时间时11点,使用此命令可能会造成任务重复执行。因此使用ntpdate同步可能会引发风险,因此该命令也多用于配置时钟同步服务时第一次同步时间时使用。 
    平滑同步 
    使用ntpd进行时钟同步,可以保证一个时间不经历两次,它每次同步时间的偏移量不会太陡,是慢慢来的,这正因为这样,ntpd平滑同步可能耗费的时间比较长。

    标准时钟同步服务 
    http://www.pool.ntp.org/zone/cn网站包含全球的标准时间同步服务,也包括对中国时间的同步,对应的URL为cn.pool.ntp.org。

    在其中也描述了ntp配置文件中的建议写法: 
    server 1.cn.pool.ntp.org 
    server 3.asia.pool.ntp.org 
    server 2.asia.pool.ntp.org

    检查ntp服务是否安装:

    rpm -qa | grep ntp

    安装ntp服务:

    yum -y install ntp

    设置服务开机启动并启动服务:

    systemctl enable ntpd
    systemctl start ntpd

    同步时间:

    ntpdate -u cn.pool.ntp.org

    配置ntp同步服务器:

    vim /etc/ntpd.conf
    server 2.cn.pool.ntp.org
    server 1.asia.pool.ntp.org
    server 2.asia.pool.ntp.org

    重启ntp服务:

    systemctl restart ntpd

    查看时间同步状态:

    #ntpstat
    unsynchronised
      time server re-starting
       polling server every 8 s
  • 相关阅读:
    Java实现找出数组中重复次数最多的元素以及个数
    java经典小算法
    java将数组中的零放到末尾
    BP神经网络
    Centos配置Caffe详解
    JAVA面试题之实现字符串的倒序输出
    Android 发送短信与接收短信
    java 选择排序法
    java数组获取最值
    spring kafka consumer原理解析二
  • 原文地址:https://www.cnblogs.com/xiaoerlang/p/6576610.html
Copyright © 2011-2022 走看看