NTP服務搭建

2021-10-05 04:23:05 字數 3769 閱讀 3888

[root@bogon ~]

# yum -y install ntp ntpdate.x86_64

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

#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

server 127.127.1.0 iburst

fudge 127.127.1.0 stratum 10

server

作用:指定ntp伺服器的位址

格式:server [ip or hostname] [perfer]

例子:server 127.127.1.0 《將當前主機作為時間伺服器

fudge

作用:設定時間伺服器的層級

格式:fudge ip [startnum int]

例子:fudge 10.225.5.1 startnum 10

注意:fudge必須和server一塊用, 而且是在server的下一行

startnum

0~15

0:表示頂級

10:通常用於給區域網主機提供時間服務

[root@bogon ~]

# systemctl restart ntpd

[root@bogon ~]

# systemctl status ntpd

[root@bogon ~]

# ntpq -p

remote refid st t when poll reach delay offset jitter

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

==*local(0) .locl. 10 l 19 64 377 0.000 0.000 0.000

[root@bogon ~]

# systemctl enable ntpd

created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

[root@bogon wo]

# yum -y install ntp ntpdate.x86_64

[root@bogon wo]

# systemctl start ntpd

[root@bogon wo]

# systemctl enable ntpd

created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.

3、修改配置檔案,將剛剛搭建好的ntp伺服器作為客戶端上游時間伺服器

將下面

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

修改為#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

server 192.168.2.10 iburst

restrict 192.168.2.10 nomodify notrap noquery

192.168.2.10為ntp伺服器ip

restrict

作用:對ntp做許可權控制

格式:restrict [ip] [mask] [par]

par:

ignore:忽略所有型別的ntp連線請求

nomodify:限制客戶端不能使用命令ntpc和ntpq來修改伺服器端的時間

noquery:不提供ntp網路校時服務

notrap:不接受遠端登入請求

notrust:不接受沒有經過認證的客戶端的請求

【如果沒有用任何引數,那麼表示不做任何限制】

例子:restrict 10.220.5.0 mask 255.255.255.0 nomodify 《允許10.220.5.0/24 網段主機進行時間同步

4、跟ntp伺服器時間同步一下

[root@bogon wo]

# ntpdate -u 192.168.2.10

17 apr 19:59:59 ntpdate[13730]: adjust time server 192.168.2.10 offset 0.128113 sec

[root@bogon wo]

# systemctl restart ntpd

[root@bogon wo]

# ntpq -p

remote refid st t when poll reach delay offset jitter

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

====

==*bogon local(0) 11 u 1 64 3 0.235 22.965 14.293

[root@bogon ~]

# crontab -e

10 06 * * * /usr/sbin/ntpdate -u 192.168.2.10 >> /usr/local/logs/crontab/ntpdate.log

注:192.168.2.10是ntp伺服器ip

NTP服務搭建

restrict 192.168.2.0 mask 255.255.255.0 nomodify 允許192.168.2.0段的機器同步時間,nomodify 表明客戶端不可以修改伺服器的位址 server 202.120.2.101 上海交大 server s2m.time.edu.cn 北京大學...

搭建NTP 伺服器

一 用centos 6.0來搭建ntp伺服器 先只說步驟不說原理,搭建的過程都是在vmware下完成的,我的元件步驟是 1 先安裝好系統,然後開始檢視系統有沒有安裝ntp伺服器元件,用 rmp qa grep ntp 命令來檢視,結果中包 含 ntp 4.2 什麼什麼,說明 ntp 軟體已經裝好了,...

Linux下NTP服務搭建

檢查是否安裝ntp root jie rpm q ntp ntp 4.2.2p1 7.el5 root jie yum y install ntp yum安裝 root jie rpm ivh ntp.rpm rpm 已有包 安裝完成以後編輯配置檔案 etc ntp.conf root jie vi...