1. NTP 简介

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

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

2. 环境准备

os hostname ip
centos6.7 localntpserver 172.16.1.100
centos6.7 ntpclient 172.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 server
server 202.108.6.95
server 202.112.29.82
server 110.75.190.198
server cn.ntp.org.cn #store last time
driftfile /etc/ntp/drift #allow upper modify localhost
restrict 0.0.0.0 nomodify notrap noquery #allow any host
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #level number
fudge 127.127.1.1 stratum 2 #ntp log path
statsdir /var/log/ntp/ #ntp log file
logfile /var/log/ntp/ntp.log

3.5 初始同步时间

ntpdate 202.108.6.95

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

    安装定时工具

yum install crontab

添加定时规则:crontab -e

在末尾追加以下内容

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed #ntp config
0 9 * * 1 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 server
server 172.16.1.92 prefer #store last time
driftfile /etc/ntp/drift #allow upper modify localhost
restrict 0.0.0.0 nomodify notrap noquery #allow any host
restrict 0.0.0.0 mask 0.0.0.0 nomodify notrap #level number
fudge 127.127.1.1 stratum 2 #ntp log path
statsdir /var/log/ntp/ #ntp log file
logfile /var/log/ntp/ntp.log includefile /etc/ntp/crypto/pw keys /etc/ntp/keys

4.3 初始同步时间

ntpdate localntpserver

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

添加定时规则: crontab -e

在末尾追加以下内容

# Example of job definition:
# .---------------- minute (0 - 59)
# | .------------- hour (0 - 23)
# | | .---------- day of month (1 - 31)
# | | | .------- month (1 - 12) OR jan,feb,mar,apr ...
# | | | | .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# | | | | |
# * * * * * command to be executed #ntp config
0 9 * * 1 hwclock -w

4.5 启动 ntpd

service ntpd start

4.6 设置 ntpd 开机启动

chkconfig ntpd on

4.7 查看ntpd 状态

ntpstat

至此,NTP server 与 client 配置完成

最新文章

  1. 使用命令行 Subversion 访问项目源文件(SVN)
  2. Nightmare基于phantomjs的自动化测试套件
  3. FreeImage使用
  4. BZOJ1146——[CTSC2008]网络管理Network
  5. Failed to resolve: junit:junit:4.12
  6. hibernate的pojo和xml文件
  7. C#, float.ToString()的一个坑
  8. C基础--结构体成员初始化方式
  9. java线程安全理解
  10. ubuntu1204上不能正常用emacs配合gocode进行自动补全
  11. 全球顶级专家为你解读:什么是真正的 DevOps?
  12. POJ 1236.Network of Schools (强连通)
  13. hdu 5188
  14. 远程访问数据库查询数据量一大就Hang
  15. Java调用IIS发布的WebService
  16. FZU Problem 1895 整除45问题(整除问题+字符串维护+优化)
  17. 【反编译系列】四、反编译so文件(IDA_Pro)
  18. angular 使用window事件
  19. ALSA声卡驱动的DAPM(二)-建立过程
  20. 数学集合:N Z Q R C

热门文章

  1. V语言横空出世,C/C++/Java/Python/Go地位不保
  2. CentOS 常用命令合集
  3. Codeforces 776C:Molly's Chemicals(思维)
  4. ifream子页面与父页面互调
  5. RT-Thread定时器以及结构体指针的一些思考
  6. vim与系统剪切板之间的复制粘贴
  7. 20140117-配置文件为什么放在UI层
  8. 20131228-sql命令
  9. [Spring+SpringMVC+Mybatis]框架学习笔记(六):事务
  10. windows RDP远程代码执行_CVE-2019-0708漏洞复现