系统时间同步脚本Centos7/8适用
此脚本为同步服务器时间的
针对Centos7/8
脚本自用测试中......
因为机房服务器需要定期与云上服务器同步时间,否则某些服务会出问题,
#!/bin/bash
#查看系统版本,如果为centos7则
if egrep "7.[0-9]" /etc/redhat-release &>/dev/null;
then
timedatectl set-timezone Asia/Shanghai
ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
yum -y install ntpdate
ntpdate ntp1.aliyun.com
hwclock --systohc
if ! grep "*/10 * * * * ntpdate ntp1.aliyun.com" /etc/crontab &>/dev/null;
then
echo "*/10 * * * * ntpdate ntp1.aliyun.com" >> /etc/crontab
fi
echo "susses 7..."
elif egrep "8.[0-9]" /etc/redhat-release &>/dev/null;
then
#加入开启启动
systemctl enable chronyd
#启动chronyd
systemctl start chronyd
#设置时区
rm -rf /etc/localtime && \
cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
chronyc sources -v
echo "susses 8..."
fi

浙公网安备 33010602011771号