Chrony

RHEL7.4 192.168.100.1 作为时间服务器,其它主机到这台来同步时间。

时间服务器安装及配置:
#yum install chrony –RHEL7默认已安装chrony,而没有安装ntpd.

#systemctl status chronyd –查看chronyd服务状态
#systemctl enable chronyd –开机启动

#vi /etc/chrony.conf    –修改配置文件

#server 0.rhel.pool.ntp.org iburst   –注释这4行,由于是内网环境,所以无法跟外部时间服务器进行时间同步。
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst    –添加这一行,表示与本机同步时间local stratum 10    –该行取消注释

# Allow NTP client access from local network.
allow 192.168.100.0/24   –允许哪些服务器到这台服务器来同步时间

#systemctl restart chronyd –修改完配置文件后,重启chronyd服务

[root@rhel1 ~]# netstat -antulp | grep chronyd
udp        0      0 0.0.0.0:123             0.0.0.0:*                           705/chronyd
udp        0      0 127.0.0.1:323           0.0.0.0:*                           705/chronyd
udp6       0      0 ::1:323                 :::*                                705/chronyd

1.显示系统的当前时间和日期

timedatectl
# timedatectl status
# 两条命令效果等同

[root@rhel1 ~]# timedatectl
Local time: Sat 2017-10-07 10:55:22 CST
Universal time: Sat 2017-10-07 02:55:22 UTC
RTC time: Sat 2017-10-07 02:55:22
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a

注意NTP synchronized值,只有时间服务器自己同步完成时间之后,才能为其它服务器提供时间同步服务。
2.设置日期与时间

timedatectl set-time “YYYY-MM-DD HH:MM:SS”
timedatectl set-time “YYYY-MM-DD”
timedatectl set-time “HH:MM:SS”
3.查看所有可用的时区

timedatectl list-timezones
# 亚洲
timedatectl list-timezones |  grep  -E “Asia/S.*”
4.设置时区

timedatectl set-timezone Asia/Shanghai
5.设置硬件时间

# 硬件时间默认为UTC
timedatectl set-local-rtc 1
# hwclock –systohc –localtime
# 两条命令效果等同

6.启用NTP时间同步
timedatectl set-ntp yes
# yes或no; 1或0也可以

问题:不明白这里启用ntp时间同步有啥意义。难道是说可以在时间服务器上都安装chronyd和ntpd服务来同时提供时间服务吗????如果设置为yes,手动设置时间则报错。看本文结尾。

7、查看时间源信息

