Chrony时间同步

NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步的一种协议.它的用于是把计算机的时钟同步到世界协调时UTC,其精度在局域网内可达0.1ms,在网络网上绝大多数的地方其精度可以达到1-50ms.

1.chrony服务部署

//查看一下由哪个包提供的
[root@ntp-server ~]# yum provides chronyd
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
chrony-3.1-2.el7.x86_64 : An NTP client/server
Repo : dvd
Matched from:
Filename : /usr/sbin/chronyd //安装chrony服务
[root@ntp-server ~]# yum install chrony
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
dvd | 4.1 kB 00:00:00
Resolving Dependencies
--> Running transaction check
---> Package chrony.x86_64 0:3.1-2.el7 will be installed
--> Processing Dependency: libseccomp.so.2()(64bit) for package: chrony-3.1-2.el7.x86_64
--> Running transaction check
---> Package libseccomp.x86_64 0:2.3.1-3.el7 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================
Package Arch Version Repository Size
==========================================================================================
Installing:
chrony x86_64 3.1-2.el7 dvd 237 k
Installing for dependencies:
libseccomp x86_64 2.3.1-3.el7 dvd 56 k Transaction Summary
==========================================================================================
Install 1 Package (+1 Dependent package) Total download size: 293 k
Installed size: 761 k
Is this ok [y/d/N]: y
Downloading packages:
------------------------------------------------------------------------------------------
Total 1.6 MB/s | 293 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : libseccomp-2.3.1-3.el7.x86_64 1/2
Installing : chrony-3.1-2.el7.x86_64 2/2
Verifying : chrony-3.1-2.el7.x86_64 1/2
Verifying : libseccomp-2.3.1-3.el7.x86_64 2/2 Installed:
chrony.x86_64 0:3.1-2.el7 Dependency Installed:
libseccomp.x86_64 0:2.3.1-3.el7 Complete! //启动服务
[root@ntp-server ~]# systemctl start chrony
chrony-dnssrv@ chronyd.service chrony-wait.service
[root@ntp-server ~]# systemctl start chronyd

chrony服务相关命令

参数 解释
list-timezones 列出可用时区信息
set-timezone 设置时区
set-ntp 启用NTP
status 查看状态
[root@ntp-server ~]# timedatectl
Local time: Tue 2018-08-21 14:02:35 CST
Universal time: Tue 2018-08-21 06:02:35 UTC
RTC time: Tue 2018-08-21 06:02:33
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@ntp-server ~]# timedatectl
list-timezones set-ntp set-timezone
set-local-rtc set-time status
[root@ntp-server ~]# timedatectl list-timezones | grep -i shanghai
Asia/Shanghai //关闭NTP
[root@ntp-server ~]# timedatectl set-ntp false
[root@ntp-server ~]# timedatectl
Local time: Tue 2018-08-21 14:15:36 CST
Universal time: Tue 2018-08-21 06:15:36 UTC
RTC time: Tue 2018-08-21 06:15:36
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a //启用NTP
[root@ntp-server ~]# timedatectl set-ntp true
[root@ntp-server ~]# timedatectl
Local time: Tue 2018-08-21 14:16:02 CST
Universal time: Tue 2018-08-21 06:16:02 UTC
RTC time: Tue 2018-08-21 06:16:02
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: no
DST active: n/a //查看一下ntpdate由哪个包提供的
[root@ntp-server ~]# yum provides ntpdate
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
ntpdate-4.2.6p5-25.el7_3.2.x86_64 : Utility to set the date and time via NTP
Repo : dvd //如果没有请安装ntpdate
[root@ntp-server ~]# yum install ntpdate.x86_64
Loaded plugins: product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Resolving Dependencies
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-25.el7_3.2 will be installed
--> Finished Dependency Resolution Dependencies Resolved ==========================================================================================
Package Arch Version Repository Size
==========================================================================================
Installing:
ntpdate x86_64 4.2.6p5-25.el7_3.2 dvd 86 k Transaction Summary
==========================================================================================
Install 1 Package Total download size: 86 k
Installed size: 121 k
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : ntpdate-4.2.6p5-25.el7_3.2.x86_64 1/1
Verifying : ntpdate-4.2.6p5-25.el7_3.2.x86_64 1/1 Installed:
ntpdate.x86_64 0:4.2.6p5-25.el7_3.2 Complete!

2.配置时间同步服务器

