使用阿里雲映象站NTP服務搭建NTP伺服器(基於CentOS 7系統)
一、NTP伺服器介紹
網路時間協議(Network Time Protocol,NTP)伺服器,也就是日常所說的NTP伺服器,用來提供同步時間服務。在生產環境中,很多人都會忽略時間問題,實際上伺服器、網路裝置等,特別是Linux作業系統和虛擬化平臺的時間不同步會導致很多問題。那麼搭建一臺NTP伺服器就非常重要,生產環境中的裝置可以直接與NTP伺服器進行時間同步,NTP伺服器本身也可以訪問互連的NTP伺服器進行同步。NTP伺服器可以是物理伺服器,也可以是虛擬機器。
二、安裝NTP服務元件
在Linux伺服器(如,CentOS、Ubuntu等作業系統)上,使用命令進行安裝。
本實驗以CentOS 7 Linux環境進行演示操作記錄。
YUM源已更新成阿里雲開源映象站裡的CentOS映象,加速快捷訪問。
[root@ntp ~]# yum clean allLoaded plugins: fastestmirror Cleaning repos: base extras updates Cleaning up list of fastest mirrors [root@ntp ~]# yum repolistLoaded plugins: fastestmirror Determining fastest mirrors * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com base | 3.6 kB 00:00:00 extras | 2.9 kB 00:00:00 updates | 2.9 kB 00:00:00 (1/4): base/7/x86_64/group_gz | 153 kB 00:00:00 (2/4): extras/7/x86_64/primary_db | 243 kB 00:00:00 (3/4): updates/7/x86_64/primary_db | 12 MB 00:00:01 (4/4): base/7/x86_64/primary_db | 6.1 MB 00:00:03 repo id repo name status base/7/x86_64 CentOS-7 - Base - mirrors.aliyun.com 10,072 extras/7/x86_64 CentOS-7 - Extras - mirrors.aliyun.com 500 updates/7/x86_64 CentOS-7 - Updates - mirrors.aliyun.com 2,963 repolist: 13,535 [root@ntp ~]#
執行
yum install -y ntp
命令,進行ntp元件安裝。
[root@ntp ~]# yum install -y ntpLoaded plugins: fastestmirror Loading mirror speeds from cached hostfile * base: mirrors.aliyun.com * extras: mirrors.aliyun.com * updates: mirrors.aliyun.com Resolving Dependencies --> Running transaction check ---> Package ntp.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed --> Processing Dependency: ntpdate = 4.2.6p5-29.el7.centos.2 for package: ntp-4.2.6p5-29.el7.centos.2.x86_64 --> Processing Dependency: libopts.so.25()(64bit) for package: ntp-4.2.6p5-29.el7.centos.2.x86_64 --> Running transaction check ---> Package autogen-libopts.x86_64 0:5.18-5.el7 will be installed ---> Package ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 will be installed --> Finished Dependency Resolution Dependencies Resolved ================================================================================================================= Package Arch Version Repository Size ================================================================================================================= Installing: ntp x86_64 4.2.6p5-29.el7.centos.2 base 549 k Installing for dependencies: autogen-libopts x86_64 5.18-5.el7 base 66 k ntpdate x86_64 4.2.6p5-29.el7.centos.2 base 87 k Transaction Summary ================================================================================================================= Install 1 Package (+2 Dependent packages) Total download size: 701 k Installed size: 1.6 M Downloading packages: (1/3): autogen-libopts-5.18-5.el7.x86_64.rpm | 66 kB 00:00:00 (2/3): ntpdate-4.2.6p5-29.el7.centos.2.x86_64.rpm | 87 kB 00:00:00 (3/3): ntp-4.2.6p5-29.el7.centos.2.x86_64.rpm | 549 kB 00:00:00 ----------------------------------------------------------------------------------------------------------------- Total 1.7 MB/s | 701 kB 00:00:00 Running transaction check Running transaction testTransaction test succeeded Running transaction Installing : autogen-libopts-5.18-5.el7.x86_64 1/3 Installing : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 2/3 Installing : ntp-4.2.6p5-29.el7.centos.2.x86_64 3/3 Verifying : ntpdate-4.2.6p5-29.el7.centos.2.x86_64 1/3 Verifying : ntp-4.2.6p5-29.el7.centos.2.x86_64 2/3 Verifying : autogen-libopts-5.18-5.el7.x86_64 3/3 Installed: ntp.x86_64 0:4.2.6p5-29.el7.centos.2 Dependency Installed: autogen-libopts.x86_64 0:5.18-5.el7 ntpdate.x86_64 0:4.2.6p5-29.el7.centos.2 Complete! [root@ntp ~]#
三、配置阿里雲映象站NTP服務
配置之前,測試伺服器是否能夠訪問到阿里雲NTP伺服器。
ping ntp.aliyun.com -c 5
修改/etc/ntp.conf
配置檔案。
註釋掉原來配置檔案中的NTP伺服器地址,新增阿里雲NTP伺服器地址。
[root@ntp ~]# vi /etc/ntp.conf[root@ntp ~]# cat /etc/ntp.conf# For more information about this file, see the man pages# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).driftfile /var/lib/ntp/drift# Permit time synchronization with our time source, but do not# permit the source to query or modify the service on this system.restrict default nomodify notrap nopeer noquery# Permit all access over the loopback interface. This could# be tightened as well, but to do so would effect some of# the administrative functions.restrict 127.0.0.1 restrict ::1# Hosts on local network are less restricted.#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap# Use public servers from the pool.ntp.org project.# Please consider joining the pool ().#server 0.centos.pool.ntp.org iburst#server 1.centos.pool.ntp.org iburst#server 2.centos.pool.ntp.org iburst#server 3.centos.pool.ntp.org iburstserver ntp.aliyun.com#broadcast 192.168.1.255 autokey # broadcast server#broadcastclient # broadcast client#broadcast 224.0.1.1 autokey # multicast server#multicastclient 224.0.1.1 # multicast client#manycastserver 239.255.254.254 # manycast server#manycastclient 239.255.254.254 autokey # manycast client# Enable public key cryptography.#cryptoincludefile /etc/ntp/crypto/pw# Key file containing the keys and key identifiers used when operating# with symmetric key cryptography. keys /etc/ntp/keys# Specify the key identifiers which are trusted.#trustedkey 4 8 42# Specify the key identifier to use with the ntpdc utility.#requestkey 8# Specify the key identifier to use with the ntpq utility.#controlkey 8# Enable writing of statistics records.#statistics clockstats cryptostats loopstats peerstats# Disable the monitoring facility to prevent amplification attacks using ntpdc# monlist command when default restrict does not include the noquery flag. See# CVE-2013-5211 for more details.# Note: Monitoring will not be disabled with the limited restriction flag.disable monitor [root@ntp ~]#
四、啟動NTP服務
啟動ntp服務
systemctl start ntpd
設定ntp服務開機自啟動
systemctl enable ntpd
檢視ntp服務是否正常
systemctl status ntpd
[root@ntp ~]# systemctl start ntpd[root@ntp ~]# systemctl enable ntpdCreated symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service. [root@ntp ~]# systemctl status ntpd● ntpd.service - Network Time Service Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled) Active: active (running) since Sun 2021-11-28 19:06:34 CST; 23h left Main PID: 1988 (ntpd) CGroup: /system.slice/ntpd.service └─1988 /usr/sbin/ntpd -u ntp:ntp -g Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 3 ens32 192.168.1.50 UDP 123 Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 4 lo ::1 UDP 123 Nov 28 19:06:34 ntp ntpd[1988]: Listen normally on 5 ens32 fe80::e4b:3ef:613c:8741 UDP 123 Nov 28 19:06:34 ntp ntpd[1988]: Listening on routing socket on fd #22 for interface updatesNov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c016 06 restart Nov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM Nov 28 19:06:34 ntp ntpd[1988]: 0.0.0.0 c011 01 freq_not_set Nov 28 19:09:51 ntp ntpd[1988]: 0.0.0.0 c61c 0c clock_step -86398.982768 s Nov 27 19:09:52 ntp ntpd[1988]: 0.0.0.0 c614 04 freq_mode Nov 27 19:09:53 ntp ntpd[1988]: 0.0.0.0 c618 08 no_sys_peer [root@ntp ~]#
五、檢視NTP源
ntpq -p
即[203.107.6.88]地址為阿里雲NTP伺服器的IP地址。
[root@ntp ~]# ntpq -premote refid st t when poll reach delay offset jitter
203.107.6.88 100.107.25.114 2 u 56 64 7 13.685 -0.002 0.415
六、檢視NTP服務狀態
# 輸出如下內容,表示在同步中,需要耐心等待一下[root@ntp ~]# ntpstatunsynchronised time server re-starting polling server every 8 s# 輸出如下內容,表示同步成功[root@ntp ~]# ntpstatsynchronised to NTP server (203.107.6.88) at stratum 3 time correct to within 958 ms polling server every 64 s
七、將客戶端與NTP伺服器同步
[root@client ~]# ntpdate -d 192.168.1.5028 Nov 19:37:54 ntpdate[2880]: ntpdate 4.2.6p5@1.2349-o Tue Jun 23 15:38:19 UTC 2020 (1) Looking for host 192.168.1.50 and service ntp host found : 192.168.1.50 transmit(192.168.1.50) receive(192.168.1.50) transmit(192.168.1.50) receive(192.168.1.50) transmit(192.168.1.50) receive(192.168.1.50) transmit(192.168.1.50) receive(192.168.1.50) server 192.168.1.50, port 123 stratum 3, precision -25, leap 00, trust 000 refid [192.168.1.50], delay 0.02652, dispersion 0.00000 transmitted 4, in filter 4 reference time: e54c9534.6f868aa9 Sat, Nov 27 2021 19:29:56.435 originate timestamp: e54c9719.4617ce7f Sat, Nov 27 2021 19:38:01.273 transmit timestamp: e54de898.b45bc870 Sun, Nov 28 2021 19:38:00.704 filter delay: 0.02658 0.02655 0.02652 0.02660 0.00000 0.00000 0.00000 0.00000 filter offset: -86399.4 -86399.4 -86399.4 -86399.4 0.000000 0.000000 0.000000 0.000000 delay 0.02652, dispersion 0.00000 offset -86399.431479 28 Nov 19:38:00 ntpdate[2880]: step time server 192.168.1.50 offset -86399.431479 sec [root@client ~]#
八、將系統時間同步到硬體
[root@client ~]# hwclock -w[root@client ~]# dateSun Nov 28 19:39:10 CST 2021
【阿里雲官方映象站: https://developer.aliyun.com/mirror/?utm_content=g_1000307095 】
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/70010340/viewspace-2847449/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- CentOS 配置阿里雲 NTP 服務CentOS阿里
- CentOS7使用NTP搭建時間同步伺服器CentOS伺服器
- Linux 之 NTP 服務 伺服器Linux伺服器
- ntp服務在區域網內的搭建
- .NET實現獲取NTP伺服器時間並同步(附帶Windows系統啟用NTP服務功能)伺服器Windows
- Windos NTP 服務設定
- centos8使用chrony作為NTP伺服器CentOS伺服器
- Linux NTP服務配置 for Oracle RACLinuxOracle
- 如何在 CentOS 中設定 NTP 伺服器CentOS伺服器
- NTP/SSH 伺服器伺服器
- 【NTP】Redhat5.1環境下網路時間服務NTP的安裝部署Redhat
- 基於GPS北斗雙系統的NTP網路時間伺服器的開發伺服器
- 基於ECS搭建FTP服務(阿里雲)FTP阿里
- Linux系統 Centos7 環境基於Docker部署Rocketmq服務LinuxCentOSDockerMQ
- 自動批量對linux伺服器安裝配置NTP服務Linux伺服器
- Linux下 ntp 時間同步服務ntpd 出現 the NTP socket is in use, exiting 解決Linux
- Centos下部署NTP時間伺服器同步環境CentOS伺服器
- 時間伺服器-NTP伺服器
- CentOS7系統如何搭建Magento電子商務網站?CentOS網站
- Centos7系統配置DNS服務CentOSDNS
- CentOS7中使用阿里雲映象CentOS阿里
- centos7下ldap服務搭建CentOSLDA
- Linux伺服器配置---ntpLinux伺服器
- 基於windows系統上搭建git-server服務WindowsGitServer
- linux-ntp 使用Linux
- NTP系統時間同步-操作記錄
- centos下部署NTP時間伺服器同步環境記錄CentOS伺服器
- 在Centos7伺服器上搭建閘道器服務CentOS伺服器
- NTP網路時間伺服器助力金融網路系統安全伺服器
- 淺談基於 NTP 的反射和放大攻擊反射
- 阿里雲ECS伺服器CentOS7上安裝MySql服務阿里伺服器CentOSMySql
- 【Grafana】基於CentOS 7 安裝部署Grafana服務端GrafanaCentOS服務端
- centos 7 下搭建zabbix監聽服務CentOS
- 【伺服器】CentOs7系統使用寶塔皮膚搭建網站,有FTP配置(保姆式教程)伺服器CentOS網站FTP
- Windows下更改並使用NTPWindows
- 用 NTP 設定 CentOS 和 Ubuntu 伺服器的正確時區CentOSUbuntu伺服器
- Linux使用ntp時間伺服器同步時間Linux伺服器
- 基於 CentOS 7 搭建支援 HTTP 協議的 SVN 伺服器CentOSHTTP協議伺服器