Centos7搭建NTP服务

1.1 查看系统是否已经安装ntp服务组件

rpm -qa | grep "ntp"                #<==查看是否已经安装ntp组件,有如下两个组件说明已经安装
ntpdate-4.2.6p5-1.el6.centos.x86_64
ntp-4.2.6p5-1.el6.centos.x86_64

 1.2 yum安装

yum -y install ntp

1.3 ntp服务器端的配置


1.3.1 配置文件
Ø  配置文件

/etc/ntp.conf


Ø  配置文件默认内容

egrep -v "^$|#" /etc/ntp.conf        #<==排除默认注释及空行
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery     #<==对默认的client拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1      #<==允许本地地址的一切操作                             
restrict -6 ::1
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
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

Ø  修改配置

cat /etc/ntp.conf
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery     #<==对默认的client拒绝所有操作
restrict -6 default kod nomodify notrap nopeer noquery
restrict 127.0.0.1                                      #<==允许本机的一切操作
restrict 192.168.1.0 mask 255.255.255.0 nomodify    #<==允许局域网内所有client连接到这台服务器
restrict -6 ::1                                         同步时间.但是拒绝让他们修改服务器上的时间
#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 ntp1.aliyun.com          #<==同步公网的时间
server 127.127.1.0              #<==如果无法连接公网,则使用自己本身的时间作为标准时间。
fudge 127.127.1.0 stratum 10    #<==设置stratum级别
includefile /etc/ntp/crypto/pw
keys /etc/ntp/keys

1.4服务启动

systemctl start ntpd
systemctl enable ntpd

1.5客户端同步

yum -y install ntpdate
ntpdate -u IP地址(ntp服务的IP地址)

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,下面是在 CentOS 7 上搭建 NTP 服务器的步骤: 1. 安装 NTP:运行以下命令安装 NTP: ``` sudo yum install ntp ``` 2. 配置 NTP:编辑 `/etc/ntp.conf` 文件,配置服务器地址和允许访问的客户端地址。例如,以下是一个示例配置: ``` server 0.centos.pool.ntp.org iburst server 1.centos.pool.ntp.org iburst server 2.centos.pool.ntp.org iburst restrict default nomodify notrap nopeer noquery restrict 127.0.0.1 restrict <客户端IP地址> mask <子网掩码> nomodify notrap ``` 其中,`server` 指定 NTP 服务器地址,`restrict` 用于限制访问控制。 3. 启动 NTP:运行以下命令启动 NTP 服务并设置为开机自启: ``` sudo systemctl start ntpd sudo systemctl enable ntpd ``` 4. 验证 NTP:使用 `ntpq` 命令验证 NTP 是否正常工作。例如,运行以下命令: ``` ntpq -p ``` 如果 NTP 正常工作,将显示类似以下内容的输出: ``` remote refid st t when poll reach delay offset jitter ============================================================================== *ntp1.example.c .GPS. 1 u 154 256 377 0.862 -30.200 1.835 +ntp2.example.c .PPS. 1 u 173 256 377 0.991 -30.230 1.309 -ntp3.example.c .GPS. 1 u 130 256 377 1.003 -29.990 1.935 ``` 其中,`*` 表示当前服务器为 NTP服务器,`+` 表示当前服务器为 NTP 辅助服务器,`-` 表示当前服务器为 NTP 被动服务器。 以上就是在 CentOS 7 上搭建 NTP 服务器的步骤。希望能对你有所帮助。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值