溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

ntp時(shí)間服務(wù)器

發(fā)布時(shí)間:2020-07-05 13:32:47 來源:網(wǎng)絡(luò) 閱讀:791 作者:小鐵匠819 欄目:建站服務(wù)器

1NTP時(shí)間服務(wù)器

NTP是網(wǎng)絡(luò)時(shí)間協(xié)議(Network Time Protocol),它是用來同步網(wǎng)絡(luò)中各個(gè)計(jì)算機(jī)的時(shí)間的協(xié)議。

NTP服務(wù)器是用于局域網(wǎng)服務(wù)器時(shí)間同步使用的,可以保證局域網(wǎng)所有的服務(wù)器與時(shí)間服務(wù)器的時(shí)間保持一致,某些應(yīng)用對(duì)時(shí)間實(shí)時(shí)性要求高的必須統(tǒng)一時(shí)間。

基于Client/server模式,udp123端口

 

2、安裝步驟:

2.1、 服務(wù)器端: 

NTP服務(wù)器監(jiān)聽端口為UDP的123,那就需要在本地防火墻開啟運(yùn)行客戶端訪問123端口,vi /etc/sysconfig/iptables添加如下規(guī)則:

-A INPUT -m state --state NEW -m udp -pudp --dport 123 -j ACCEPT

2.1.1、首先關(guān)閉防火墻:   /etc/init.d/iptables stop

     或關(guān)閉Selinux軟件服務(wù): Setenforce 0臨時(shí)關(guān)閉

2.1.2、[root@haikang~]#yum install ntp* -y   //安裝ntp軟件

        [root@haikang ~]# cp /etc/ntp.conf/etc/ntp.conf.bak  //備份ntp主配置文件

        [root@haikang ~]#vi /etc/ntp.conf   //修改ntp主配置文件 

        [root@haikang~]# cat /etc/ntp.conf   //查看主配置文件

          driftfile /var/lib/ntp/drift 

           //在與上級(jí)時(shí)間服務(wù)器聯(lián)系時(shí)所花費(fèi)的時(shí)間,記錄在driftfile參數(shù)后面的文件內(nèi)

restrictdefault kod nomodify notrap nopeer noquery

//允許所有來跟我進(jìn)行同步

          restrict 127.0.0.1  //開啟內(nèi)部遞歸網(wǎng)絡(luò)接口 lo

          restrict 192.168.1.0 mask255.255.255.0 nomodify notrap

           //定義可訪問的內(nèi)部子網(wǎng)客戶端,但不能修改NTP服務(wù)器的時(shí)間參數(shù)。

server 0.centos.pool.ntp.org iburst    

//上級(jí)時(shí)間服務(wù)器

server 127.127.1.0     # local clock//設(shè)置與本機(jī)ntp同步時(shí)鐘

         [root@haikang~]# /etc/init.d/ntpd start 

         //啟動(dòng)ntp服務(wù),客戶端需要幾分鐘后才能同步,否則會(huì)提示錯(cuò)誤.

         [root@haikang ~]# netstat -nulp|grep ntp   //查看是否有ntp進(jìn)程

[root@haikang ~]# ntpq -p   //查看ntp服務(wù)器的上級(jí)服務(wù)器

[root@haikang ~]# watch ntpq -p

     remote           refid      st t when poll reach   delay  offset  jitter

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

 ntp1.ams1.nl.le 130.133.1.10     2 u  15   64  153 337.087  -705047 7050475

注釋:remote -本機(jī)和上層ntp的ip或主機(jī)名,“+”表示優(yōu)先,“*”表示次優(yōu)先

refid  - 參考上一層ntp主機(jī)地址

st    - stratum階層

when   - 多少秒前曾經(jīng)同步過時(shí)間

poll   - 下次更新在多少秒后

reach  - 已經(jīng)向上層ntp服務(wù)器要求更新的次數(shù)

delay  - 網(wǎng)絡(luò)延遲

offset  - 時(shí)間補(bǔ)償

jitter  - 系統(tǒng)時(shí)間與bios時(shí)間差 

    2.2、客戶端:           

[root@localhost ~]# ntpdate172.16.30.12  //與NTP進(jìn)行同步

30 May 01:15:35 ntpdate[1096]: adjust timeserver 172.16.30.12 offset 0.003669 sec

備注:如果客戶機(jī)沒有ntpdate,可以yum –y install ntp 即可!

客戶端創(chuàng)建計(jì)劃任務(wù):

crontab -e  創(chuàng)建客戶端定期同步,需創(chuàng)建計(jì)劃任務(wù)。

如:增加一行,在每天的6點(diǎn)10分與時(shí)間同步服務(wù)器進(jìn)行同步

10(分)  06(時(shí)) *(日) *(月) *(周)/usr/sbin/ntpdate ntp-server的ip (172.16.30.10)>>/usr/local/logs/crontab/ntpdate.log

crontab -l  //查看計(jì)劃任務(wù)

備注:如果客戶機(jī)沒有crontab,可以yum  install cron*  -y 即可。

crontab 主要用來創(chuàng)建計(jì)劃任務(wù)

2.3、ntp客戶端同步時(shí)的錯(cuò)誤解決方案:

[root@localhost~]# ntpdate 172.16.30.12

30 May11:50:29 ntpdate[1136]: no server suitable for synchronization found

   客戶端用[root@localhost~]# ntpdate  -d 172.16.30.12

    錯(cuò)誤1.Serverdropped: no data

        關(guān)閉防火墻或者加入規(guī)則-AINPUT -m state --state NEW -m udp -p udp --dport 123 -j ACCEPT

 


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI