CentOS环境中ntp服务器搭建

主要是简单记录一下ntp服务器的搭建过程,网上攻略很多,这里稍微记录

  1. 安装ntp软件
    直接使用yum就可以了 yum install ntp ntpdate -y

  2. 查找时间同步服务器
    查找的网址为http://www.pool.ntp.org/zone/asia
    对于中国区基本上都是如下内容(来源http://www.pool.ntp.org/zone/cn

    server 0.cn.pool.ntp.org
    server 1.cn.pool.ntp.org
    server 2.cn.pool.ntp.org
    server 3.cn.pool.ntp.org

  3. 配置文件修改
    编辑 /etc/ntp.conf
    server 127.127.1.0 iburst local clock #当外部时间不可用时,使用本地时间。
    restrict x.y.z.c mask 255.255.255.0 nomodify #允许更新的IP地址段

4.防火墙配置
firewall-cmd –add-service=ntp –permanent
firewall-cmd –reload
这样就不需要将防火墙关闭了。

5.启动时间同步服务
systemctl start ntpd
systemctl enable ntpd.service #设置开机启动服务

6.验证是否生效
使用如下命令
ntpq -p
date -R

其它,现在还有一个流行的时间同步应用 chronyd 改天研究一下再补充。

好的,下面是在 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、付费专栏及课程。

余额充值