Linux使用入门教程之Rsyslog日志管理、NTP和Rsync备份(2)

四、NTP(网络时间协议)
NTP(Network Time Protocol)是用来使计算机时间同步化的一种协议,它可以使计算机系统与NTP服务器或时钟源(如石英钟,GPS等等)进行同步化的一种协议,它可以提供高精准度的时间校正。ntp服务器默认监听UTP 123端口。
1、搭建时间同步服务器(NTP)(IP:192.168.0.1),并让它与外部时间服务器同步,内部的其他服务器以这台NTP作为标准时间,有两种配置:
1>.允许所有IP进行时间同步(默认)
restrict default kod nomodify notrap nopeer noquery restrict default modify notrap
2>.只允许网段IP进行时间同步
restrict 192.168.2.0 mask 255.255.255.0 nomodify notrap
2、NTP安装与配置
yum install -y ntp
service ntpd restart #不需要配置,启动即可
iptables -I INPUT -p udp --dport 123 -j ACCEPT #ntp使用upd协议123端口,设置允许规则

3、客户端同步NTP服务器
1 ntpdate 192.168.0.1

设置自动同步

crontab -e
00 21 * * * /usr/sbin/ntpdate 192.168.0.1; /sbin/hwclock -w  #设置每天晚上9点同步,hwclock -w 将系统时间写入系统硬件

客户端刚开始同步会报错:ntpdate[1731]: step time server 192.168.0.202 offset -28797.853105 sec
这是因为NTP本身时间没有和Internet时间同步,这个过程需要5分钟以上,使用watch ntpq -p命令查看显示如下信息说明已经同步

Linux使用入门教程之Rsyslog日志管理、NTP和Rsync备份

ntp主配置文件

grep -v "^#" /etc/ntp.conf |grep -v "^$"
driftfile /var/lib/ntp/drift
restrict default kod nomodify notrap nopeer noquery  #限制其他计算机查询、修改本机上的NTP服务,其中default表示所有IP
restrict -6 default kod nomodify notrap nopeer noquery #应用于IPV6地址的主机
restrict 127.0.0.1 #开放本机内部接口,用于反馈;以便于在本地对NTP服务进行监控及配置
restrict -6 ::1  #开放这个网段,不能修改;即允许192.168.1.0/24网段的NTP客户端都可以用本机的NTP服务器进行网络校时,但不允许它们修改本机的NTP服务配置
server 0.CentOS.pool.ntp.org #指定真实上层NTP服务器
server 1.centos.pool.ntp.org
server 2.centos.pool.ntp.org
includefile /etc/ntp/crypto/pw

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/19146.html