1,使用命令date -s
for((i=101;i<=103;i++))
do
#获取当前机器时间: 年月日, 时分秒
datestr=`date +%y-%m-%d`
datestr2=`date +%H:%M:%S`
#同步其他主机时间
echo "ssh s$i date -s--------$datestr $datestr2"
ssh s$i date -s $datestr
ssh s$i date -s $datestr2
ssh s$i hwclock -w #写入bios
echo
done
2, 安装ntpd服务
集群节点: s101[192.168.56.111] --> s102[192.168.56.112] --> s103[192.168.56.113]
设置: s101为时间服务器,其他节点同步s101的时间
- 1, 所有节点 ,统一 使用 yum 安装ntp
- 2, 修改/etc/ntpd.conf
a, 服务器master 节点
修改 /etc/ntpd.conf
#允许本局域网段修改时间
restrict 192.168.56.0 mask 255.255.255.0 nomodify notrap
#配置自己,充当时间同步服务器
server 127.127.1.0
fudge 127.127.1.0 stratum 10
修改 ntpd启动参数
echo “SYNC_HWCLOCK=yes” >> /etc/sysconfig/ntpd
b, slave节点
执行同步时间的命令: ntpdate s101; hwclock -w
这种配置,同样需要配置定时任务: 定期进行时间同步
crontab -e
*/10 * * * * ntpdate s101; hwclock -w