centos配置ntp时间同步_Linux CentOS配置ntpd时间同步
腳本在CentOS7上測試OK。可以直接使用。
yum -y install ntp ntpdatecp /usr/share/zoneinfo/Asia/Shanghai /etc/localtimentpdate ntp.sjtu.edu.cnhwclock -wsed -i.bak '2,$d' /etc/ntp.confcat << EOF >> /etc/ntp.confdriftfile /var/lib/ntp/driftrestrict default kod nomodify notrap nopeer noqueryrestrict -6 default kod nomodify notrap nopeer noqueryrestrict 127.0.0.1restrict -6 ::1server 0.centos.pool.ntp.orgserver 1.centos.pool.ntp.orgserver 2.centos.pool.ntp.orgserver time.asia.apple.com burst iburstserver ntp.nasa.gov burst iburstserver ntp.sjtu.edu.cn burst iburstserver clock.via.net burst iburstincludefile /etc/ntp/crypto/pwkeys /etc/ntp/keysEOFsystemctl start ntpd.servicesystemctl enable ntpd.servicentpq -pntpstat下面是我操作的大致過程,供參考:
node2 root@node2:~# bash -x ntpd.sh
+ yum -y install ntp ntpdate
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
* base: mirrors.cqu.edu.cn
* extras: mirrors.cqu.edu.cn
* updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
docker-ce-stable | 3.5 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
Package ntp-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version
Package ntpdate-4.2.6p5-29.el7.centos.2.x86_64 already installed and latest version
Nothing to do
+ cp /usr/share/zoneinfo/Asia/Shanghai /etc/localtime
+ ntpdate ntp.sjtu.edu.cn
30 Oct 16:54:09 ntpdate[23958]: the NTP socket is in use, exiting
+ hwclock -w
+ sed -i.bak '2,$d' /etc/ntp.conf
+ cat
+ systemctl start ntpd.service
+ systemctl enable ntpd.service
+ ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
ntp1.ams1.nl.le 130.133.1.10 2 u 40 64 3 278.831 -30.265 20.725
139.199.215.251 100.122.36.4 2 u 39 64 3 46.198 8.272 1.160
undefined.hostn 127.67.113.92 2 u 38 64 3 413.253 -88.696 52.447
*hkhkg1-ntp-002. .GPSs. 1 u 35 64 3 62.384 8.753 6.082
clock.via.net .INIT. 16 u - 64 0 0.000 0.000 0.000
+ ntpstat
synchronised to NTP server (17.253.84.253) at stratum 2
time correct to within 983 ms
polling server every 64 s
node2 root@node2:~# ntpstat
synchronised to NTP server (17.253.84.253) at stratum 2
time correct to within 983 ms
polling server every 64 s
如何確認工作OK?
node2 root@node2:~# netstat -ln|grep 123
udp 0 0 10.42.1.0:123 0.0.0.0:*
udp 0 0 172.17.0.1:123 0.0.0.0:*
udp 0 0 192.168.122.1:123 0.0.0.0:*
udp 0 0 10.211.55.6:123 0.0.0.0:*
udp 0 0 127.0.0.1:123 0.0.0.0:*
udp 0 0 0.0.0.0:123 0.0.0.0:*
udp6 0 0 fe80::69dc:5159:1d4:123 :::*
udp6 0 0 fe80::2ce8:d4ff:fe8:123 :::*
udp6 0 0 fdb2:2c26:f4e4:0:7a:123 :::*
udp6 0 0 fe80::ecee:eeff:fee:123 :::*
udp6 0 0 fe80::ecee:eeff:fee:123 :::*
udp6 0 0 fe80::ecee:eeff:fee:123 :::*
udp6 0 0 fe80::ecee:eeff:fee:123 :::*
udp6 0 0 ::1:123 :::*
udp6 0 0 :::123 :::*
node2 root@node2:~# ntpstat
synchronised to NTP server (17.253.84.253) at stratum 2
time correct to within 985 ms
polling server every 64 s
#該指令可列出NTP
服務器是否與上層聯機。由上述輸出結果可知,時間校正約
為985ms且每隔64秒會主動更新時間
OK
當然要更改時間源的自己可以檢索下。
總結
以上是生活随笔為你收集整理的centos配置ntp时间同步_Linux CentOS配置ntpd时间同步的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: AMD 发布超频工具 Ryzen Mas
- 下一篇: Counterpoint:春节前后5周内