本地NTP服务器与客户端配置

来源:互联网 发布:亚加装饰 知乎 编辑:程序博客网 时间:2024/06/05 05:15

1. NTP 简介

    NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。

    在集群中,为了保证各节点之间的时间一致,我们通常需要配置本地的 NTP 服务器。

2. 环境准备

    oshostnameipcentos6.7localntpserver172.16.1.100centos6.7ntpclient172.16.1.101


3. ntpserver配置

    3.1   查看是否安装有ntpd

    

chkconfig --list


    3.2 安装ntpd

yum install ntpd ntpdate

    3.3 备份 ntpd 配置

mv /etc/ntp.conf /etc/ntp.conf.bak

    3.4 修改ntpd 配置 

    vi/etc/ntp.conf

    输入以下内容

#fast ntp serverserver 202.108.6.95server 202.112.29.82server 110.75.190.198server cn.ntp.org.cn#store last timedriftfile /etc/ntp/drift#allow upper modify localhostrestrict 0.0.0.0 nomodify notrap noquery#allow any hostrestrict 0.0.0.0 mask 0.0.0.0 nomodify notrap#level numberfudge 127.127.1.1 stratum 2#ntp log pathstatsdir /var/log/ntp/#ntp log filelogfile /var/log/ntp/ntp.log

    3.5 初始同步时间

ntpdate 202.108.6.95

    3.6 定时将日期写入硬件,确保重启时时间异常
    安装定时工具

yum install crontab

    

    添加定时规则:vi /etc/crontab

    在末尾追加以下内容

#ntp00 */1 * * * root hwclock -w

    3.7 启动 ntpserver

service ntpd start

    3.8 设置 ntpd 服务开机启动

chkconfig ntpd on

4. 配置 ntpd client

客户端配置除了 /etc/ntp.conf 配置文件内容不同外,其他配置都与ntpd server 相同,因此只做简单介绍,相应步骤参考 ntpd server。

    4.1   安装 ntpd 

yum install ntpd ntpdate

    4.2 修改ntpd 配置vi/etc/ntp.conf

    输入以下内容(localntpserver为ntp server 的hostname)

#fast ntp serverserver localntpserver#store last timedriftfile /etc/ntp/drift#allow upper modify localhostrestrict 0.0.0.0 nomodify notrap noquery#allow any hostrestrict 0.0.0.0 mask 0.0.0.0 nomodify notrap#level numberfudge 127.127.1.1 stratum 2#ntp log pathstatsdir /var/log/ntp/#ntp log filelogfile /var/log/ntp/ntp.logincludefile /etc/ntp/crypto/pw keys /etc/ntp/keys

    4.3 初始同步时间

ntpdate localntpserver

    4.4 定时将日期写入硬件,确保重启时时间异常

    vi/etc/crontab

    在末尾追加以下内容

#ntp00 */1 * * * root hwclock -w

    4.5 启动 ntpd

service ntpd start

    4.6 设置 ntpd 开机启动

chkconfig ntpd on

    4.7 查看ntpd 状态

ntpstat




至此,NTP server 与 client 配置完成





0 0
原创粉丝点击