[linux]通过ssh远程设定各服务器时间,从而实现集群时间同步
#!/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
每分钟执行一次。
posted on 2016-07-28 17:04 xf-xrh-xf 阅读(1514) 评论(0) 编辑 收藏 举报
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步