1、之前未安装过ntp直接执行安装命令yum -y install ntp即可
[root@node01 hadoop]# yum -y install ntp
Loaded plugins: fastestmirror
Determining fastest mirrors
centos-office | 3.7 kB 00:00
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package ntp.x86_64 0:4.2.6p5-12.el6.centos.2 will be installed
--> Processing Dependency: ntpdate = 4.2.6p5-12.el6.centos.2 for package: ntp-4.2.6p5-12.el6.centos.2.x86_64
--> Running transaction check
---> Package ntpdate.x86_64 0:4.2.6p5-12.el6.centos.2 will be installed
--> Finished Dependency Resolution
.............................
Running Transaction
Installing : ntpdate-4.2.6p5-12.el6.centos.2.x86_64 1/2
Installing : ntp-4.2.6p5-12.el6.centos.2.x86_64 2/2
Verifying : ntpdate-4.2.6p5-12.el6.centos.2.x86_64 1/2
Verifying : ntp-4.2.6p5-12.el6.centos.2.x86_64 2/2
Installed:
ntp.x86_64 0:4.2.6p5-12.el6.centos.2
Dependency Installed:
ntpdate.x86_64 0:4.2.6p5-12.el6.centos.2
Complete!
2、同步时间服务器时间
[root@node02 yum.repos.d]# ntpdate ntp1.aliyun.com
7 Jul 23:53:25 ntpdate[1222]: step time server 120.25.115.20 offset 168.642068 sec
[root@node02 yum.repos.d]#
遇见问题:
[root@node02 .ssh]# yum -y install ntp
Loaded plugins: fastestmirror
Determining fastest mirrors
YumRepo Error: All mirror URLs are not using ftp, http[s] or file.
Eg. Invalid release/repo/arch combination/
removing mirrorlist with no valid mirrors: /var/cache/yum/x86_64/6/base/mirrorlist.txt
Error: Cannot find a valid baseurl for repo: base
解决方法:修改yum源
[root@node01 yum.repos.d]# cat CentOS-Base.repo
[centos-office]
name=centos-office
failovermethod=priority
baseurl=https://vault.centos.org/6.10/os/x86_64/
gpgcheck=1
gpgkey=https://vault.centos.org/6.10/os/x86_64/RPM-GPG-KEY-CentOS-6