#!/usr/bin/env bash

#all hosts should to  sync time, all hosts should no password login echo other

synchosts_array=("xufeng-1" "xufeng-2")

#currnt time in this host

currentDay=`date "+%Y-%m-%d"`

currentTime=`date "+%H:%M:%S"`

echo "current day in this host is "

echo $currentDay

echo "current time in this host is "

echo $currentTime

#loop host to set time

for hostname in ${synchosts_array[*]}

do

    echo $hostname

    ssh -t $hostname bash -c "'date -s '$currentDay' &&hwclock --systohc'"

    ssh -t $hostname bash -c "'date -s '$currentTime' &&hwclock --systohc'"

done

在某个节点上配置任务调度周期即可:

crontab -u root -e

*/ * * * * /opt/software/rootbin/synctime.sh >> /opt/software/rootbin/synctime.log

每分钟执行一次。

[linux]通过ssh远程设定各服务器时间,从而实现集群时间同步的更多相关文章

  1. Linux 下 SSH 远程超时解决方案

    Linux 下 SSH 远程超时解决方案 今天突然看到一个问题说是如何解决SSH远程超时的问题. 找了一点资料.用于解决这个需求~ 第一种:OpenSSH 配置文件设置 位于112行的 "C ...

  2. (转)详解Linux中SSH远程访问控制

    详解Linux中SSH远程访问控制 原文:http://blog.51cto.com/dengqi/1260038 SSH:是一种安全通道协议,主要用来实现字符界面的远程登录,远程复制等功能(使用TC ...

  3. mac 通过 终端 ssh 远程连接 centos 服务器

    mac 通过 终端 ssh 远程连接 centos 服务器 在终端下输入 ssh -l root 204.74.*.*      就可以连接了,这是端口没变的情况,还是原来的22 ssh -p 448 ...

  4. Oracle归档日志所在目录时间不对&&Oracle集群日志时间显示错误

    Oracle归档日志所在目录时间不对&&Oracle集群日志时间显示错误 前言 这个问题在18年的时候遇到了,基本不注意并且集群或者数据库运行正常是很难注意到的. 忘记当时怎么发现的了 ...

  5. 在linux环境下安装redis并且搭建自己的redis集群

    此文档主要介绍在linux环境下安装redis并且搭建自己的redis集群 搭建环境: ubuntun 16.04 + redis-3.0.6 本文章分为三个部分:redis安装.搭建redis集群 ...

  6. Linux:ssh远程执行命令并自动退出

    ssh命令格式: [root@localhost ~]# ssh --helpusage: ssh [-1246AaCfgKkMNnqsTtVvXxYy] [-b bind_address] [-c ...

  7. linux利用ssh远程执行多台机器执行同样的命令

    这篇文章主要介绍了ssh远程执行命令方法和Shell脚本实例,本文讲解了ssh执行远程操作方法和远程执行命令shell脚本示例,需要的朋友可以参考下 ssh执行远程操作命令格式代码如下: ssh -t ...

  8. SSH远程登录CentOS服务器

    1.把ssh默认远程连接端口修改为2200编辑防火墙配置:vi /etc/sysconfig/iptables防火墙增加新端口2222 -A INPUT -m state --state NEW -m ...

  9. Linux下 SSH远程管理服务

    第1章 SSH基本概述 1.1 SSH服务协议说明 SSH 是 Secure Shell Protocol 的简写,由 IETF 网络工作小组(Network Working Group )制定 在进 ...

随机推荐

  1. P4316 绿豆蛙的归宿

    题意翻译 「Poetize3」 题目背景 随着新版百度空间的上线,Blog宠物绿豆蛙完成了它的使命,去寻找它新的归宿. 题目描述 给出一个有向无环图,起点为1终点为N,每条边都有一个长度,并且从起点出 ...

  2. 122. Best Time to Buy and Sell Stock II (Array)

    Say you have an array for which the ith element is the price of a given stock on day i. Design an al ...

  3. java.util.Stack类简介(栈)

    Stack是一个后进先出(last in first out,LIFO)的堆栈,在Vector类的基础上扩展5个方法而来 Deque(双端队列)比起stack具有更好的完整性和一致性,应该被优先使用 ...

  4. BZOJ4873:[SHOI2017]寿司餐厅——题解

    http://www.lydsy.com/JudgeOnline/problem.php?id=4873 https://www.luogu.org/problemnew/show/P3749 简要题 ...

  5. js判断设备类型

    1. 判断微信 function is_weixin() { var ua = window.navigator.userAgent.toLowerCase(); if (ua.match(/Micr ...

  6. Linux之poll与select20160619

    使用非阻塞I/O的应用程序通常会使用select()和poll()系统调用查询是否可对设备进行无阻塞的访问,这两个系统调用最终又会引发设备驱动中的poll()函数被执行 如果当前不可读(先调用驱动.p ...

  7. The database cluster was initialized with RELSEG_SIZE 1048576, but the server was compiled with RELSEG_SIZE 8388608

    由于一次误操作,将线上机器的数据库程序目录删除,虽然不影响程序的正常使用,数据也未丢失,但后面如果出现服务器宕机或数据库宕机,数据库将无法启动,而且数据库对应的编译参数也已无法查看,所以征得开发同意后 ...

  8. bzoj 1132 [POI2008]Tro 几何

    [POI2008]Tro Time Limit: 20 Sec  Memory Limit: 162 MBSubmit: 1796  Solved: 604[Submit][Status][Discu ...

  9. MongoDB入门(4)- MongoDB日常操作

    MongoDB客户端 MongoDB有很多客户端 MongoVue Robomongo MongoDB命令行 启动mongo shell 在windows下,双击mongo.exe可以启动mongo ...

  10. UVA 10837 A Research Problem

    https://vjudge.net/problem/UVA-10837 求最小的n,使phi(n)=m #include<cstdio> #include<algorithm> ...