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服务器以及一些常见错误解决的更多相关文章

  1. Hadoop - Mac OSX下配置和启动hadoop以及常见错误解决

    0. 安装JDK 参考网上教程在OSX下安装jdk 1. 下载及安装hadoop a) 下载地址: http://hadoop.apache.org b) 配置ssh环境 在terminal里面输入: ...

  2. centos配置NTP服务器

    时间服务器: NTP(Network Time Protocol,网络时间协议)是用来使用网络中的各个计算机时间同步的一种协议,NTP服务器就是利用NTP协议提供时间同步服务的. 一.环境准备: 1. ...

  3. Linux配置NTP服务器,时间同步

    当服务器多了,时间准确与否,一致与否是个大问题.虽然这个问题总是被忽略,但是统一一致的时间是很有必要的.下面说一下在局域网内配置Linux时间服务器的方法. 配置的环境及要求: 假设在192.168. ...

  4. 95、配置ntp服务器

    95.1.ntp简介: ntp服务使用的是udp的123端口,如果开启了防火墙要记得放开这个端口: NTP(Network Time Protocol,网络时间协议)是用来使网络中的各个计算机时间同步 ...

  5. 为在MyEclipse中配置Tomcat服务器郁闷的朋友们解决郁闷

    是不是很郁闷!为了在MyEclipse配置Tomcat 服务器,竟然弄了你几乎一个上午,最后也没弄成功,也许你本该早注意到Tomcat 5.x要有这个JDK的支持,配置才能成功. 一上午辛辛苦苦也没解 ...

  6. Linux vsftpd服务配置以及三种验证方式以及常见错误解决办法

    文件传输协议(FTP): 文件传输协议(FTP,File Transfer Protocol),即能够让用户在互联网中上传.下载文件的文件协议,而FTP服务器就是支持FTP传输协议的主机,要想完成文件 ...

  7. linux免密登录ssh验证配置方法及常见错误解决

    目标:从服务器A免密登录服务器B [配置方法] 1.在服务器A生成密钥文件,直接使用以下命令: ssh-keygen 中间遇到输入内容一路回车即可,完成后会在 ~/.ssh 目录下生成两个文件:id_ ...

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

    一.安装命令: 1)以root身份登录.执行:sudo su -命令 2)执行安装命令:apt-get install subversion   二.创建项目目录 1)mkdir  /home/svn ...

  9. 日常工作问题解决:rhel7下配置多路径设备

    目录 1.情景描述 2.安装多路径软件 2.1 安装多路径 2.2检查安装情况 2.3 重启系统 2.4 将多路径软件添加至内核模块 2.5 检查内核添加情况 2.6 启动multipath服务 2. ...

随机推荐

  1. Python多线程笔记(二)

    Lock对象 原语锁(互斥锁)是一个同步原语,状态是"已锁定"或者"未锁定"之一.两个方法acquire()和release()用于修改锁的状态.如果状态为已锁 ...

  2. 递归函数返回值 undefined

    getItem(obj, arr, index) { if (arr.length - 1 !== index) { const tempObj = obj[arr[index]]; this.get ...

  3. php curl 传递数据

    <?php header("Content-type: text/html; charset=utf-8"); /** * curl 传递数据 */ class curl { ...

  4. mysql中Numeric类型和int类型的区别

    首先记一下,Numeric数字数据只包含 数字.数字数据包括正数.负数.小数.分数和整数 例子如下: Numeric(6,2) Numeric(16,6) Numeric(16,0) 从左到右,第一个 ...

  5. python下载后出现python 已停止工作

    背景: 在执行IDLE或者在terminal窗口执行 python命令时出现如下提示,修改了防火墙关闭也不行,找不到解决办法? 如图: [解决方案] 1.卸载重装python,确保python版本与系 ...

  6. Python基础之可接受任意数量参数的函数

    1. 可接受任意数量位置参数的函数 为了能让一个函数接受任意数量的位置参数,可以在参数部分使用“*”. def avg(first, *rest): return (first + sum(rest) ...

  7. js 删除节点

    亲身经历,寻得此法,告知大家=============== 在javascript操作dom树的时候可能会经常遇到增加,删除节点的事情,比如一个输入框后一个增加按钮,一个删除按钮,点击增加就增加 个输 ...

  8. MyBatis:Error evaluating expression ''''. Return value () was not iterable错误

    Error evaluating expression ''''.  Return value () was not iterable 出现原因:xml文件中遍历List 时,该参数的实际值为非Lis ...

  9. Jenkins中插件下载失败的解决办法

    插件下载失败原因:通过国外服务器下载镜像,有较高的失败率,某些插件下载失败或者中断会引起其他有依赖关系的插件也下载失败 解决方案:1. 使用VPN.2. Jenkins镜像地址改为国内镜像地址:系统管 ...

  10. String源码分析

    前言:String类在日常开发过程中使用频率非常高,平时大家可能看过String的源码,但是真的认真了解过它么,笔者在一次笔试过程中要求写出String的equals方法,瞬间有点懵逼,凭着大致的理解 ...