安装命令:
yum -y install ntp
启动NTP服务:
systemctl start ntpd
systemctl enable ntpd
查看NTP服务运行状态:
systemctl status ntpd
修改配置文件:
我这里没有安装vim
,所以用vi
,vim
也一样只是换个名
vi /etc/ntp.conf
我这里有个问题,找不到配置文件,但是用文件查找命令发现就在那里,也许是被隐藏了吧。
ntp配置文件查找命令:
sudo find / -name ntp.conf
修改内容:
# Use public servers from the pool.ntp.org project.
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 iburst
server ntp.aliyun.com iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcast 224.0.1.1 autokey # multicast server
#manycastserver 239.255.254.254 # manycast server
应用配置文件:
grep server /etc/ntp.conf
重启NTP服务:
systemctl restart ntpd
查看同步状态:
ntpq -p
这样再次重启,时间也不会乱了。
详细安装信息:
[root@localhost ~]# yum -y install ntp
已加载插件:fastestmirror
Determining fastest mirrors
* base: ftp.sjtu.edu.cn
* extras: mirrors.bfsu.edu.cn
* updates: mirrors.bfsu.edu.cn
base | 3.6 kB 00:00:00
extras | 2.9 kB 00:00:00
updates | 2.9 kB 00:00:00
updates/7/x86_64/primary_db | 23 MB 00:00:02
软件包 ntp-4.2.6p5-29.el7.centos.2.x86_64 已安装并且是最新版本
无须任何处理
[root@localhost ~]# systemctl start ntpd
[root@localhost ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@localhost ~]# systemctl status ntpd
● ntpd.service - Network Time Service
Loaded: loaded (/usr/lib/systemd/system/ntpd.service; enabled; vendor preset: disabled)
Active: active (running) since 一 2023-10-02 09:06:57 CST; 29s ago
Main PID: 2705 (ntpd)
CGroup: /system.slice/ntpd.service
└─2705 /usr/sbin/ntpd -u ntp:ntp -g
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listen and drop on 1 v6wildcard :: UDP 123
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listen normally on 2 lo 127.0.0.1 UDP 123
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listen normally on 3 ens33 192.168.175.131 UDP 123
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listen normally on 4 lo ::1 UDP 123
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listen normally on 5 ens33 fe80::62:fd49:3a6c:994c UDP 123
10月 02 09:06:57 localhost.localdomain ntpd[2705]: Listening on routing socket on fd #22 for interface updates
10月 02 09:06:57 localhost.localdomain ntpd[2705]: 0.0.0.0 c016 06 restart
10月 02 09:06:57 localhost.localdomain ntpd[2705]: 0.0.0.0 c012 02 freq_set kernel 0.000 PPM
10月 02 09:06:57 localhost.localdomain ntpd[2705]: 0.0.0.0 c011 01 freq_not_set
10月 02 09:07:04 localhost.localdomain ntpd[2705]: 0.0.0.0 c614 04 freq_mode
[root@localhost ~]#
[root@localhost ~]# vi /etc/ntp.conf
[root@localhost ~]# grep server /etc/ntp.conf
# Use public servers from the pool.ntp.org project.
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 iburst
server ntp.aliyun.com iburst
#broadcast 192.168.1.255 autokey # broadcast server
#broadcast 224.0.1.1 autokey # multicast server
#manycastserver 239.255.254.254 # manycast server
[root@localhost ~]# systemctl restart ntpd
[root@localhost ~]# ntpq -p
remote refid st t when poll reach delay offset jitter
==============================================================================
*ntp8.flashdance 194.58.202.20 2 u 1 64 1 350.605 69.011 11.779
111.230.189.174 100.122.36.196 2 u 2 64 1 64.256 38.951 7.296
a.chl.la 131.188.3.222 2 u 1 64 1 215.988 15.178 12.127
203.107.6.88 100.107.25.114 2 u - 64 1 26.506 39.602 7.992
[root@localhost ~]#