[root@rhel1 ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address         Stratum Poll Reach LastRx Last sample
===============================================================================
^* rhel1.rusky.com              10   7   377   22m  -3603ns[  -19us] +/-   32us
[root@rhel1 ~]# 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
===============================================================================
^* rhel1.rusky.com              10   7   377   22m  -3603ns[  -19us] +/-   32us
[root@rhel1 ~]#

客户端时间同步配置:

1.yum install chrony –y

2.修改配置文件

[root@rhel2 ~]# vi /etc/chrony.conf
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
#server 0.rhel.pool.ntp.org iburst  –注释这4行
#server 1.rhel.pool.ntp.org iburst
#server 2.rhel.pool.ntp.org iburst
#server 3.rhel.pool.ntp.org iburst
server 192.168.100.1 iburst    —添加该行,表示到这台服务器去同步时间。

3.重启chronyd并设置开机启动

[root@rhel2 ~]# systemctl restart chronyd.service
[root@rhel2 ~]# systemctl enable chronyd.service

4. 查看时间同步状态

[root@rhel2 ~]# timedatectl
Local time: Sat 2017-10-07 11:15:43 CST
Universal time: Sat 2017-10-07 03:15:43 UTC
RTC time: Sat 2017-10-07 03:02:26
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: yes   –为yes表示已同步
RTC in local TZ: no
DST active: n/a

重启chronyd服务后,需要过几分钟才会自动完成同步。

如果需要手动,可使用下面的命令:

#ntpdate 192.168.100.1   如果同步失败,则可能 是服务端的时间未同步。即服务端NTP synchronized 为no。

============================

手动修改时间时,必须把NTP enabled 设置为no.

[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017
[root@rhel1 ~]# timedatectl
Local time: Sat 2017-10-07 11:31:45 CST
Universal time: Sat 2017-10-07 03:31:45 UTC
RTC time: Sun 2017-10-08 03:01:57
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: no
NTP synchronized: no
RTC in local TZ: no
DST active: n/a

如果把NTP enabled 修改为yes时,表示开启自动同步时间,此时,是不能手动修改时间的。

如果为No时,表示关闭自动同步时间。

[root@rhel1 ~]# timedatectl set-ntp yes
[root@rhel1 ~]# timedatectl set-time “2017-10-08 11:00:50”
Failed to set time: Automatic time synchronization is enabled
[root@rhel1 ~]# timedatectl set-ntp no
[root@rhel1 ~]# timedatectl set-time “2017-10-08 11:00:50”
[root@rhel1 ~]# date
Sun Oct  8 11:00:51 CST 2017

 

本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/90867

(1)
上一篇 2018-01-06 00:39
下一篇 2018-01-07 15:15

相关推荐

  • 高效运维最佳实践(03):Redis集群技术及Codis实践

    前言 诚如开篇文章所言,高效运维包括管理的专业化和技术的专业化。前两篇我们主要在说些管理相关的内容,本篇说一下技术专业化。希望读者朋友们能适应这个转换,谢谢。 互联网早在几年前就已进入Web 2.0时代,对后台支撑能力的要求,提高了几十倍甚至几百倍。在这个演化过程中,缓存系统扮演了举足轻重的角色。 运维进化到今天,已经不是重复造轮子的时代。所以,我们在架构优…

    Linux干货 2015-04-03
  • CentOS6.8编译安装—- php-fpm

    安装环境: [root@station11 ~]# lsb_release -a Distributor ID: CentOS Description:     CentOS release 6.8 (Final) Release:  6.8 Codename:    …

    Linux干货 2016-12-21
  • 数据结构应用详解-

    概述 最小生成树——无向连通图的所有生成树中有一棵边的权值总和最小的生成树 拓扑排序 ——由偏序定义得到拓扑有序的操作便是拓扑排序。建立模型是AOV网 关键路径——在AOE-网中有些活动可以并行地进行,所以完成工程的最短时间是从开始点到完成点的最长路径的长度,路径长度最长的路径叫做关键路径(Critical Path)。 最短路径——最短路径问题是…

    Linux干货 2015-04-07
  • iptables之froward

    先克隆一台centos服务器添加虚拟网卡 同时两个服务器配上host only的网卡 echo 1 > /proc/sys/net/ipv4/ip_forward打开网卡间转发 有回包 但是没有10.0.0.3还是没有ping通原因是192.168.68.134 的网关指向了192.168.68.2 而不是192.168.68.144添加一条指向192…

    2017-11-12
  • lamp部署及编译安装

    lamp 资源类型: 静态资源:原始形式与响应给客户端的结果一致; 动态资源:原始形式通常为程序文件(为某种编程语言开发),需要运行后将生成的结果展示给客户端;如果请求的资源不存在那么结果就会重定向至指定的文件中 客户端技术:javascript 服务端技术:php, jsp, … CGI:Common Gateway Interfa…

    Linux干货 2016-10-19
  • 3.26第一篇博客

    1.安装VNC viewer (VNC是一款远程控制软件,即便版本不一样也可以互通) 安装好后,进入界面,可以直接在上方数据栏里输入服务器端的主机名或IP地址,即可建立连接。 二.安装VMware (VMware是一款可以控制和管理虚拟化的IT环境 可以跑各种的操作系统) 1.首先在内网ftp://172.16.0.1/pub/tools找到VMware版本…

    2018-03-26