日常工作问题解决:配置NTP服务器以及一些常见错误解决
1、配置NTP服务端
环境:redhat 6.5
服务器主机名 | ip地址 | 说明 |
---|---|---|
server | 192.168.57.20 | NTP服务端 |
client | 192.168.57.21 | NTP客户端 |
搭建说明:
本地server使用外网ntp源同步时间,再作为NTP服务端同步时间给本地client服务器NTP客户端
1.1 安装NTP服务
在ntp服务器查看系统是否安装NTP服务
[root@server~]# rpm -qa|grep ntp
ntpdate-4.2.6p5-1.el6.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-1.el6.x86_64
如果没有安装,安装ntp
yum -y install ntp
备份原有ntp配置文件
mv /etc/ntp.conf /etc/npt.conf.bak
1.2 配置NTP服务端
编辑ntp.conf配置文件
# Permit time synchronization with our time source, but do not
# permit the source to query or modify the service on this system.
restrict default ignore
restrict 127.0.0.1
restrict 192.168.112.0 mask 255.255.255.0 nomodify
设置容许访问该ntp服务器的网络地址段
restrict 192.168.57.0 mask 255.255.255.0 nomodify
Permit all access over the loopback interface. This could
be tightened as well, but to do so would effect some of
the administrative functions.
Use public servers from the pool.ntp.org project.
Please consider joining the pool (http://www.pool.ntp.org/join.html).
设定NTP主机来源(其中prefer表示优先主机)
server 1.cn.pool.ntp.org prefer
默认优先使用1.cn.pool.ntp.org
server 1.rhel.pool.ntp.org
server pool.ntp.org
broadcast 172.30.8.255 key 42 # broadcast server
broadcastclient # broadcast client
broadcast 224.0.1.1 key 42 # multicast server
multicastclient 224.0.1.1 # multicast client
manycastserver 239.255.254.254 # manycast server
manycastclient 239.255.254.254 key 42 # manycast client
Undisciplined Local Clock. This is a fake driver intended for backup
and when no outside source of synchronized time is available.
server 127.127.1.0
fudge 127.127.1.0 stratum 10
local clock设置本地ntp服务器地址,当外网ntp服务器连接异常时,使用本地NTP服务器进行同步
Drift file. Put this in a directory which the daemon can write to.
No symbolic links allowed, either, since the daemon updates the file
by creating a temporary in the same directory and then rename()'ing
it to the file.
driftfile /var/lib/ntp/drift
Key file containing the keys and key identifiers used when operating
with symmetric key cryptography.
broadcastdelay 0.008
logfile /var/log/ntp.log
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
启动ntp服务
service ntpd start
设置开机启动
chkconfig ntpd on
查看NTP状态
-bash-4.1$ ntpstat
synchronised to local net at stratum 11
time correct to within 12 ms
polling server every 64 s
-bash-4.1$ ntpq -p
remote refid st t when poll reach delay offset jitter
*LOCAL(0) .LOCL. 10 l 11 64 377 0.000 0.000 0.000
120.25.115.20 .INIT. 16 u - 1024 0 0.000 0.000 0.000
2 配置NTP客户端
2.1 安装NTP服务
在ntp服务器查看系统是否安装NTP服务
[root@client~]# rpm -qa|grep ntp
ntpdate-4.2.6p5-1.el6.x86_64
fontpackages-filesystem-1.41-1.1.el6.noarch
ntp-4.2.6p5-1.el6.x86_64
如果没有安装,安装ntp
yum -y install ntp
备份原有ntp配置文件
mv /etc/ntp.conf /etc/npt.conf.bak
2.2 配置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
Permit all access over the loopback interface. This could
be tightened as well, but to do so would effect some of
the administrative functions.
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).
server 0.rhel.pool.ntp.org iburst
server 1.rhel.pool.ntp.org iburst
server 2.rhel.pool.ntp.org iburst
server 192.68.57.20 perfer
设置192.168.57.20为优先的ntp服务器
restrict 192.68.57.20 nomodify notrap noquery
server 127.127.1.0 # local clock
fudge 127.127.1.0 stratum 10
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服务
service ntpd start
设置NTP服务自启动
chkconfig ntpd on
查看ntp服务状态:
-bash-4.1$ ntpstat
synchronised to NTP server (192.168.57.20) at stratum 12
time correct to within 21 ms
polling server every 256 s
-bash-4.1$ ntpq -p
remote refid st t when poll reach delay offset jitter
*192.168.57.20 LOCAL(0) 11 u 242 256 377 0.302 0.012 0.187
LOCAL(0) .LOCL. 10 l 46m 64 0 0.000 0.000 0.000
3、常见错误
3.1 ntpq -p查看时间同步情况时报localhost: timed out, nothing received错误
在使用ntpq -p时报:
localhost: timed out, nothing received
***Request timed out
解决办法:
1、查看/etc/hosts文件,确认有以下信息,可以正确解析本地ntp服务
127.0.0.1 localhost localhost4 localhost4.localdomain4
::1 localhost localhost.localdomain localhost6 localhost6.localdomain6
2、如果/etc/hosts文件配置正确,使用ntpq -4p(即指定通过ipv4 地址获取返回值),如果正常显示,但是使用ntpq -6p(即指定通过ipv4 地址获取返回值)异常,则说明时因为开启了Ipv6 ,默认ntpq 先走Ipv6的通道,而ECS linux 默认无法直接访问ipv6地址,因此会访问超时
可以禁用接口的IPv6,然后就会正确,方法如下:
/etc/sysctl.conf 文件尾添加如下参数
# 禁用整个系统所有接口的IPv6
net.ipv6.conf.all.disable_ipv6 = 1
# 禁用某一个指定接口的IPv6(例如:eth0, eth1)
net.ipv6.conf.eth1.disable_ipv6 = 1
net.ipv6.conf.eth0.disable_ipv6 = 1
然后重启网络服务
service restart network
然后使用ntpq -p,返回值就正常
3.2 ntpq -p查看时间同步情况时报no association ID's returned错误信息
解决方法:
1、关闭selinux
-bash-4.1$ vi /etc/selinux/config
This file controls the state of SELinux on the system.
SELINUX= can take one of these three values:
enforcing - SELinux security policy is enforced.
permissive - SELinux prints warnings instead of enforcing.
disabled - No SELinux policy is loaded.
SELINUX=enforcing
SELINUX=disabled # 设置为disabled
SELINUXTYPE= can take one of these two values:
targeted - Targeted processes are protected,
mls - Multi Level Security protection.
SELINUXTYPE=targeted
2、执行restorecon -R -v /etc/ntp.conf
3、重启ntp服务
service ntpd restart
3.3 添加ntp服务开机自启动,报:service nptd does not support chkconfig
解决方法:
1、查看ntpd服务脚本,是不是在/etc/init.d/目录下
-bash-4.1$ ll /etc/init.d/ntpd
-rwxr-xr-x 1 root root 1974 10月 30 20:28 /etc/init.d/ntpd
注:一般成功安装ntp以后都会有
2、在chkconfig工具服务列表中增加ntpd服务,此时服务会被在/etc/rc.d/rcN.d中赋予K/S入口了
chkconfig --add ntpd
3、修改/etc/init.d/ntpd
vi打开/etc/init.d/ntpd文件
在
#!/bin/bash
后加入
# chkconfig: 2345 10 90
# description: myservice
4、设置ntp服务自启动,发现正常
chkconfig ntpd on
日常工作问题解决:配置NTP服务器以及一些常见错误解决的更多相关文章
- Hadoop - Mac OSX下配置和启动hadoop以及常见错误解决
0. 安装JDK 参考网上教程在OSX下安装jdk 1. 下载及安装hadoop a) 下载地址: http://hadoop.apache.org b) 配置ssh环境 在terminal里面输入: ...
- centos配置NTP服务器
时间服务器: NTP(Network Time Protocol,网络时间协议)是用来使用网络中的各个计算机时间同步的一种协议,NTP服务器就是利用NTP协议提供时间同步服务的. 一.环境准备: 1. ...
- Linux配置NTP服务器,时间同步
当服务器多了,时间准确与否,一致与否是个大问题.虽然这个问题总是被忽略,但是统一一致的时间是很有必要的.下面说一下在局域网内配置Linux时间服务器的方法. 配置的环境及要求: 假设在192.168. ...
- 95、配置ntp服务器
95.1.ntp简介: ntp服务使用的是udp的123端口,如果开启了防火墙要记得放开这个端口: NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步 ...
- 为在MyEclipse中配置Tomcat服务器郁闷的朋友们解决郁闷
是不是很郁闷!为了在MyEclipse配置Tomcat 服务器,竟然弄了你几乎一个上午,最后也没弄成功,也许你本该早注意到Tomcat 5.x要有这个JDK的支持,配置才能成功. 一上午辛辛苦苦也没解 ...
- Linux vsftpd服务配置以及三种验证方式以及常见错误解决办法
文件传输协议(FTP): 文件传输协议(FTP,File Transfer Protocol),即能够让用户在互联网中上传.下载文件的文件协议,而FTP服务器就是支持FTP传输协议的主机,要想完成文件 ...
- linux免密登录ssh验证配置方法及常见错误解决
目标:从服务器A免密登录服务器B [配置方法] 1.在服务器A生成密钥文件,直接使用以下命令: ssh-keygen 中间遇到输入内容一路回车即可,完成后会在 ~/.ssh 目录下生成两个文件:id_ ...
- Ubuntu 搭建svn服务器 ,以及常见错误解决方案
一.安装命令: 1)以root身份登录.执行:sudo su -命令 2)执行安装命令:apt-get install subversion 二.创建项目目录 1)mkdir /home/svn ...
- 日常工作问题解决:rhel7下配置多路径设备
目录 1.情景描述 2.安装多路径软件 2.1 安装多路径 2.2检查安装情况 2.3 重启系统 2.4 将多路径软件添加至内核模块 2.5 检查内核添加情况 2.6 启动multipath服务 2. ...
随机推荐
- Educational Codeforces Round 55 题解
题解 CF1082A [Vasya and Book] 史上最难A题,没有之一 从题意可以看出,翻到目标页只有三种办法 先从\(x\)到\(1\),再从\(1\)到\(y\) 先从\(x\)到\(n\ ...
- grafana 的配置文件,和使用mysql数据库做持久化
grafana 配置文件 vim /etc/grafana/grafana.ini 下面有些参数在新版中6.x版本中已经过时,请参考下面官网最新帮助文档为准 https://grafana.com/d ...
- 同一个类里@Cacheable缓存不起作用
问题原因: 注解@Cacheable是使用AOP代理实现的 ,通过创建内部类来代理缓存方法,类内部的方法调用类内部的缓存方法不会走代理,所以就不能正常创建缓存,所以每次都需要去调用数据库. 解决方法: ...
- ICEM-缺角正方体
原视频下载地址:https://yunpan.cn/cqKwGiMRiqN7I 访问密码 3377
- 浅谈JSONP 的本质工作原理
json 是一种数据格式jsonp 是一种数据调用的方式. 你可以简单的理解为 带callback的json就是jsonp 话说我们访问一个页面的时候 需要像另一个网站获取部分信息, 这就是所谓的跨域 ...
- 《Glibc内存管理》笔记DAY1
目录 x86_64栈和mmap固定映射地址 内存的延迟分配 内核数据结构 mm_struct Heap 操作相关函数 Mmap 映射区域操作相关函数 内容来源 x86_64栈和mmap固定映射地址 ...
- oracle主键修改级联外键
举例:修改te_rygj_menu这张表的主键menu_id时,te_rygj_usermenu中的menu_id也跟着修改.利用触发器trigger实现: create or replace tri ...
- ajax 提交 form表单 ,后台执行两次的问题
网上大多的答案是说同步不同步的问题,但是我把异步改成同步也不行.async: false, // 单击时表单检查 $('.btn-next a').click(function () { if ...
- MIPS 指令集(共31条)
MIPS 指令集(共31条) MIPS 指令集(共31条) 助记符 指令格式 示例 示例含义 操作及其解释 Bit # 31..26 25..21 20..16 15..11 10..6 5..0 R ...
- SpringBoot持久层技术
一.Springboot整合mybatis maven中添加对数据库与mybatis的依赖 <dependencies> <dependency> <groupId> ...