Linux 时间服务器同步设置

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

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Linux服务器时间同步可以通过NTP协议来实现。具体步骤如下: 1.安装NTP服务:在终端中输入以下命令进行安装 ```shell yum install ntp ``` 2.配置NTP服务:在终端中输入以下命令进行配置 ```shell vi /etc/ntp.conf ``` 在打开的文件中添加如下内容: ```shell server ntp1.aliyun.com iburst server ntp2.aliyun.com iburst server ntp3.aliyun.com iburst ``` 这里以阿里云的NTP服务器为例,你也可以使用其他的NTP服务器。 3.启动NTP服务:在终端中输入以下命令进行启动 ```shell systemctl start ntpd ``` 4.设置NTP服务开机自启:在终端中输入以下命令进行设置 ```shell systemctl enable ntpd ``` 5.让集群自己同步时间:有两种方式 第一种方式:通过crontab来完成同步,推荐这种,容易控制时间同步频率。所有子节点配置定时任务,半分钟同步一次,命令如下: ```shell crontab -e ``` 在打开的文件中添加如下一条信息: ```shell 30 * * * * /usr/sbin/ntpdate master的ip或域名 >> /root/ntpdate.log 2>&1 ``` 后期需要观察一下/root/ntpdate.log中有没有定时同步时间的运行日志。 第二种方式:通过chrony来完成同步,命令如下: ```shell yum install chrony systemctl start chronyd systemctl enable chronyd ``` 6.检查时间同步是否成功:在终端中输入以下命令进行检查 ```shell timedatectl ``` 如果输出结果中的NTP synchronized为yes,则表示时间同步成功。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值