linux ntp同步日志,Linux使用入门教程之Rsyslog日志管理、NTP和Rsync备份同步
四、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命令查看顯示如下信息說明已經同步
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
總結
以上是生活随笔為你收集整理的linux ntp同步日志,Linux使用入门教程之Rsyslog日志管理、NTP和Rsync备份同步的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: linux 网卡 开启dhcp,Linu
- 下一篇: linux磁盘混乱,Linux磁盘设备文