分享

[linux]通过ssh远程设定各服务器时间,从而实现集群时间同步

 快来看看咯 2021-05-31
复制代码
#!/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

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

每分钟执行一次。

    本站是提供个人知识管理的网络存储空间,所有内容均由用户发布,不代表本站观点。请注意甄别内容中的联系方式、诱导购买等信息,谨防诈骗。如发现有害或侵权内容,请点击一键举报。
    转藏 分享 献花(0

    0条评论

    发表

    请遵守用户 评论公约

    类似文章 更多