努力挣扎的生活 努力挣扎的生活
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 运维基础
  • 监控
  • 日志系统
  • gitlab安装
  • jenkins安装和管理
  • Jenkins工具集成
  • pipeline流水线
  • Docker
  • Kubernetes
  • Nexus
  • Rancher
  • Prometheus
  • ELK(EFK)
  • 虚拟化
  • Mysql
  • PostgreSQL
  • Redis
  • MongoDB
  • clickhouse
关于
  • 分类
  • 标签
  • 归档
  • 收藏
  • 更多
GitHub (opens new window)

yangfk

瑟瑟发抖的小运维
  • 前端文章

    • JavaScript
  • 学习笔记

    • 《JavaScript教程》
    • 《JavaScript高级程序设计》
    • 《ES6 教程》
    • 《Vue》
    • 《React》
    • 《TypeScript 从零实现 axios》
    • 《Git》
    • TypeScript
    • JS设计模式总结
  • 运维基础
  • 监控
  • 日志系统
  • gitlab安装
  • jenkins安装和管理
  • Jenkins工具集成
  • pipeline流水线
  • Docker
  • Kubernetes
  • Nexus
  • Rancher
  • Prometheus
  • ELK(EFK)
  • 虚拟化
  • Mysql
  • PostgreSQL
  • Redis
  • MongoDB
  • clickhouse
关于
  • 分类
  • 标签
  • 归档
  • 收藏
  • 更多
GitHub (opens new window)
  • 运维基础

    • nginx 安装
    • nginx-conf常用示例
    • rsync 服务pull与push
    • linux时间同步
      • date命令
      • ntpdate命令
        • 公网同步服务器
      • ntpd服务
        • 关闭防火墙
        • 安装
        • 配置文件示例
      • Windows开启ntpServer
    • 系统参数优化
    • ruby版本升级
    • fpm定制rpm
    • php7_X安装
    • iptables规则
    • tcpdump抓包
    • 公司部署Pritunl-VPN
    • 需求shell脚本记录
    • openldap安装配置
    • Ldap集成常用开源服务示例图
    • ansible基础
    • ansible进阶playbook与Roles
    • centos安装python3
    • Firewalld防火墙
    • Linux配置jdk
    • ubuntu安装ftp
    • minio分布式文件存储
    • windows安装openssh
    • centos7安装系统检测不到网卡
    • docker运行一个bind9和常用的网络命令
    • nginx禁用真实IP
  • 监控

  • 日志系统

  • 安全记录

//
  • 运维
  • 运维基础
yangfk
2019-08-23

linux时间同步

//

为啥时间同步? 因为监控,k8s集群,数据库主从延迟,等等......

# date命令

命令示例 说明
date 查看当前时间
date +%y_%m_%d 查看当前年月日 "21_09_27"
date +%F_%H:%M:%S 查看当前详细时间年月日时分秒 "2021-09-27_16:14:54"
date -d "-1 day" 查看前一天时间
date -d "+1 hour" 查看后一小时
date -s "2020-09-27" 修改时间为2020年9月27号,00:00:00
date -s "16:00:05" 修改时间为今天的16点5秒

window修改时间:cmd 打开终端,输入 time 输入时间,就是你要修改的时间

# ntpdate命令

ntpdate命令需要安装:

yum install ntpdate -y

调试命令:

ntpdate -d 192.168.5.8

  • 同步命令

同步IP: ntpdate -u 192.168.5.8

同步网络时间: ntpdate -u ntp.aliyun.com

注意:若不加上-u参数, 也行会出现以下提示:no server suitable for synchronization found ,-u参数可以越过防火墙与主机同步;

# 公网同步服务器

  • 国内
cn.pool.ntp.org  中国开源免费NTP服务器
ntp.aliyun.com 阿里云NTP服务器
ntp1.aliyun.com 阿里云NTP服务器
time1.aliyun.com 阿里云NTP服务器
time2.aliyun.com 阿里云NTP服务器
1
2
3
4
5
  • 国外
pool.ntp.org 开源免费NTP服务器
time1.apple.com 苹果NTP服务器
time2.apple.com 苹果NTP服务器
time1.google.com 谷歌NTP服务器
time2.google.com 谷歌NTP服务器
1
2
3
4
5

# ntpd服务

# 关闭防火墙

setenforce 0
systemctl stop firewalld

#永久关闭
sed -i 's#^SELINUX=.*#SELINUX=disabled#g' /etc/sysconfig/selinux
systemctl disable firewalld
1
2
3
4
5
6

# 安装

  • yum安装

yum install ntp -y

# 配置文件示例

  • 内网同步
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

#内网ntp同步服务器15
server 192.168.5.15 prefer

server 127.127.1.0
fudge 127.127.1.0 stratum 8
1
2
3
4
5
6
7
8
9
10
11
12
13
  • 外网同步ntp.aliyun.com
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1 
restrict ::1
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor

restrict 192.168.5.0 mask 255.255.255.0 nomodify notrap
server ntp.aliyun.com iburst
pool ntp.aliyun.com

1
2
3
4
5
6
7
8
9
10
11
12

查看服务状态: ntpq -p

参数 说明
remote 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先
refid 参考上一层ntp主机地址
st stratum阶层
when 多少秒前曾经同步过时间
poll 下次更新在多少秒后
reach 已经向上层ntp服务器要求更新的次数
delay 网络延迟
offset 时间补偿
jitter 系统时间与bios时间差
  • ntp.conf 配置参数

访问控制的支持;语法为: restrict IP地址 mask 子网掩码 参数 其中IP地址也可以是default ,default 就是指所有的IP。

ignore:拒绝所有类型的NTP的连线。

nomodfiy:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

noquery:不提供客户端的时间查询。

notrap:不提供trap这个远程时间登录的功能。

notrust:拒绝没有认证的用户端。

restrict -6 表示IPV6地址的权限设置。

nopeer 不与其他同一层的ntp服务器进行时间同步。

restrict default ignore # 关闭所有的IP-v4 NTP服务器联机服务

preper 优先级设定

server 进行设置上端同步ntp

iburst 当一个远程ntp服务器不可用时,向它发送一系列的并发包进行检测

burst 当一个远程ntp服务器可用时,向它发送一系列的并发包进行检测

# Windows开启ntpServer

记录:https://blog.csdn.net/weixin_44248438/article/details/89419949

win + R -->> regedit 注册表修改

	打开注册表编辑器。您可以按Win+R键,然后输入regedit并回车。
	
	导航到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer
	
		在右侧面板中,双击"Enabled",然后在数据值字段中输入"1"。
	
	导航到 HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\Config
	
	在右侧面板中,双击"AnnounceFlags",然后在数据值字段中输入"5"。
  • 重启时间服务

net stop w32time && net start w32time

win + R -->> wf.msc 添加入站规则

防火墙放开udp协议端口:123

//
如果此文章对您有帮助,点击 -->> 请博主喝咖啡 (opens new window)
上次更新: 2025/03/28, 13:42:54
rsync 服务pull与push
系统参数优化

← rsync 服务pull与push 系统参数优化→

最近更新
01
Linux Polkit 权限提升漏洞(CVE-2021-4034)
03-28
02
postgreSQL维护
03-17
03
trivy系统漏洞扫描
02-25
更多文章>
Theme by Vdoing | Copyright © 2019-2025 yangfk | 湘ICP备2021014415号-1
  • 跟随系统
  • 浅色模式
  • 深色模式
  • 阅读模式
×
//