[root@ntp-server ~]# vim /etc/chrony.conf
server ntp1.aliyun.com iburst
server ntp2.aliyun.com iburst
server ntp3.aliyun.com iburst
server ntp4.aliyun.com iburst
server ntp5.aliyun.com iburst
server ntp6.aliyun.com iburst
server ntp7.aliyun.com iburst allow 172.16.10.0/24 //验证服务端是否能同步时间
[root@ntp-server ~]# chronyc sources -v
210 Number of sources = 1 .-- Source mode '^' = server, '=' = peer, '#' = local clock.
/ .- Source state '*' = current synced, '+' = combined , '-' = not combined,
| / '?' = unreachable, 'x' = time may be in error, '~' = time too variable.
|| .- xxxx [ yyyy ] +/- zzzz
|| Reachability register (octal) -. | xxxx = adjusted offset,
|| Log2(Polling interval) --. | | yyyy = measured offset,
|| \ | | zzzz = estimated error.
|| | | \
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 120.25.115.20 2 6 17 22 -117us[ -948us] +/- 24ms //看一下服务器时间
[root@ntp-server ~]# date
Tue Aug 21 15:31:29 CST 2018 //看一下客户端时间 时间不对需要同步
[root@ntp-client ~]# date
Fri Aug 20 14:10:28 CST 2010 //ntp服务器地址
ens35: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 172.16.10.20 netmask 255.255.255.0 broadcast 172.16.10.255
inet6 fe80::da6c:394e:1ef7:c236 prefixlen 64 scopeid 0x20<link>
ether 00:0c:29:6e:66:65 txqueuelen 1000 (Ethernet)
RX packets 6 bytes 480 (480.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 21 bytes 1614 (1.5 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0 //客户端同步,时间已经同步正确
[root@ntp-client ~]# ntpdate 172.16.10.20
21 Aug 15:35:10 ntpdate[2421]: step time server 172.16.10.20 offset 252552056.617240 sec
You have new mail in /var/spool/mail/root
[root@ntp-client ~]# date
Tue Aug 21 15:35:15 CST 2018 //第一种方式设置定时任务
[root@ntp-client ~]# which ntpdate
/usr/sbin/ntpdate
[root@ntp-client ~]# crontab -e
*/2 * * * * /usr/sbin/ntpdate 172.16.10.20 &>/dev/null //第二种方式客户端编辑配置文件服务器指向172.168.10.20
[root@ntp-client ~]# vim /etc/chrony.conf
server 172.16.10.20 iburst //启动服务查看服务运行状态
[root@ntp-client ~]# systemctl restart chronyd
[root@ntp-client ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Tue 2018-08-21 15:52:11 CST; 6s ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Process: 3012 ExecStartPost=/usr/libexec/chrony-helper update-daemon (code=exited, status=0/SUCCESS)
Process: 3009 ExecStart=/usr/sbin/chronyd $OPTIONS (code=exited, status=0/SUCCESS)
Main PID: 3011 (chronyd)
Tasks: 1
CGroup: /system.slice/chronyd.service
└─3011 /usr/sbin/chronyd Aug 21 15:52:10 ntp-client systemd[1]: Starting NTP client/server...
Aug 21 15:52:11 ntp-client chronyd[3011]: chronyd version 3.2 starting (+CMDMON +NTP ...G)
Aug 21 15:52:11 ntp-client chronyd[3011]: Frequency -37.840 +/- 1000000.000 ppm read ...ft
Aug 21 15:52:11 ntp-client systemd[1]: Started NTP client/server.
Aug 21 15:52:15 ntp-client chronyd[3011]: Selected source 172.16.10.20
Hint: Some lines were ellipsized, use -l to show in full. //差不多一分钟同步了
[root@ntp-client ~]# date
Tue Aug 10 08:32:32 CST 2010
[root@ntp-client ~]# date
Tue Aug 10 08:32:33 CST 2010
[root@ntp-client ~]# date
Tue Aug 21 16:04:24 CST 2018
[root@ntp-client ~]# date
Tue Aug 21 16:04:25 CST 2018

Linux基础学习-chrony时间同步服务的更多相关文章

  1. Linux基础学习-使用iSCSI服务部署网络存储

    使用iSCSI服务部署网络存储 iSCSI技术实现了物理硬盘设备与TCP/IP网络协议的相互结合,使得用户可以通过互联网方便地访问远程机房提供的共享存储资源.下面介绍如何在Linux上部署iSCSI服 ...

  2. Linux基础学习-Samba文件共享服务

    使用Samba文件共享服务 Samba起源: 早期网络想要在不同主机之间共享文件大多要用FTP协议来传输,但FTP协议仅能做到传输文件却不能直接修改对方主机的资料数据,这样确实不太方便,于是便出现了N ...

  3. Linux基础学习-使用vsftpd服务传输文件

    使用vsftpd服务传输文件 1 安装vsftpd [root@qdlinux ~]# yum install vsftpd Loaded plugins: product-id, search-di ...

  4. Linux基础学习系列目录导航

    Linux基础学习-通过VM安装RHEL7.4 Linux基础学习-命令行与图形界面切换 Linux基础学习-基本命令 Linux基础学习-RHEL7.4之YUM更换CentOS源 Linux基础学习 ...

  5. Linux 基础学习2

    目录 Linux 基础学习2 文件目录结构 文件命名规范 文件系统结构 linux应用程序的组成 绝对路径和相对路径 目录名和基名 切换目录 切换到家目录 切换到上一次的目录 显示当前的工作目录 列出 ...

  6. chrony时间同步 服务端 客户端 安装配置

    chrony时间同步 服务端 客户端 安装配置 原创内容http://www.cnblogs.com/elvi/p/7658021.html #!/bin/sh #运行环境 centos7 #chro ...

  7. linux基础学习之软件安装以及常用命令

    linux基础学习之软件安装以及常用命令 调用中央仓库: yum install wget 然后下载nodejs: wget https://nodejs.org/dist/v10.14.2/node ...

  8. linux基础学习路线&review

    linux基础学习网址: https://www.runoob.com/linux/linux-tutorial.html 比较重点的是这个启动过程的介绍学习:https://www.runoob.c ...

  9. Linux 基础学习1

    目录 Linux 基础学习 用户登录 终端 交互式接口 bash 修改ssh连接慢的步骤 命令提示符 显示提示符格式 命令 别名 命令格式 获取命令的帮助信息 man bash 快捷键 tab 键 引 ...

随机推荐

  1. Shiro 权限管理框架

    一.什么是Shiro Apache Shiro是一个强大易用的java安全框架,提供认证.授权.加密和会话管理等功能 · 认证:用户身份识别,俗称“登录”: · 授权:访问控制 · 密码加密:保护或隐 ...

  2. Ubuntu终端查看系统时间,以及日历

    时间:  date 日历: cal https://blog.csdn.net/zhengchaooo/article/details/79500032 修改时区以及时间 查看时区 date -R 修 ...

  3. VLAN-6-VLAN Trunk协议(VTP)

    VTP能够将VLAN配置信息通告给邻居交换机,这样做可以使工程师只在一台交换机上配置VLAN,同一个VTP域中的所有其他交换机动态学习这些VLAN信息.VTP通告VLAN ID.VLAN 名称和 VL ...

  4. [題解]luogu_P1144最短路計數

    1.無權圖最短路邊權為1 2.如果兩個點恰好不能被更新(d[y]==d[x]+1)那麼就能通過x的所有最短路到達y,所以ans[y]+=ans[x] 3.如果兩個點不能恰好被更新(d[y]>d[ ...

  5. 统计最长回文串(传说中的Manacher算法)Hihocoder 1032

    算法的核心就在这一句上了:p[i] = min(p[2*id-i], p[id] + id - i); #include <iostream> #include <cstdio> ...

  6. python 基础(十四) 正则表达式

    正则表达式 概念: 正则匹配就是一个模糊的匹配 只要符合我的匹配规则 就会认为是正确的数据(精确的匹配) 1.[] #代表原子表把想要匹配的内容写入原子表中   匹配包含的任意一位字符 [a]     ...

  7. [coci2015-2016 coii] torrent【树形dp 二分】

    传送门:http://www.hsin.hr/coci/archive/2015_2016/ 进去之后点最下面那个. 这道题没有想出来,可惜了,其实不难的. 题目是两个“源”的,我们先考虑单源的问题. ...

  8. G. Of Zorcs and Axes 二分 + 贪心 —— STL的用法

    http://codeforces.com/gym/101149/problem/G 一开始还以为要用二分图去做,但是复杂度也太高了,O(n * m)的话直接爆炸. 考虑贪心,考虑第i个东西优先选一个 ...

  9. react 父子传值

    import React from 'react'; import ReactDOM from 'react-dom'; import $ from 'jquery'; //var $ = requi ...

  10. 利用nodejs读取数据库数据生成树结构的json数据

    在做后台管理界面的时候,几乎少不了的一个结构就是树形结构,用来做菜单导航: 那么,最希望的就是树结构的所有数据都是读取的数据库,而不是直接代码当中写死,那我们就一步一步来看: 一,建表 字段通常包括: ...