同步阿里时间服务器和建立私有时间服务器同步

  • 时间同步(同步阿里云时间服务器)
    • centos 安装
    • ubuntu 安装
    • 配置文件
    • 监听的端口
    • 如果系统上已经有其他时间服务,那么先停止
    • 防火墙设置
      • Firewalld设置
      • iptables 防火墙设置
    • 具体操作步骤
    • 配置阿里云时间服务器 ntp.aliyun.com
    • 设置启用NTP时间 自动同步
    • 手动同步系统时间
    • 查看同步源
    • 同步源状态
    • 设置硬件时间,硬件时间默认为UTC
    • 校准时间服务器
  • 私有时间服务器设置
    • 时间服务器配置
    • 客户端同步
    • 查看现有的时间服务器
    • 查看时间服务器状态
    • ntpdate 客户端同步时间
    • 立即手动同步
    • 自用批处理命令

时间同步(同步阿里云时间服务器)

需求:
同步 阿里云时间服务器 ntp.aliyun.com

centos 安装

yun install chrony -y

ubuntu 安装

apt install chrony -y

ubuntu 下 查看安装软件后,该软件配置文件目录 用

whereis chrony

配置文件

主配置文件:/etc/chrony.conf
客户端程序:/usr/bin/chronyc
服务端程序:/usr/sbin/chronyd

监听的端口

123/udp:兼容ntp服务监听在udp的123端口上
323/udp:chrony服务本身监听在udp的323端口上

如果系统上已经有其他时间服务,那么先停止

systemctl stop ntpdate
systemctl disable ntpdate

防火墙设置

如果存在防火墙

Firewalld设置

firewall-cmd --add-service=ntp --permanent
firewall-cmd --reload

因NTP使用123/UDP端口协议,所以允许NTP服务即可。

iptables 防火墙设置

iptables -I INPUT -p udp --dport 123 -j ACCEPT
iptables -I INPUT -p udp --dport 223 -j ACCEPT
service iptables save

具体操作步骤

启动并加入开机自启动

#设置开机启动,并同时启动
systemctl enable chronyd.service --now
#重启
systemctl restart chronyd.service
#状态
systemctl status chronyd.service

查看当前系统时区:

timedatectl

输出

      Local time: 五 2022-01-21 10:59:48 CSTUniversal time: 五 2022-01-21 02:59:48 UTCRTC time: 六 2022-01-22 03:00:11Time zone: Asia/Shanghai (CST, +0800)NTP enabled: no
NTP synchronized: noRTC in local TZ: noDST active: n/a

查看上海时区

timedatectl list-timezones |  grep  -E "Asia/Shanghai"设置时区
timedatectl set-timezone Asia/Shanghai

配置阿里云时间服务器 ntp.aliyun.com

vim /etc/chrony.conf

内容,在 server 下添加

    ...server 0.centos.pool.ntp.org iburstserver 1.centos.pool.ntp.org iburstserver 2.centos.pool.ntp.org iburstserver 3.centos.pool.ntp.org iburstserver ntp.aliyun.com iburst...

重启服务

systemctl restart chronyd

设置启用NTP时间 自动同步

timedatectl set-ntp yes

手动同步系统时间

chronyc -a makestep

查看同步源

chronyc sources -v

同步源状态

chronyc sourcestats -v

设置硬件时间,硬件时间默认为UTC

如果你需要的可以设置

timedatectl set-local-rtc 1

校准时间服务器

chronyc tracking

私有时间服务器设置

需求:
1.192.168.50.138 这台服务器为时间服务器
2.其他服务器同步 192.168.50.138 这台时间服务器

时间服务器配置

vim /etc/chrony.conf

内容

    ...# 允许指定网络的主机同步时间,不指定就是允许所有,默认不开启。allow 192.168.50.0/24...#当外部时间服务器不可用时,采用本地时间作为同步标准local stratum 10

重启服务

systemctl restart chronyd

客户端同步

vim /etc/chrony.conf

如果只有一台服务作为时间标准,把默认 4个全部用#号注释
内容

    ...#server 0.centos.pool.ntp.org iburst#server 1.centos.pool.ntp.org iburst#server 2.centos.pool.ntp.org iburst#server 3.centos.pool.ntp.org iburstserver 192.168.50.138 iburst...

重启服务

systemctl restart chronyd

查看现有的时间服务器

chronyc sources

查看时间服务器状态

chronyc sourcestats

ntpdate 客户端同步时间

chrony兼容ntpdate,可以直接使用命令同步

ntpdate 192.168.50.138

立即手动同步

chronyc -a makestep

自用批处理命令

我的服务器使用的是 iptables 防火墙,默认是 ntpdate

