Linux?配置時(shí)間服務(wù)器的詳細(xì)過(guò)程
更新時(shí)間:2025年03月26日 09:41:48 作者:陣雨會(huì)停.
文章介紹了如何在Linux系統(tǒng)上配置時(shí)間服務(wù)器,包括同步阿里云服務(wù)器時(shí)間和服務(wù)端、客戶端的配置方法,以及在本地服務(wù)器上進(jìn)行時(shí)間同步的步驟,感興趣的朋友一起看看吧
一、同步阿里云服務(wù)器時(shí)間
服務(wù)端設(shè)置
1.檢查chrony服務(wù)是否安裝,設(shè)置chrony開(kāi)機(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ù)開(kāi)機(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 是一個(gè)關(guān)鍵字,作用是指定一組 NTP 服務(wù)器,iburst表示的是首次同步的時(shí)候快速同步 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為時(shí)間服務(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ù)器時(shí)間
服務(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è)置為一個(gè) NTP 時(shí)間源,并且將其 Stratum 層級(jí)設(shè)定為 10
2.修改 /etc/resolv.conf 文件,不使用dns解析,模擬無(wú)法上網(wǎng)的情況
[root@node1-server ~]# vim /etc/resolv.conf # Generated by NetworkManager #nameserver 223.5.5.5 # 注釋此行
3.修改錯(cuò)誤時(shí)間
[root@node1-server ~]# date -s '2021-12-13 14:54:58' # 修改時(shí)間是為了讓結(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)]有時(shí)間服務(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 # 時(shí)間與服務(wù)端同步成功
到此這篇關(guān)于Linux 配置時(shí)間服務(wù)器的文章就介紹到這了,更多相關(guān)Linux 時(shí)間服務(wù)器內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
VScode Remote SSH通過(guò)遠(yuǎn)程編輯與調(diào)試代碼
這篇文章主要介紹了VScode Remote SSH通過(guò)遠(yuǎn)程編輯與調(diào)試代碼,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05深入理解linux執(zhí)行文件提示No such file or directory的背后原因
這篇文章主要介紹了深入理解linux執(zhí)行文件提示No such file or directory的背后原因,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來(lái)一起學(xué)習(xí)學(xué)習(xí)吧2019-12-12Linux環(huán)境下使用glog日志庫(kù)的方法
今天小編就為大家分享一篇關(guān)于Linux環(huán)境下使用glog日志庫(kù)的方法,小編覺(jué)得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來(lái)看看吧2018-12-12Windows下 Apache PHP 環(huán)境搭建的方法
經(jīng)常在 Linux 環(huán)境下搭建 php 環(huán)境,在 windows 下還是第一次,沒(méi)啥技術(shù)含量,就是記錄一下,需要的朋友參考下本教程2017-01-01