配置NTP服务器

配置NTP时间服务器

一.安装ntp软件

1.检查是否安装了ntp相关包。

rpm -qa | grep ntp

2.安装ntp软件。

yum -y install ntp


二.参数讲解

ignore  :关闭所有的 NTP 联机服务

nomodify:客户端不能更改服务端的时间参数,但是客户端可以通过服务端进行网络校时。

notrust :客户端除非通过认证,否则该客户端来源将被视为不信任子网

noquery :不提供客户端的时间查询:用户端不能使用ntpq,ntpc等命令来查询ntp服务器

notrap :不提供trap远端登陆:拒绝为匹配的主机提供模式 6 控制消息陷阱服务。陷阱服务是 ntpdq 控制消息协议的子系统,用于远程事件日志记录程序。

nopeer :用于阻止主机尝试与服务器对等,并允许欺诈性服务器控制时钟

kod : 访问违规时发送 KoD 包。


三.修改配置文件

1.查看未修改的配置文件

# grep ^[^#] /etc/ntp.conf   

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.pool.ntp.org iburst

server 3.centos.pool.ntp.org iburst

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

1.设置允许任何IP的客户机都可以进行时间同步(修改后的配置文件)

# grep ^[^#] /etc/ntp.conf   

driftfile /var/lib/ntp/drift

restrict default nomodify notrap

restrict 127.0.0.1

restrict ::1

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.pool.ntp.org iburst

server 3.centos.pool.ntp.org iburst

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor

2.只允许192.168.1.0网段的客户机进行时间同步(修改后的配置文件)

# grep ^[^#] /etc/ntp.conf  

driftfile /var/lib/ntp/drift

restrict default nomodify notrap nopeer noquery

restrict 127.0.0.1

restrict ::1

restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

server 0.centos.pool.ntp.org iburst

server 1.centos.pool.ntp.org iburst

server 2.centos.ntp.org iburst

server 3.centos.pool.ntp.org iburst

includefile /etc/ntp/crypto/pw

keys /etc/ntp/keys

disable monitor


四.启动NTP服务和防火墙

systemctl start ntpd

systemctl enable ntpd

iptables -A INPUT -p UDP -i eno16777736 -s 192.168.1.0/24 –dport 123 -j ACCEPT

setsebool -P ntp_disable_trans 1#SELinux设置

vi /etc/sysconfig/ntpd#允许BIOS与系统时间同步,添加下面一行。

SYNC_HWCLOCK=yes


五.检测NTP

1.检测NTP服务是否运行

# netstat -tlunp | grep ntp

udp        0      0 192.168.1.101:123       0.0.0.0:*                           2563/ntpd          

udp        0      0 127.0.0.1:123           0.0.0.0:*                           2563/ntpd          

udp        0      0 0.0.0.0:123             0.0.0.0:*                           2563/ntpd          

udp6       0      0 fe80::20c:29ff:fe7b:123 :::*                                2563/ntpd          

udp6       0      0 ::1:123                 :::*                                2563/ntpd          

udp6       0      0 :::123                  :::*                                2563/ntpd 

2.查看ntp服务器有无和上层ntp连通

# ntpstat

synchronised to NTP server (120.25.108.11) at stratum 3

   time correct to within 99 ms

   polling server every 64 s

3.查看ntp服务器与上层ntp的状态

# ntpq -p

     remote           refid      st t when poll reach   delay   offset  jitter

==============================================================================

 news.neu.edu.cn .INIT.          16 u    –   64    0    0.000    0.000   0.000

x202.118.1.130   202.118.1.47     2 u    7   64  377  153.659    9.605  19.941

*time4.aliyun.co 10.137.38.86     2 u   10   64  377   39.666  -47.661  15.944


remote   – 本机和上层ntp的ip或主机名,“+”表示优先,“*”表示次优先

refid    – 参考上一层ntp主机地址

st       – stratum阶层

when     – 多少秒前曾经同步过时间

poll     – 下次更新在多少秒后

reach    – 已经向上层ntp服务器要求更新的次数

delay    – 网络延迟

offset   – 时间补偿

jitter   – 系统时间与bios时间差


六.配置时间同步客户机

1.执行ntpdate命令:

ntpdate 192.168.1.101 #192.168.1.101为ntp服务器IP地址

2.写入BIOS

hclock -w

3.crond服务

vi /etc/crontab

30 8 * * * root /usr/sbin/ntpdate 192.168.1.101; /sbin/hwclock -w

4.重启crond服务

service crond restart

原创文章,作者:sjfbjs,如若转载,请注明出处:http://www.178linux.com/54767

(0)
sjfbjssjfbjs
上一篇 2016-10-30 21:02
下一篇 2016-10-30 21:03

相关推荐

  • N25第一周作业

    1.描述计算机的组成及其功能   计算机整体上分为两大部分:     一、硬件部分:运算器,存储器,控制器,输入设备,输出设备     运算器是对数据进行加工处理,主要是指各种算术运算与逻辑运算     存储器是存储各种数据、信号、命令等信息并在他们需要时提供这些信息 &nbsp…

    Linux干货 2016-12-03
  • MySQL半同步配置

    先配置主从服务器,过程见另一篇博库 就是先搭一个主从服务器,然后 1、先在主节点上安装半同步复制的主节点专用插件 MariaDB [(none)]> SHOW PLUGINS;这条命令可以查看有哪些插件可以用 2、从节点也一样先装插件 从节点上先停止线程 STOP SLAVE; 主节点上 从节点上 START SLAVE; 这里需要手动的停止一下线程,…

    Linux干货 2016-11-21
  • 08.02 笔记总结

    1. newgrp 用来临时切换主组。    root 切换, 不需要组密码。    而普通用户切换是需要组密码的。    newgrp 组名  用来切换当前用户的组信息 2. pwunconv     //  将密码的密文复制到/etc/passw…

    Linux干货 2016-08-08
  • 第四周作业

    1. 复制/etc/skel目录为/home/tuser1,要求/home/tuser1以及内部文件的属组和其它用户均没有任何访问权限 cp -r /etc/skel  /home/tuser1 chmod go-rwx /home/tuser1 2. 编辑/etc/group文件,添加组hadoo…

    Linux干货 2016-12-27
  • N22-第五周作业-冥界之王

    1、显示/boot/grub/grub.conf中以至少一个空白字符开头的行;    [root@CentOS6 ~]# cat /boot/grub/grub.conf | grep -E  "^[[:space:]]{1,}"…

    Linux干货 2016-09-19
  • 进入linux世界的初步认识

    1、 描述计算机的组成及其功能.
    2、 按系列罗列Linux的发行版,并描述不同发行版之间的联系与区别.
    3、 描述Linux的哲学思想,并按照自己的理解对其进行解释性描述.
    4、 说明Linux系统上命令的使用格式;详细介绍ifconfig、echo、tty、startx、export、pwd、history、shutdown、poweroff、reboot、hwclock、date命令的使用,并配合相应的示例来阐述.
    5、 如何在Linux系统上获取命令的帮助信息,请详细列出,并描述man文档的章节是如何划分的.
    6、 请罗列Linux发行版的基础目录名称命名法则及功用规定.

    Linux干货 2018-02-25