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
本文来自博客园,作者:blog-elvin-vip,转载请注明原文链接:https://www.cnblogs.com/elvi/p/7657994.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 浏览器原生「磁吸」效果!Anchor Positioning 锚点定位神器解析
· 没有源码,如何修改代码逻辑?
· 一个奇形怪状的面试题:Bean中的CHM要不要加volatile?
· [.NET]调用本地 Deepseek 模型
· 一个费力不讨好的项目,让我损失了近一半的绩效!
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战