ntp服務配置,詳解!,ntp服務配置詳解

來源:互聯網
上載者:User

ntp服務配置,詳解!,ntp服務配置詳解

  在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,沒有修改過的ntp。conf檔案內同如下:

[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 nomodify 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 (http://www.pool.ntp.org/join.html).

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 server

#broadcastclient                        # broadcast client

#broadcast 224.0.1.1 autokey            # multicast server

#multicastclient 224.0.1.1              # multicast client

#manycastserver 239.255.254.254         # manycast server

#manycastclient 239.255.254.254 autokey # manycast client

 

# Enable public key cryptography.

#crypto

 

includefile /etc/ntp/crypto/pw

 

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

# 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.

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是否開機啟動:[root@localhost ~]# chkconfig --level 35 ntpd on

 

http://www.cnblogs.com/kerrycode/archive/2015/08/20/4744804.html(ntp配置參考檔案)

 

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.