首页 > 其他 > 详细

系统时间同步脚本Centos7/8适用

时间:2021-04-30 10:24:56      阅读:27      评论:0      收藏:0      [点我收藏+]

此脚本为同步服务器时间的
针对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
        if ! grep "ntp.aliyun.com" /etc/chrony.conf &>/dev/null;
        then
                contents="pool 2.centos.pool.ntp.org"
                recontents="server ntp.aliyun.com iburst"
                #第三行后添加内容
                sed -i "3a$recontents" /etc/chrony.conf
                #将内容注释掉
                sed -i "s/$contents/#$contents/g" /etc/chrony.conf
        fi
        systemctl restart chronyd.service
        #设置开机自启
        systemctl enable chrony.service
        chronyc sources -v
        echo "susses 8..."
fi

系统时间同步脚本Centos7/8适用

原文:https://www.cnblogs.com/piout/p/14720100.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!