日常工作问题解决:配置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服务


[[email protected]~]# 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服务


[[email protected]~]# 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

原文地址:https://www.cnblogs.com/yj411511/p/11771595.html

时间: 2024-08-01 22:39:40

日常工作问题解决:配置NTP服务器以及一些常见错误解决的相关文章

Linux配置NTP服务器

Linux配置NTP服务器   背景 当服务器多了,时间准确与否,一致与否是个大问题.虽然这个问题总是被忽略,但是统一一致的时间是很有必要的.下面说一下在局域网内配置Linux时间服务器的方法. 配置的环境及要求: 1.假设在192.168.0.0网段内,要以IP为192.168.0.240的Linux机器时间服务器. 2.192.168.0.240服务器能上外网,能与比较权威的公网时间服务器同步 3.同网段内的其他机器每小时自动向192.168.0.240同步时间 配置方法 一.配置NTP服务

用命令设置esxi主机时间和配置NTP服务器

一.设置esxi主机时间 设置esxi主机时间为 2016 年03月8日16:01: 更改esxi系统时间: ~ #  esxcli system time set -d 08 -H 16 -m 01 -M 03 -y 2016 如果同步系统时间到主板上,使用下面命令: ~ # esxcli system time get 更改esxi主机主板上的时间: ~ # esxcli hardware clock set -d 10 -H 10 -m 18 -M 04 -y 2016  如果同步主板到e

搭建配置NTP服务器

1.yum install -y ntp 2.关闭防火墙     service iptables stop     service ip6tables stop     chkconfig iptables off     chkconfig ip6tables off     vim /etc/selinux/config          修改SELINUX=disabled           3.备份ntp.conf配置文件     cp /etc/ntp.conf /etc/ntp.

linux 11G R2 RAC 配置NTP服务器

11G RAC  配置NTP服务器 tip01的IP:162.20.1.228  NTP服务端 tip02的IP:162.20.1.229  NTP客户端 配置NTP服务器之前,确认服务器已装好NTP包 [[email protected] ~]# rpm -qa  | grep ntp ntp-4.2.2p1-9.el5_4.1 chkfontpath-1.10.1-1.1 然后再把服务器的系统时钟与硬件时间同步一下 先查看下系统 [[email protected] ~]# date 201

Centos6.5 配置NTP服务器

配置NTP-server 环境: [[email protected] ~]# cat/etc/redhat-release  CentOS release 6.5 (Final) [[email protected] ~]# uname -r 2.6.32-431.el6.x86_64 [[email protected] ~]# uname -m x86_64 安装NTP软件: [[email protected] ~]# yum install -yntp 检查远程ntp服务器是否可用:

windows配置NTP服务器

将 Windows 时间服务配置为使用外部时间源管理员可以对位于林根的 PDC 操作主机上的 Windows 时间服务进行配置,使其将外部简单网络时间协议 (SNTP) 时间服务器识别为权威时间服务器.例如,可以将 Microsoft 时间服务器 (time.windows.com) 用作外部 SNTP 时间服务器.要将 Windows 时间服务配置为使用外部 SNTP 时间服务器,请按照下列步骤操作: 1.        单击"开始",单击"运行",键入 rege

安装配置NTP服务器

S端: 192.168.1.193 [[email protected] ~]# yum install ntp -y &>/dev/null [[email protected] ~]# rpm -ql ntp /etc/dhcp/dhclient.d /etc/dhcp/dhclient.d/ntp.sh /etc/ntp.conf                        #主配置文件 /etc/ntp/crypto /etc/ntp/crypto/pw /etc/rc.d/ini

Ubuntu 搭建svn服务器 ,以及常见错误解决方案

一.安装命令: 1)以root身份登录.执行:sudo su -命令 2)执行安装命令:apt-get install subversion 二.创建项目目录 1)mkdir  /home/svn/     mkdir  /home/svn/project 2)cd  /home/svn/project 3)执行权限命令:chmod -R 777 project/ 三.创建svn仓库 svnadmin create  /home/svn/project 执行命令后生成一下文件   四.设置访问权

搭建VPN服务器或 出现733错误解决方法[验证]

搭建VPN服务器出现733错误解决方法[验证]   昨晚用Windows 2003单网卡用花生壳实现VPN,搭建好VPN服务器后(记得把防火墙和WINDOWS连接共享服务关掉哦,在WINDOWS 2003中服务名为:Windows Firewall/Internet Connection Sharing),注册好花生壳(这真是个好东本啊),尝试远程连接时出现错误信息:TCP/IP CP报告了错误733,不能完成到远程计算机的连接, 没有就ppp协议成功.怎么回事呢?百度了一下!原来VPN服务器不