zoukankan      html  css  js  c++  java
  • ntp时间同步

    集群时间同步

    1. 时间服务器配置(必须root用户)

    1) 检查ntp是否安装

    [root@node1 ~]# rpm -qa | grep ntp

    fontpackages-filesystem-1.44-8.el7.noarch

    ntp-4.2.6p5-25.el7.centos.2.x86_64

    python-ntplib-0.3.2-1.el7.noarch

    ntpdate-4.2.6p5-25.el7.centos.2.x86_64

    2) 如果没有ntp服务,可使用yum命令进行安装

    [root@node1 ~]# yum -y install ntp

    2. 检查当前系统时区

    1) 选择某台机器,作为集群中时间服务器的主节点,然后其他机器同步该机器的时间即可。但是在开始这步操作之前,我们需要确保所有节点的时区是统一的

    [root@node1 ~]# date -R

    显示类似如下格式:

    Wed, 28 Feb 2018 15:28:53 +0800

    2) 尖叫提示:如果显示的时区不是+0800,你可以删除localtime文件夹后,再关联一个正确时区的链接过去

    [root@node1 ~]# rm -rf /etc/localtime

    [root@node1 ~]# ln -s /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

    3. 同步网络时间

    1) 如果怀疑自己本地机器的时间与标准时间相差很多,建议使用时间服务器的主节点同步一下网络时间:

    [root@node1 ~]# ntpdate pool.ntp.org

    4. 修改ntp配置文件

    1) 我们需要修改ntp服务的配置文件,关闭网络时间的同步

    [root@node1 ~]# vi /etc/ntp.conf

    2)对如下内容做出修改

    # Hosts on local network are less restricted.

    # 授权192.168.2.0网段上的所有机器可以从这台机器上查询和同步时间

    restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap

    # 当该节点丢失网络连接,依然可以作为时间服务器为集群中的其他节点提供时间同步

    server 127.127.1.0

    fudge  127.127.1.0 stratum 10

    # Please consider joining the pool (http://www.pool.ntp.org/join.html).

    #集群在局域网中,不使用其他的网络时间

    #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

    尖叫提示:

    nomodify:客户端不能使用ntpc与ntpq修改服务器的时间参数

    notrap:不提供trap远程时间登录的功能

    5.重启ntp服务

    CentOS6

    [root@node1 ~]# service ntpd restart

    [root@node1 ~]# chkconfig ntpd on

    CentOS7

    [root@node1 ~]# systemctl restart ntpd.service

    [root@node1 ~]# systemctl enable ntpd.service

    6. 设置定时同步任务
    1) 首先在其他节点上关闭ntp服务

     

    CentOS6

    [root@node1 ~]# service ntpd stop

    [root@node1 ~]# chkconfig ntpd off

     

    CentOS7

    [root@node1 ~]# systemctl stop ntpd.service

    [root@node1 ~]# systemctl disable ntpd.service

     

    查看ntp进程id

    [root@node1 ~]# pgrep ntpd

     

    2) 其他节点手动同步第一台时间服务器的时间进行测试

    [root@node1 ~]# ntpdate node1

     

    3) 其他节点制定计划任务,周期性同步时间

    [root@node1 ~]# crontab -e

    # .------------------------------------------minute(0~59)

    # | .----------------------------------------hours(0~23)

    # | | .--------------------------------------day of month(1~31)

    # | | | .------------------------------------month(1~12)

    # | | | | .----------------------------------day of week(0~6)

    # | | | | | .--------------------------------command

    # | | | | | |

    # | | | | | |

    */10 * * * * /usr/sbin/ntpdate node1

     

    4) 重启定时任务

     

    CentOS6

    [root@node1 ~]# service crond restart

     

    CentOS7

    [root@node1 ~]# systemctl restart crond.service      

     

    5) 查看任务

    [root@node1 ~]# crontab -l

  • 相关阅读:
    Nginx.conf 配置文件详细说明
    CentOs中iptables配置允许mysql远程访问
    CentOS 6.4下编译安装MySQL 5.6.14
    CentOS6.4下Mysql数据库的安装与配置
    让nginx支持.htaccess文件实现伪静态的方法!
    MySQL导入.sql文件及常用命令
    PHP里10个鲜为人知但却非常有用的函数
    Nginx配置文件详细说明
    linux 开机启动nginx
    Redhat系列使用ISO或者光盘制作yum本地安装源
  • 原文地址:https://www.cnblogs.com/heihouzi/p/8663821.html
Copyright © 2011-2022 走看看