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

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

相關推薦

  • RPM及YUM工具介紹及使用(下)

    YUM工具 YUM工作原理 YUM工具的出現就是為了解決rpm工具不能夠自動解決軟件包之間的依賴關系這一難題的。它的工作原理大致如下:YUM透過分析RPM的標頭資料,根據各軟件的相關性找出軟件所依賴的軟件列表,然后去下載速度最快的yum倉庫中下載所有相關RPM軟件包,然后完成相應軟件的安裝。同時yum工具和rpm工具一樣,也可以提供對軟件包的查詢,安裝、升級…

    Linux干貨 2016-12-26
  • N22第七周作業

    1.創建一個10G的分區,并格式為ext4的文件系統;     (1)要求其block大小為2048,預留空間百分比為2,卷標為MYDATA,默認掛載屬性包含acl; # fdisk /dev/sdb 歡迎使用 fdisk (util-linux 2.23.2)。 更改…

    Linux干貨 2016-10-24
  • Systemd服務

    POST –> Boot Sequence –> Bootloader –> kernel + initramfs(initrd) –> rootfs –> /sbin/initinit:CentOS 5: SysV initCentOS 6: UpstartCentO…

    Linux干貨 2015-03-02
  • 文件系統磁盤管理上

    磁盤:主要作用用于存儲數據 早期一塊硬盤共有256個盤面,每個盤面有1024個磁道,每個磁道有63個扇區,每個扇區的大小是512byte 硬盤的命名: 早期IDE硬盤標記為hd scsi、usb、sas標記為sd 引用設備的方式 設備文件名 標卷 UUID 硬盤分區: 第0個磁道的第0個扇區存放的是磁盤的信息 MBR:Master Boot Record 主…

    Linux干貨 2016-08-30
  • linux 基礎命令總結——文件類命令

    <span style="font-size: 18px;">linux 基礎命令總結——文件類命令</span> #wmd-preview h1  {    color: #0077bb; /* 將標題改為藍色 */} linux 基礎命令總結——文件類命令 命令總結 文件類命令 l…

    Linux干貨 2016-06-26
  • 馬哥教育網絡班21期+第9周課程練習

    1、寫一個腳本,判斷當前系統上所有用戶的shell是否為可登錄shell(即用戶的shell不是/sbin/nologin);分別這兩類用戶的個數;通過字符串比較來實現; #!/bin/bash while read line; do     if [[ $line&n…

    Linux干貨 2016-09-06
欧美性久久久久