CentOS NTP服务器安装与配置
NTP简介: NTP(Network Time Protocol)是用来使计算机时间同步化的一种协议,它可以使计算机对其服务器或时钟源做同步化,它可以提供高精准度的时间校正。本例讲解如何在CentOS6.3上配置NTP服务器和NTP客户端,可使多台客户机的时间与指定的NTP服务器的时间保持一致。从而保证了多台服务器的时间同步。
服务器环境 操作系统:CentOS 6.5 x86_x64 服务器ip:192.168.17.253
一、安装NTP服务器
yum install ntp
二、配置NTP NTP配置文件路径:/etc/ntp.conf
# For more information about this file, see the man pages
# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).
driftfile /var/lib/ntp/drift
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default kod nomodify notrap nopeer noquery
restrict -6 default kod nomodify notrap nopeer noquery
restrict 210.72.145.44
# Permit all access over the loopback interface. This could
# be tightened as well, but to do so would effect some of
# the administrative functions. //限定了哪些主机可以从本NTP服务器同步时间
restrict 127.0.0.1
restrict -6 ::1
# Hosts on local network are less restricted.
#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap
# Use public servers from the pool.ntp.org project.
# Please consider joining the pool (http://www.pool.ntp.org/join.html).
//远程时间服务器的地址(建议使用以下NTP服务器地址)
server 210.72.145.44 perfer # 中国国家授时中心
server ntp.sjtu.edu.cn #上海交通大学NTP服务器
server 202.112.10.36 # 1.cn.pool.ntp.org
server 59.124.196.83 # 0.asia.pool.ntp.org
#broadcast 192.168.1.255 autokey # broadcast server
#broadcastclient # broadcast client
#broadcast 224.0.1.1 autokey # multicast server
#multicastclient 224.0.1.1 # multicast client
#manycastserver 239.255.254.254 # manycast server
#manycastclient 239.255.254.254 autokey # manycast client
# Enable public key cryptography.
#crypto
includefile /etc/ntp/crypto/pw
# Key file containing the keys and key identifiers used when operating
# with symmetric key cryptography.
keys /etc/ntp/keys
# Specify the key identifiers which are trusted.
#trustedkey 4 8 42
# Specify the key identifier to use with the ntpdc utility.
#requestkey 8
# Specify the key identifier to use with the ntpq utility.
#controlkey 8
# Enable writing of statistics records.
#statistics clockstats cryptostats loopstats peerstats
三、防火墙 NTP服务默认走UPD协议,使用123端口,如果启动防火墙的话,需要配置一下防火墙。
vim /etc/sysconfig/iptables
打开防火墙配置文件。加入如下配置项:
#open port for NTP server
-A INPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT
重启防火墙服务器:
service iptables restart
四、测试配置 NTP服务启动后大约需要3~5分钟的时间才会进行一次时间同步,在我配置的时候大约等了10分钟左右。我们可以通过命令ntpstat查看同步情况。
注:只有NTP服务器同步成功后,NTP客户端才可以同来同步时间。如果需要立刻从指定的时间服务器同步时间,可以使用”ntpdate”命令。使用”ntpdate”命令时,需要先关闭ntp服务:
service ntpd stop
然后执行 “ntpdate NTPSERVERIP” 即可立即完成时间的同步。 五、相关命令 ntpdate //手动更新NTP服务器时间 ntpq -p //查询网络中的NTP服务器,同时显示客户端和每个服务器的关系 watch ntpq -p //监测ntpq -p命令
六、相关文献 NTP官方网站:http://ntp.org 鸟哥NTP配置:http://vbird.dic.ksu.edu.tw/linux_server/0440ntp_2.php
[box style=”warning”]
感谢adamfei提醒,123端口容易被上传文件攻击。希望大家注意一下!
[/box]
- GitLab 任意文件读取漏洞 (CVE-2016-9086) 和任意用户 token 泄露漏洞
- 如何使用Hue通过数据文件创建Collections
- GNU tar 解压路径绕过漏洞(CVE-2016-6321) 分析
- Memcached 命令执行漏洞(CVE-2016-8704、CVE-2016-8705、CVE-2016-8706)简析
- 使用Hue创建Ssh的Oozie工作流时重定向输出日志报错分析
- Joomla未授权创建特权用户漏洞(CVE-2016-8869)分析
- 检测本地文件躲避安全分析
- 如何在Kerberos的Linux上安装及配置Impala的ODBC驱动
- 对抗静态分析——so文件的加密
- Bypass unsafe-inline mode CSP
- Joomla未授权创建用户漏洞(CVE-2016-8870)分析
- 如何将HDFS文件系统挂载到Linux本地文件系统
- 使用 XML 内部实体绕过 Chrome 和 IE 的 XSS 过滤器
- 响应式编程的实践
- JavaScript 教程
- JavaScript 编辑工具
- JavaScript 与HTML
- JavaScript 与Java
- JavaScript 数据结构
- JavaScript 基本数据类型
- JavaScript 特殊数据类型
- JavaScript 运算符
- JavaScript typeof 运算符
- JavaScript 表达式
- JavaScript 类型转换
- JavaScript 基本语法
- JavaScript 注释
- Javascript 基本处理流程
- Javascript 选择结构
- Javascript if 语句
- Javascript if 语句的嵌套
- Javascript switch 语句
- Javascript 循环结构
- Javascript 循环结构实例
- Javascript 跳转语句
- Javascript 控制语句总结
- Javascript 函数介绍
- Javascript 函数的定义
- Javascript 函数调用
- Javascript 几种特殊的函数
- JavaScript 内置函数简介
- Javascript eval() 函数
- Javascript isFinite() 函数
- Javascript isNaN() 函数
- parseInt() 与 parseFloat()
- escape() 与 unescape()
- Javascript 字符串介绍
- Javascript length属性
- javascript 字符串函数
- Javascript 日期对象简介
- Javascript 日期对象用途
- Date 对象属性和方法
- Javascript 数组是什么
- Javascript 创建数组
- Javascript 数组赋值与取值
- Javascript 数组属性和方法
- 桥接模式
- CF--思维练习--CodeForces - 220C Little Elephant and Shifts (STL模拟)
- CF--思维练习--CodeForces - 221C-H - Little Elephant and Problem (思维)
- CF--思维练习--CodeForces - 219C Color Stripe (思维)
- 疯子的算法总结(六) 简单排序总 选择排序+插入排序+比较排序+冒泡排序
- C语言基础知识总结
- CF思维联系--CodeForces - 218C E - Ice Skating (并查集)
- 数组及字符串相关知识
- C++循环结构
- C++条件分支结构
- USACO Training Section 1.1 贪婪的送礼者Greedy Gift Givers
- 数学--数论--HDU--5878 Count Two Three 2016 ACM/ICPC Asia Regional Qingdao Online 1001
- ACM-ICPC 2019 山东省省赛D Game on a Graph
- 数学--数论--HDU6919 Senior PanⅡ【2017多校第九场】
- 数学--数论--Alice and Bob (CodeForces - 346A )推导