使用ntp服务同步时间
来源:互联网 发布:芈月传 大秦帝国 知乎 编辑:程序博客网 时间:2024/04/20 07:43
今天要在公司的集群上做时间同步,一台机子作为ntp服务器,其余的当做ntp客户端。上网搜了一些资料,总结如下:
ntp服务端配置
- 修改ntp配置文件
# vi /etc/ntp.conf
注意修改中文处注释
# Hosts on local network are less restricted.# 允许内网中其他机器同步时间restrict 192.168.0.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).# 上层时间服务器,有外网的情况下可以使用 : server 210.72.145.44 perfer # 中国国家受时中心server 202.112.10.36 # 1.cn.pool.ntp.orgserver 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# allow update time by the upper server # 允许上层时间服务器主动修改本机时间restrict 210.72.145.44 nomodify notrap noqueryrestrict 202.112.10.36 nomodify notrap noqueryrestrict 59.124.196.83 nomodify notrap noquery
配置文件中有两种关键配置项,一种是server,代表上层时间服务器,本机可以从这些IP上获取时间;一种是restrict,约束了ntp服务的权限。
说下restrict配置。restrict的格式是:
restrict [IP] mask [netmask_IP] [parameter]
parameter主要有以下选项
2. 启动ntp服务
# sudo service ntpd start
- 查看服务连接与监听端口
# sudo netstat -tlunp | grep ntp udp 0 0 172.24.209.222:123 0.0.0.0:* 7554/ntpd udp 0 0 127.0.0.1:123 0.0.0.0:* 7554/ntpd udp 0 0 0.0.0.0:123 0.0.0.0:* 7554/ntpd udp6 0 0 fe80::20c:29ff:fe23:123 :::* 7554/ntpd udp6 0 0 ::1:123 :::* 7554/ntpd udp6 0 0 :::123 :::* 7554/ntpd
第一行说明ntp服务已经启动,ntp默认监听123端口。
ntp客户端配置
- 修改ntp.conf,按照上面的方法配置server为刚才设置的服务器ip,并增加restrict配置(参数nomodify noquery notrap)
server 192.168.0.102restrict 192.168.0.102 nomodify notrap noquery
- 启动ntp服务。启动服务后等待几分钟,再检查时间同步是否成功。
# sudo service ntpd start
- 手动同步。也可以使用下面命令手动同步时间,下面例子中,192.168.0.102是ntp服务器的地址。
# ntpdate -u 192.168.0.102
当ntp自动同步有问题时,可以在crontab中加入如下命令(每5分钟同步一次时间):
# crontab -e*/5 * * * * /usr/sbin/ntpdate -u 192.168.0.102
1 0
- 使用ntp服务同步时间
- IOS 使用NTP时间同步服务
- NTP服务同步时间
- ntp同步时间服务
- ntp时间服务同步
- NTP服务时间同步方案
- NTP服务和时间同步
- NTP服务及时间同步
- 使用NTP同步系统时间
- NTP 服务介绍和配置时间同步
- ntp服务及时间同步问题
- NTP服务及时间同步(CentOS6.x)
- NTP服务及时间同步(CentOS6.x)
- NTP服务及时间同步(CentOS6.x)
- linux之NTP时间同步服务介绍
- NTP服务及时间同步(CentOS6.x)
- 局域网时间同步NTP服务架设
- ntp服务时间同步状态采集策略
- c# 加密与解密 Base64Encode
- Sql Server内置函数实现MD5加密
- PXC集群添加新节点如何使用IST方式避免使用SST方式传输数据
- Bootstrap 按钮
- URAL 1982 Parallel and Perpendicular
- 使用ntp服务同步时间
- 用户线程和守护线程
- ssh 免登陆配置
- 堆排序实现(Java)
- MQTT---HiveMQ源码详解(十五)Persistence-Cluster/Single
- PHP7.0.1下的csv解析bug
- spring事务隔离
- POI操作word模板并生成新的word.docx
- 【译】关键渲染路径