Linux?配置時間服務(wù)器的詳細(xì)過程
更新時間:2025年03月26日 09:41:48 作者:陣雨會停.
文章介紹了如何在Linux系統(tǒng)上配置時間服務(wù)器,包括同步阿里云服務(wù)器時間和服務(wù)端、客戶端的配置方法,以及在本地服務(wù)器上進(jìn)行時間同步的步驟,感興趣的朋友一起看看吧
一、同步阿里云服務(wù)器時間
服務(wù)端設(shè)置
1.檢查chrony服務(wù)是否安裝,設(shè)置chrony開機(jī)自啟,查看chrony服務(wù)狀態(tài)
[root@node1-server ~]# rpm -q chrony # rpm -q 用于查看包是否安裝
chrony-4.3-1.el9.x86_64
[root@node1-server ~]# systemctl enable --now chronyd # 設(shè)置服務(wù)開機(jī)自啟
[root@node1-server ~]# systemctl status chronyd # 查看chronyd服務(wù)狀態(tài)
● chronyd.service - NTP client/server
Loaded: loaded (/usr/lib/systemd/system/chronyd.service; enabled; preset: enabled)
Active: active (running) since Tue 2025-03-25 14:11:34 CST; 2h 22min ago
Docs: man:chronyd(8)
man:chrony.conf(5)
Main PID: 905 (chronyd)
Tasks: 1 (limit: 10681)
Memory: 4.0M
CPU: 80ms
CGroup: /system.slice/chronyd.service
└─905 /usr/sbin/chronyd -F 2
2.關(guān)閉防火墻,SELinux設(shè)置為寬容模式,查看防火墻狀態(tài)
[root@node1-server ~]# systemctl stop firewalld && systemctl disable firewalld # 關(guān)閉防火墻服務(wù),關(guān)閉成功后禁用服務(wù)
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@node1-server ~]# setenforce 0 # SELinux 調(diào)整為寬容模式
[root@node1-server ~]# getenforce # 查看 SELinux 狀態(tài)
Permissive # 寬容模式
[root@node1-server ~]# systemctl status firewalld.service # 查看防火墻狀態(tài)
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
3.編輯服務(wù)端/etc/chrony.conf文件
[root@node1-server ~]# vim /etc/chrony.conf 3 #pool 2.rhel.pool.ntp.org iburst # 注釋此行 4 pool ntp.aliyun.com iburst # pool 是一個關(guān)鍵字,作用是指定一組 NTP 服務(wù)器,iburst表示的是首次同步的時候快速同步 27 #allow 192.168.0.0/16 # 注釋此行 28 allow 192.168.11.0/24 # 允許同步該網(wǎng)段

4.重啟服務(wù),查看服務(wù),查看日期
[root@node1-server ~]# systemctl restart chronyd # 重啟服務(wù) [root@node1-server ~]# chronyc sources -v # 查看服務(wù) .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- 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 ========================================================================= ^* 203.107.6.88 2 6 17 25 +20ms[ +30ms] +/- 72ms [root@node1-server ~]# date # 查看日期 Tue Mar 25 04:54:42 PM CST 2025 # 與阿里云服務(wù)器同步成功

客戶端設(shè)置
1.關(guān)閉防火墻并查看防火墻狀態(tài)
[root@node2-client ~]# systemctl stop firewalld.service && systemctl disable firewalld.service #關(guān)閉防火墻
Removed "/etc/systemd/system/multi-user.target.wants/firewalld.service".
Removed "/etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service".
[root@node2-client ~]# systemctl status firewalld.service #查看防火墻狀態(tài)
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
2.編輯客戶端配置文件
[root@node2-client ~]# vim /etc/chrony.conf 3 #pool 2.rhel.pool.ntp.org iburst 4 pool 192.168.11.135 iburst # 以192.168.11.135為時間服務(wù)器

