zoukankan      html  css  js  c++  java
  • NTP时间同步 服务端 客户端 自动化安装配置

    NTP时间同步 服务端 客户端 自动化安装配置

     原创内容 http://www.cnblogs.com/elvi/p/7657994.html

    #!/bin/sh
    #运行环境 centos6、centos7
    # NTP时间同步 服务端 客户端 自动化安装配置
    #Mady by Elven
    
    function setntp1() {
    . /etc/init.d/functions
    pkill ntpd
    echo "时间更新……"
    /usr/sbin/ntpdate ntp6.aliyun.com
    [[ `echo $?` == 0 ]] || { echo "安装ntp服务" ; yum install ntp -y;/usr/sbin/ntpdate ntp6.aliyun.com; }
    #bakup
    cp -f /etc/ntp.conf /etc/ntp.conf.$(date +"%F-%T")
    
    echo "
    #默认配置部分
    driftfile /var/lib/ntp/drift
    restrict default kod nomodify notrap nopeer noquery
    restrict -6 default kod nomodify notrap nopeer noquery
    restrict 127.0.0.1
    restrict -6 ::1
    includefile /etc/ntp/crypto/pw
    keys /etc/ntp/keys
    ">/etc/ntp.conf
    }
    
    function setntp2() {
    echo "
    # 外部NTP服务
    server ntp6.aliyun.com perfer
    server cn.ntp.org.cn iburst
    server ntp.shu.edu.cn iburst
    server s2c.time.edu.cn iburst
    # server s2a.time.edu.cn iburst
    # server s2m.time.edu.cn iburst
    
    # 允许上层服务主动修改本机时间
    restrict ntp6.aliyun.com nomodify notrap noquery
    restrict cn.ntp.org.cn nomodify notrap noquery
    
    # 外部时间服务器不可用时,以本地时间作为时间服务
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    ">>/etc/ntp.conf
    }
    
    function ntp_server() {
    echo "
    # 作为内网192.168.20.* 提供NTP服务
    restrict 192.168.20.0 mask 255.255.255.0 nomodify notrap
    ">>/etc/ntp.conf
    }
    
    function ntp_client() {
    echo '内网时间同步'
    /usr/sbin/ntpdate 192.168.20.1
    echo "
    # 使用内网NTP服务
    server 192.168.20.1 iburst
    restrict 192.168.20.1 nomodify notrap noquery
    # 外部时间服务器不可用时,以本地时间作为时间服务
    server  127.127.1.0     # local clock
    fudge   127.127.1.0 stratum 10
    ">>/etc/ntp.conf
    }
    
    function ntptest() {
    # "重启NTP服务"
    [[ `uname -r` == *el6* ]] &&  
    { chkconfig ntpd on;service ntpd start; } || 
    { systemctl enable ntpd;systemctl start ntpd; }
    /usr/sbin/hwclock -w
    echo "NTP服务 状态检测"
    sleep 5
    netstat -upnl |grep ntpd
    ntpstat
    ntpq -p
    }
    
    case "$1" in 
        "s")
        setntp1
        setntp2
        ntp_server
        action "NTP配置" /bin/true
        ntptest
        exit
    ;;
        "c")
        setntp1
        ntp_client
        action "NTP配置" /bin/true
        ntptest
        exit
    ;;
        "-h")
        echo "-h 帮助"
        echo "c  安装NTP、并作为内网时间同步服务器Server"
        echo "s  安装NTP、使用内网时间同步服务"
        echo "*  安装配置NTP服务 "
    ;;
        *)
        setntp1
        setntp2
        action "NTP配置" /bin/true
        ntptest
        exit
    ;;
    esac
  • 相关阅读:
    .Net Core 3.1 解决数据大小限制
    Linux通过nginx反向代理net core项目
    外网无法通过IP访问部署在Windows服务器上的网站
    .NET Core项目部署时自定义端口号
    .NET Framework webAPI上传文件大小限制
    Windows服务器上部署.net core项目
    Windows服务器中PowerShell的使用
    Windows中命令提示符的打开和使用
    Linux部署net core并添加守护进程
    什么是串口服务器
  • 原文地址:https://www.cnblogs.com/elvi/p/7657994.html
Copyright © 2011-2022 走看看