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,手動設置時間則報錯??幢疚慕Y尾。

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.www58058.com/90867

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

相關推薦

  • LVS產生背景、原理及LVS-DR應用實例(二)

    六、LVS-DR應用實例          (一)基本構建思路:           Director: 通過Director實現訪問調度到RS1,RS2,實現負載均衡,RS3負責動態分離?!?/p>

    Linux干貨 2016-10-29
  • 馬哥教育網絡班22期第6周課程作業

    請詳細總結vim編輯器的使用并完成以下練習題 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; %s@^[[:space:]]\+@# 2、復制/boot/grub/grub.conf至/tmp目錄中,刪除/tmp/grub.conf文件中的行首的空白字符; %…

    Linux干貨 2016-12-05
  • Linux終端類型

    Linux系統的終端主要包括控制臺終端、控制終端、串口終端、偽終端、虛擬終端。 1、控制臺終端(/dev/console)    在Unix系統中,計算機顯示器通常被稱為控制臺終端。Console與虛擬終端相關聯,內核將信息送到控制臺終端上(/dev/console), 通過與console相關聯的虛擬終端將信息顯示到屏幕上。不管當前正在…

    Linux干貨 2016-10-19
  • Centos6.8 搭建LAMP平臺

    Centos6.8 搭建LAMP平臺 §·運行環境介紹 LAMP的運行環境介紹: L代表: Linux  Centos 6.8 A代表: apache  httpd-2.2.15-53.el6.centos.x86_64 M代表:MySQL  mysql-server-5.1.73-7.el6.x86_64 P代表: php &…

    Linux干貨 2016-10-12
  • Linux系統啟動流程簡介

    centos系統啟動流程 本篇僅僅講解centos5和6 centos7并不適用 Linux系統的組成部分:內核+根文件系統 內核功能: 進程管理 內存管理 網絡管理 驅動程序 文件系統 安全功能 有以下目錄結構的文件系統可以被識別為根文件系統,但根文件系統本身不存在 rootfs:/bin/ /sbin /etc/ /sys/…

    Linux干貨 2016-09-10
  • 推薦-tree命令的安裝和使用

    一、前言     tree命令是可以把指定文件夾的所以文件用樹狀羅列出來,呈現目錄形式的一個命令。在Centos 6.5中默認不能直接使用: 輸入type tree命令(type COMMAND:區別是內建命令還是外部命令)提示不存在: 二、安裝       …

    系統運維 2016-03-27
欧美性久久久久