CentOS7配置NTP

查看系统时间

date

查看硬件时间

hwclock 

将系统时间写入硬件时间

hwclock -w

修改时间

date -s

(将系统日期设定为2010年05月16日)

date -s 05/16/2010

时间服务器上时间同步的方法

CentOS7之前采用ntp服务自动同步时间,CentOS7推荐使用chrony同步时间,当然ntp仍然可以使用,chrony官网列举了诸多chrony优于ntp的功能(ntp与chrony的对比:https://chrony.tuxfamily.org/comparison.html)。

若要立刻将系统时间同步为NTP服务时间,使用ntpdate命令,也可以配置计划任务定期使用ntpdate命令同步时间,从而就不用使用ntp或chrony服务,减少监听的端口,增加系统安全性。

1.ntp的安装配置

安装ntp

yum -y install ntp

配置ntp同步阿里云时间服务器

vim /etc/ntp.conf
...
server ntp1.aliyun.com
server ntp2.aliyun.com
server ntp3.aliyun.com
#server 0.centos.pool.ntp.org iburst
...

启动ntp服务器

systemctl start ntpd

2chrony的安装配置

安装chrony

yum -y install chrony

配置chrony

vim /etc/chrony.conf
server ntp1.alyun.com
server ntp2.alyun.com
server ntp3.alyun.com
#server 0.centos.pool.ntp.org iburst...

启动chrony

systemctl start chronyd

3配置计划任务,使用ntpdate同步时间

启动并开机启动计划任务cron

systemctl start crond
systemctl enable crond

 配置计划任务,每30分钟同步一次

 crontab -e
*/30 * * * * /usr/sbin/ntpdate ntp1.aliyun.com

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值