当前位置: 首页 > news >正文

【个人记录】同步Linux服务器时间和时区

修改时区

timedatectl set-timezone Asia/Shanghai

时间同步

使用ntp进行同步,时间服务器使用阿里云NTP服务器

安装NTP服务

yum install -y ntp

写入NTP配置文件

cat > /etc/ntp.conf <<EOF
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOF

服务生效

systemctl restart ntpd

检查服务状态

ntpstat
date

一键脚本

#!/bin/bash
timedatectl set-timezone Asia/Shanghai
yum install -y ntp
cat > /etc/ntp.conf <<EOF
driftfile /var/lib/ntp/drift
restrict default nomodify notrap nopeer noquery
restrict 127.0.0.1
restrict ::1
server ntp.aliyun.com iburst
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys
disable monitor
EOF
systemctl restart ntpd
ntpstat
date

参考文档

https://blog.csdn.net/krabbit1997/article/details/112510514
https://help.aliyun.com/zh/ecs/user-guide/alibaba-cloud-ntp-server
http://www.lryc.cn/news/246597.html

相关文章:

  • 面试常问-如何判断链表有环、?
  • 基于springboot实现农机电招平台系统项目【项目源码+论文说明】计算机毕业设计
  • 森林无人机高效解决巡查难题,林区防火掀新篇
  • python 爬虫之 爬取网站信息并保存到文件
  • kubelet漏洞CVE-2020-8559复现与分析
  • 基于C#实现奇偶排序
  • Kibana部署
  • 【Linux】了解进程的基础知识
  • ES6 — ES14 新特性
  • 附录12-time.h的常用方法
  • C语言公交车之谜(ZZULIOJ1232:公交车之谜)
  • Liunx Ubuntu Server 安装配置 Docker
  • Oracle ORA12514 监听程序当前无法识别连接描述符中请求的服务
  • druid keepAlive 导致数据库连接数飙升
  • 四川竹哲电子商务有限公司深耕抖音电商服务领域
  • 爬虫中XPath语法四个重要概念及示例
  • MySQL-03-索引
  • CSS-长度单位篇
  • 自己动手实现一个深度学习算法——七、卷积神经网络
  • office word 使用笔记
  • vue中下载文件后无法打开的坑
  • 【追求卓越04】数据结构--栈与队列
  • 基于SpringBoot的超市信息管理系
  • 【计算机组成原理】存储系统
  • 基于SSM的旅游管理系统设计与实现
  • JeecgBoot3.0 漏洞升级 — 快速文档
  • 6.一维数组——用冒泡法,选择法将5个整数由大到小排序
  • YOLOv8 onnx 文件推理多线程加速视频流
  • CVE-2017-12615 文件上传
  • c++没有返回值的返回值