sed -i 's/server/#server/g' /etc/chrony.conf \
&& systemctl stop ntpdate \
&& systemctl disable ntpdate \
&& iptables -I INPUT -p udp --dport 123 -j ACCEPT \
&& iptables -I INPUT -p udp --dport 223 -j ACCEPT \
&& systemctl enable chronyd.service --now \
&& systemctl status chronyd.service \
&& date

最后执行

service iptables save

linux 时间同步服务 chrony相关推荐

  1. 嵌入式Linux 时间同步 gpsd+chrony

    嵌入式Linux 时间同步 gpsd+chrony 嵌入式Linux系统,外接GPS设备,系统通过NMEA数据和pps进行时间同步,同时将本系统作为时间同步服务器. 一.基本原理 ​ NMEA中获取U ...

  2. linux时间同步服务z

    稳定的NTP时间同步服务器集群:ntp.api.bz[原创] 作者:张宴 来源: 回忆未来 发布时间:2009-11-05 23:07:46 浏览(881) 评论(0) 标签: ntp ntpd nt ...

  3. 时间同步服务 chrony

    关闭selinux [root@centos7 ~]#vim /etc/selinux/config SELINUX=disabled 关闭防火墙 [root@centos7 ~]#systemctl ...

  4. Linux时间同步:chrony

    linux7以上版本都自带chrony服务 如果没有安装,则使用yum安装,如果安装了,请忽略 yum -y install chrony 说明:Chrony由两个程序组成,分别是chronyd和ch ...

  5. linux 时钟同步命令,Linux 时间同步服务命令

    Linux服务器运行久时,系统时间就会存在一定的误差,一般情况下可以使用date命令进行时间设置,但 在做数据库集群分片等操作时对多台机器的时间差是有要求的,此时就需要使用ntpdate进行时间同步. ...

  6. linux设置服务器时间同步,linux时间同步服务设置方法

    方法1: 与一个已知的时间服务器同步 ntpdate time.nist.gov 其中 time.nist.gov 是一个时间服务器. 删除本地时间并设置时区为上海 rm -rf /etc/local ...

  7. Linux 时间同步 ntpdchrony 内网

    Linux 时间同步 ntpd&chrony 在任何服务器集群中,为了更好的协同工作,除了一些互信机制外,需要的就是时间同步功能,如果时间不同步,就好比让在中国的同事与美国的同事进行沟通,会造 ...

  8. Linux设备上时间不准确?使用chrony服务配置时间服务器实现Linux时间同步以及实现主从设备时间同步

    本文基于Linux上CentOS 7版本配合chrony(需要使用yum自行下载)进行演示 一.计算机设备上的两种时间 1.硬件时间 2.系统时间 二.配置同步时间服务器 1.安装服务 2.配置服务 ...

  9. Linux运维之认识与分析日志文件(rsyslog服务),时间同步服务(chronyd服务)及时间管理命令(timedatectl)

    一.实验环境(rhel7.0版本) 主机环境:rhel7.0 各主机信息 主机名 IP server 172.25.254.1 client 172.25.254.2 二.日志文件介绍 1.Linux ...

最新文章

  1. HDU 3709 Balanced Number
  2. sqlite插入时间字段_sqlite 获取最后插入id
  3. Visual Studio Code搭建NodeJs的开发环境
  4. [AHOI2004]实验基地 dp+枚举
  5. mysql函数 字符长度限制_MySQL中使用group_concat()函数数据字符过长报错的问题解决方法...
  6. Python零基础:第一个Python程序“hello world“ 背后的运行你懂了吗?
  7. 机器学习分支:active learning、incremental learning、online machine learning
  8. 《机器学习实战》原书数据与代码(基于Python3)汇总
  9. python手写识别系统gui_求大神帮助,怎么用wxpython编写一个数字手写体识别系统!...
  10. 系统运维工程师必备面试题库
  11. MTK6737平台的GPIO驱动例程(六)
  12. DCOS之Mesos-DNS介绍
  13. (2021 ICCV)Specificity-preserving RGB-D Saliency Detection(A类)
  14. Spring学习详细代码+图片解释笔记
  15. android 多语言的实现
  16. 软考信息系统项目管理师论进度管理范文
  17. 企业微信审批页面HTML,企业微信审批模板调用示例及注意事项
  18. Android获取网络图片的宽高
  19. matplotlib常用绘图操作
  20. SRT上传文件下载文件

热门文章

  1. 被315点名的流氓下载器,又回来了…
  2. 随机接入协议简介及发展方向思考
  3. 2068. 整数拼接
  4. 合作案例 | 慧通差旅助力中核集团,打造智能化差旅平台
  5. c语言笔试题目,C语言考试题库及答案2015.doc
  6. 苹果 iOS 应用 TestFlight 内测版下载地址汇总(8月16日更新)
  7. iOS 直播类APP开发流程解析
  8. Excel基础篇(三):vlookup根据A列查询B列
  9. 李群的伴随表示如何理解
  10. python是一种面向什么的高级语言