首頁  >  文章  >  運維  >  NTP的配置怎麼操作?

NTP的配置怎麼操作?

PHP中文网
PHP中文网原創
2017-06-20 13:17:331808瀏覽

  linux系統中,為了避免主機時間因為長時間運行下所導致的時間偏差,進行時間同步(synchronize#)的工作是非常必要的。 linux系統下,一般會使用ntp服務來同步不同機器的時間。 NTP是網路時間協定(Network Time Protocol)的簡稱,就是透過網路協定使電腦之間的時間同步化。

安裝NTP套件

檢查是否安裝了ntp相關套件。如果安裝ntp相關包,使用rpm#或yum##安裝,非常簡單。

[root@localhost ~]# rpm -qa |grep ntp

fontpackages-filesystem-1.41-1.1.el6.noarch

ntpdate-4.2.6p5 -10.el6.centos.2.i686

ntp-4.2.6p5-10.el6.centos.2.i686

 

NTP的設定

A.

設定/etc/ntp.conf

  NTP server

的主要設定文件為/etc/ntp.conf,沒有修改過的ntpconf檔案內同如下:

[root@localhost ~]# more /etc/ntp.conf

# For more information about this file, see the man pages

# ntp.conf(5), ntp_acc(5), ntp_auth(5), ntp_clock(5), ntp_misc(5), ntp_mon(5).

 

driftfile /var/lib/ntp/drift

# Permit time synchronization with our time source, but do not

# permit the source to query or modify the service on this system.

restrict default kod nomodify notrap nopeer noquery

#restrict -6 default kod no Hmodify notrap nopeer noquery

#> 

# Permit all access over the loopback interface.  This could

# be tightened as well, but to do so would effect some of

# the administrative functions.

restrict 127.0.0.1

restrict -6 ::1

 

# Hosts on local network are less restricted.

##restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

 

# Use public servers from the pool.ntp.org project.

# Please consider joining the pool. #server 0.rhel.pool.ntp.org iburst

server 1.rhel.pool.ntp.org iburst

server 2.rhel.pool.ntp.org iburst

server 3.rhel.pool.ntp.org iburst

 

#broadcast 192.168.1.255 autokey                # broadcast client

#broadcast 224.0.1.1 autokey            # multicast server

#multicastclient 224.0.1.1  239.255.254.254         # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

 

# Enable public key cryptography.

#crypto

 

##et##/et##/et##/et

Bet##et#/et#cude##/et#cude##/et#cude##/et#cude##/et#cude##/et#cude#/et#cude#/et#cude#/et#cude#/et#cude#/et#cude#/et#c3

et#cet#d /ntp/crypto/pw

 

# Key file containing the keys and key identifiers used when operating

## with symmetric key cryptography.

##keys /## with symmetric key cryptography.

##keys /

etc/ntp/keys

 

# Specify the key identifiers which are trusted.

#trustedkey 4 8 42

 

# Specify the key identifier to use with the ntpdc utility.

##requestkey 8

 

## Specify the key identifier to use with the ntpq utility.

#controlkey 8

 

# Enable writing of statistics records.

statistics clockstats cryptostats loopstats peerstats

  1)設定NTP主機來源(其中prefer#表示優先主機),192.168.66.131是本機的NTP伺服器,所以優先指定從該主機同步時間

server 192.168.66.131 prefer

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

  2)限制你允許的這些伺服器的存取類型,在這個例子中的伺服器是不容許修改執行時間配置或查詢您的linux ntp伺服器

#restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap

以上的遮罩位址擴充為255,因此從192.168.1.1-192.168.1.254的伺服器都可以使用我們的NTP伺服器來同步時間

##設定預設策略為允許任何主機進行時間同步

restrict default ignore

  3)確保localhost有足夠權限,使用沒有任何限制關鍵字的語法

#    restrict 127.0.0.1

restrict -6 ::1

 

B.設定/etc/ntp/step-tickers 文件

修改/etc/ntp/step-tickers文件,內容如下(當ntp服務啟動時,會自動與該檔案中記錄的上層NTP服務進行時間校對)

[root@localhost ~]# more /etc /ntp/step-tickers

# List of servers used for initial synchronization.

## List of servers used for initial synchronization.

server 192.168.66.131 prefer

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 以上是透過了

vi

修改

 C.設定/etc /sysconfig/ntpd

檔案ntp服務,預設智慧同步系統時間。如果讓ntp同時同步硬體時間,可以設定/etc/sysconfig/ntpd文件,在/ etc/sysconfig/ntpd檔案中加入,SYNC_HWCLOCK=yes

這樣,就可以讓硬體時間與系統時間一起同步。

 IPTABLES設定

由於ntp服務需要使用到UDP連接埠號碼為123,所以當系統的防火牆(iptables)啟動的情況下,必須開放UDP連接埠號

123

##### ###

啟動NTP服務

#service ntpd status

service ntpd start

netstat -lntup|grep ntp


以上是NTP的配置怎麼操作?的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
上一篇:linux開機步驟下一篇:linux開機步驟