centos7 時間同步和時區設置
首先centos7的時間同步是使用chrony這個工具(
[root@localhost ~]# systemctl status chrony
● chrony.service
Loaded: not-found (Reason: No such file or directory)
Active: inactive (dead)
1.安裝chrony
[root@localhost ~]# yum -y install chrony
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
2.啓動chrony
[root@localhost ~]# systemctl start chronyd
[root@localhost ~]# systemctl status chronyd
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; vendor preset: enabled)
Active: active (running) since Mon 2016-10-24 17:52:52 CST; 3h 35min ago
Main PID: 807 (chronyd)
CGroup: /system.slice/chronyd.service
└─807 /usr/sbin/chronyd
Oct 24 17:52:44 localhost.localdomain systemd[1]: Starting NTP client/server...
Oct 24 17:52:44 localhost.localdomain chronyd[807]: chronyd version 2.1.1 sta...
Oct 24 17:52:45 localhost.localdomain chronyd[807]: Frequency -10.892 +/- 15....
Oct 24 17:52:52 localhost.localdomain systemd[1]: Started NTP client/server.
Oct 24 17:53:49 localhost.localdomain chronyd[807]: Forward time jump detected!
Oct 24 17:53:55 localhost.localdomain chronyd[807]: Selected source 202.118.1.81
Oct 24 17:53:55 localhost.localdomain chronyd[807]: System clock wrong by -45...
Oct 24 17:53:09 localhost.localdomain chronyd[807]: System clock was stepped ...
Oct 24 21:27:55 localhost.localdomain systemd[1]: Started NTP client/server.
Hint: Some lines were ellipsized, use -l to show in full.
等等。。先看一下本機的時間(localhost)
[root@localhost ~]# timedatectl
Local time: Mon 2016-10-24 21:30:33 CST
Universal time: Mon 2016-10-24 13:30:33 UTC
RTC time: Mon 2016-10-24 13:30:32
Time zone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: no
DST active: n/a
在設置一下另一臺主機的時間(recehost)(錯誤的時間)[root@recvhost ~]# timedatectl set-time "2018-11-11 11:11:11"
[root@recvhost ~]# timedatectl
Local time: Sun 2018-11-11 11:11:17 CST
Universal time: Sun 2018-11-11 03:11:17 UTC
RTC time: Sun 2018-11-11 11:11:18
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: no
RTC in local TZ: yes
DST active: n/a
好了,開始配置文件了(注意:現在是服務器端的修改)
22 allow 192.168.1.0/24
23
24 # Listen for commands only on localhost.
25 bindcmdaddress 127.0.0.1
26 bindcmdaddress ::1
27
28 # Serve time even if not synchronized to any NTP server.
29 local stratum 10
第22行設置爲本網段第29行的註釋取消
重啓時間同步服務,再關閉防火牆
[root@localhost ~]# vim /etc/chrony.conf
[root@localhost ~]# systemctl restart chronyd.service
[root@localhost ~]# systemctl stop firewalld.service
這下配置客戶端的配置文件是同一個文件(/etc/chrony.conf)
刪掉哪些沒用的server xxxxxxxxxx iburst
1 # Use public servers from the pool.ntp.org project.
2 # Please consider joining the pool (http://www.pool.ntp.org/j oin.html).
3 server 192.168.1.192 iburst
4 # Ignore stratum in source selection.
同樣需要重啓同步服務,關閉防火牆
[root@recvhost ~]# systemctl restart chronyd.service
[root@recvhost ~]# systemctl stop firewalld.service
使用下面的命令就可以查看同步情況
[root@recvhost ~]# 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
|| / xxxx = adjusted offset,
|| Log2(Polling interval) -. | yyyy = measured offset,
|| \ | zzzz = estimated error.
|| | |
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* 192.168.1.192 3 6 37 29 -1430ns[+7000ns] +/- 15ms
下來再看時間
[root@recvhost ~]# timedatectl
Local time: Mon 2016-10-24 21:47:23 CST
Universal time: Mon 2016-10-24 13:47:23 UTC
RTC time: Mon 2016-10-24 21:47:24
Timezone: Asia/Shanghai (CST, +0800)
NTP enabled: yes
NTP synchronized: yes
RTC in local TZ: yes
DST active: n/a
timedatectl status 顯示當前時間信息
set-time 設定當前時間
set-timezone 設定當前時區
set-local-rtc 設定bios時間
set-time 設定當前時間
set-timezone 設定當前時區
set-local-rtc 設定bios時間