[linux]通过ssh远程设定各服务器时间,从而实现集群时间同步
2016-07-28 17:04
786 查看
#!/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
每分钟执行一次。
相关文章推荐
- 制作Linux(Fedora、Ubuntu、CentOS)优盘启动 制作Linux(Fedora、Ubuntu、CentOS)优盘启动
- CentOS6配置部署Zabbix监控
- Kali Linux 秘籍 第二章 定制 Kali Linux
- linux终端在已经显示的输出中查找
- Linux 批量更改文件后缀名
- Linux中常用操作命令
- 对/etc/rc.d/init.d/目录的一点理解
- CentOS关于quota的总结与实践
- linux使用grep和find查找内容
- Centos 7 文件和目录管理
- linux如何关闭selinux?
- Linux wifi 破解
- 命令行会话管理工具screen命令详解
- Linux下配置Mysql允许远程访问详解
- LINUX C 语言--进程管理(一)
- Centos6.5 64位 安装Hadoop2.7.0, MapReduce日志分析, Hive2.1.0, JDBC连接Hive查询 (1)
- 命名管道(FIFO)
- new date() 在Linux下引起的时间差问题
- Linux文件I/O操作
- 【208】CentOS 下安装 Wine