zoukankan      html  css  js  c++  java
  • centos7下配置时间同步服务器

    同网段20几台服务器:

    其中有一组mysql 集群中 互为主从

    选一台mysql master 作为时间同步的服务器,这样做的好处以便于这台down了 另一个与他互为主从的master 继续提供时间同步服务。

    假如 这个mysql 集群  ip是这样分配

    master1 :10.0.0.11

    master2  :10.0.0.12

    其他 。。。。。省略

    vip: 10.0.0.20

    1. 选择一台服务器作为时间服务器。(master1做为时间服务器)
    2. 使用root用户,查看服务器是否安装ntp服务 
      rpm -qa|grep ntp
      timedatectl set-timezone Asia/Shanghai

       没有安装的话使用yum install进行安装。

    3.   修改文件 /etc/ntp.conf,一共修改三处内容:
    4.   ①将#去掉。并且将网段修改正确。
      restrict 10.0.0.0 mask 255.255.255.0 nomodify notrap
    5.  ②将以下4个server进行#注释掉
      #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

      server ntp1.aliyun.com
      server ntp2.aliyun.com
      server ntp3.aliyun.com
      server ntp4.aliyun.com
      server ntp5.aliyun.com
      server ntp6.aliyun.com
      server ntp7.aliyun.com

    6. ③最后添加俩句话:

      server 127.127.1.0 #local clock
      fudge  127.127.1.0 stratum 10
    7. 编辑etc/sysconfig/ntpd文件
      # Drop root to id 'ntp:ntp' by default.
      SYNC_HWCLOCK=yes
      OPTIONS="-u ntp:ntp -p /var/run/ntpd.pid -g"
    8. 启动ntpd服务,并且设置开机启动

      systemctl start ntpd.service
      systemctl enable ntpd.service
    9. 新建同步 master1 服务器的脚本。(每隔5分钟同步一次maste1服务器)
    [root@slave2 ~]# cat /opt/script/ntp.sh 
    #!/bin/bash
    
    while true
    do
      /usr/sbin/ntpdate 10.0.0.20 &> /dev/null
      sleep 300
    done

    centos7 的开机自启动文件默认没有执行权限 需要添加以下,并设置脚本开机自启动

    chmod +x /etc/rc.d/rc.local
    chmod +x /opt/script/ntp.sh


    vi /etc/rc.d/rc.local #加入下面的命令
    /opt/script/ntp.sh &

    10.重启后查看  脚本进程是否在后台运行着

     这里基本就完成了,有个地方要说下,一开始准备用定时任务执行命令的,但是不知道这centos7 有什么毛病,死活不执行,索性用个死循环脚本放后台执行吧 ,并设置开机自启动脚本。

  • 相关阅读:
    [转载]Back up all of your mysql databases nightly
    编写windows7 bat运行脚本
    Windows7开通Internet信息服务
    【LeetCode题解】7_反转整数
    【LeetCode题解】350_两个数组的交集Ⅱ
    【LeetCode题解】349_两个数组的交集
    【LeetCode题解】94_二叉树的中序遍历
    【LeetCode题解】144_二叉树的前序遍历
    【LeetCode题解】2_两数相加
    【LeetCode题解】530_二分搜索树的最小绝对值差
  • 原文地址:https://www.cnblogs.com/benjamin77/p/8677900.html
Copyright © 2011-2022 走看看