Linux时间同步服务 - chronyd

Linux时间同步服务 - chronyd

安装

使用软件包安装工具安装chronyntp

  • Arch Linux系列:

    sudo pacman -S ntp chrony
    
  • Debian系列:

    sudo apt install ntp chrony
    
  • Red Hat系列:

    sudo yum install ntp chrony
    

    或者

    sudo dnf install ntp chrony
    

配置

① 在chrony配置文件中,将原授时NTP服务器注释,并填入阿里或腾讯NTP授时服务器网址,示例如下:

### SPECIFY YOUR NTP SERVERS
# Most computers using chrony will send measurement requests to one or
# more 'NTP servers'.  You will probably find that your Internet Service
# Provider or company have one or more NTP servers that you can specify.
# Failing that, there are a lot of public NTP servers.  There is a list
# you can access at http://support.ntp.org/bin/view/Servers/WebHome or
# you can use servers from the pool.ntp.org project.

#! server 0.arch.pool.ntp.org iburst
#! server 1.arch.pool.ntp.org iburst
#! server 3.arch.pool.ntp.org iburst

#pool 2.arch.pool.ntp.org iburst

# The URL of Tencent NTP network time server is as follows:
! server ntp.tencent.com iburst
! server ntp2.tencent.com iburst
! server ntp3.tencent.com iburst
! server ntp4.tencent.com iburst
! server ntp5.tencent.com iburst

# The URL of Ali NTP network time server is as follows:
! server ntp.aliyun.com iburst
! server ntp1.aliyun.com iburst
! server ntp2.aliyun.com iburst
! server ntp3.aliyun.com iburst
! server ntp4.aliyun.com iburst
! server ntp5.aliyun.com iburst
! server ntp6.aliyun.com iburst
! server ntp7.aliyun.com iburst

pool ntp1.tencent.com

注意:

选择其中三、四个即可。

② 输入如下命令,使得防火墙为chronyd服务放行,以便chronyd服务顺利运行:

  • Firewalld设置:

    $ firewall-cmd --add-service=ntp --permanent
    $ firewall-cmd --reload
    
  • Ufw设置:

    $ sudo ufw allow ntp
    $ sudo ufw allow out ntp
    

管理

使用systemctl命令允许chronyd服务开机自启动、使得chronyd服务启动并查看chronyd服务的运行状态,具体命令如下所示:

# systemctl start chronyd.service    #启动
# systemctl status chronyd.service     #查看
# systemctl enable chronyd.service    #设置开机启动

使用如下命令,查看时间同步源:

$ chronyc sources -v

使用如下命令,查看时间同步源状态:

$ chronyc sourcestats -v

使用如下命令,启用NTP时间同步:

$ timedatectl set-ntp yes

使用如下命令,校准时间服务器:

$ chronyc tracking

注意:

配置完/etc/chrony.conf后,需重启chrony服务,否则可能会不生效。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值