3.客戶端重啟服務(wù),查看服務(wù),查看日期
[root@node2-client ~]# systemctl restart chronyd # 重啟服務(wù) [root@node2-client ~]# chronyc sources -v # 查看服務(wù) .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- 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 ========================================================================= ^* 192.168.11.135 3 6 17 8 +30us[ +80us] +/- 54ms [root@node2-client ~]# date # 查看日期 Tue Mar 25 04:59:27 PM CST 2025 #與服務(wù)端同步成功

二、同步本地服務(wù)器時間
服務(wù)端配置
1.修改服務(wù)端配置文件
[root@node1-server ~]# vim /etc/chrony.conf 30 # Serve time even if not synchronized to a time source. 31 local stratum 10 # 把本地系統(tǒng)設(shè)置為一個 NTP 時間源,并且將其 Stratum 層級設(shè)定為 10

2.修改 /etc/resolv.conf 文件,不使用dns解析,模擬無法上網(wǎng)的情況
[root@node1-server ~]# vim /etc/resolv.conf # Generated by NetworkManager #nameserver 223.5.5.5 # 注釋此行

3.修改錯誤時間
[root@node1-server ~]# date -s '2021-12-13 14:54:58' # 修改時間是為了讓結(jié)果更明顯 Mon Dec 13 02:54:58 PM CST 2021

4.重啟服務(wù),查看服務(wù),查看日期
[root@node1-server ~]# systemctl restart chronyd [root@node1-server ~]# chronyc sources -v .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- 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 ========================================================================= [root@node1-server ~]# # 此處能看到?jīng)]有時間服務(wù)器與本機(jī)同步 [root@node1-server ~]# date Mon Dec 13 02:56:42 PM CST 2021

客戶端配置 僅需客戶端重啟服務(wù),查看服務(wù),查看日期
[root@node2-client ~]# systemctl restart chronyd [root@node2-client ~]# chronyc sources -v .-- Source mode '^' = server, '=' = peer, '#' = local clock. / .- Source state '*' = current best, '+' = combined, '-' = not combined, | / 'x' = may be in error, '~' = too variable, '?' = unusable. || .- 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 ========================================================================= ^* 192.168.11.135 10 6 17 8 +7530ns[+8920ns] +/- 150us [root@node2-client ~]# date Mon Dec 13 02:58:41 PM CST 2021 # 時間與服務(wù)端同步成功

到此這篇關(guān)于Linux 配置時間服務(wù)器的文章就介紹到這了,更多相關(guān)Linux 時間服務(wù)器內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
centOS7 下利用iptables配置IP地址白名單的方法
下面小編就為大家?guī)硪黄猚entOS7 下利用iptables配置IP地址白名單的方法。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-11-11
在Linux x64系統(tǒng)開發(fā)一個完整的Qt GUI文字識別應(yīng)用
本文介紹了如何在Linux x64系統(tǒng)上使用C++開發(fā)一個完整的QtGUI文字識別應(yīng)用,該應(yīng)用集成了百度飛槳的PP-OCRv5 server模型,具備圖片上傳、OCR識別、結(jié)果展示、剪貼板操作等功能,需要的朋友可以參考下2026-03-03
apache2.2和php5.2.17在windows下整合過程的錯誤解決方法
照理來說apache和php的整合應(yīng)該是非常簡單的,apache下載windows安裝版本后一路next即可完成安裝,php下載解壓版本后直接解壓到指定目錄,然后在apache的配置文件httpd.conf的最后加入如下幾行即可2011-08-08
Linux兩個服務(wù)器實(shí)現(xiàn)數(shù)據(jù)同步方案
這篇文章主要介紹了Linux兩個服務(wù)器實(shí)現(xiàn)數(shù)據(jù)同步方案,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-07-07
Linux進(jìn)程CPU綁定優(yōu)化與實(shí)踐過程
Linux支持進(jìn)程綁定至特定CPU核心,通過sched_setaffinity系統(tǒng)調(diào)用和taskset工具實(shí)現(xiàn),優(yōu)化緩存效率與上下文切換,提升多核計算性能,適用于實(shí)時系統(tǒng)、負(fù)載均衡及高性能計算場景2025-07-07

