Central Standard Time (Australia) UT 9:30
        China Standard Time               UT 8:00
        Cuba Standard Time UT-4:00

二、操作系統上的兩種時間

軟件時鐘:也叫系統時間,根據1970/01/01開始計算的總秒數

查看系統時間:
    [root@node1 ~]# date            #查看當前時間
    Wed Jun 28 19:57:53 CST 2017

    [root@node1 ~]#  date  %Y-%m-%d #設置當前時間格式
    2017-06-28
    
    [root@node1 ~]# date  %Y-%m-%d %H:%M:%S    #設置當前時間格式
    2017-06-28 19:58:42
    
    [root@node1 ~]# date  %s         #從1970/01/01到現在的總秒數
    1498651211
設置時間:


date  -s  20120523 01:01:01   #設置當前系統時間,一般不建議直接在生產主機上執行。
date  -s dd/mm/yyyy hh:mm:ss

硬件時鐘:主機硬件系統上的時鐘。主板上BIOS中的時間,由主板電池供電來維持運行,系統開機時要讀取這個時間,并根據它來設定系統時間.

查看硬件時間: hwclock 或clock
設置: hwclock --set --date=06/18/14 14:55

硬件時間與系統時間相互轉換:

clock --hctosys      #將系統時間調整為目前的硬件時間一致;當Linux啟動時,系統時鐘會去讀取硬件時鐘的設定,之后系統時鐘即獨立運作.
clock --systohc      #將硬件時鐘調整為與目前的系統時鐘一致;將系統時間存回硬件時鐘內

三、NTP服務器安裝與設置

1.所需要的軟件

    ntp      主要軟件  

    tzdata   提供各時區對應的顯示格式

2.相關文件

     /etc/ntp.conf     主配置文件

     /usr/share/zoneinfo/    由tzdata提供,為各時區的時間格式對應文件。

     /etc/sysconfig/clock    設置時區是否使用UTC時鐘的配置文件。

 [root@node1 zoneinfo]# cat /etc/sysconfig/clock 
  ZONE=Asia/Shanghai
 #表明我們的時間配置文件要使用/usr/share/zoneinfo/Asia/Shanghai那個文件

    /etc/localtime     本地端的時間配置文件

簡單的一個例子:
目前在上海,假如到了美國,怎么調整時間?
首先    vim /etc/sysconfig/clock  
        ZONE=America/New_York
然后    cp  /usr/share/zoneinfo/America/New_York    /etc/localtime 
最后    date

3.主配置文件

[root@node1 ~]# cat /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

server 1.cn.pool.ntp.org

#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)driftfile  記錄時間差異

(2)restrict   管理權限控制

restrict   [ip]  mask [netmask_ip]  [parameter]
    parameter主要有:
       ignore:拒絕所有類型的NTP連接
       nomodify:客戶端不能使用ntpc/ntpq來修改服務器的時間參數,但客戶端可以進行網絡校時
       noquery:客戶端不能用ntpq/ntpc來查詢時間服務器,等于不提供NTP的網絡校時
       notrap:不提供trap這個遠程事件登陸
       notrust:拒絕沒有認證的客戶端
       
如果在[parameter] 沒有設置,則表示該網段不受任何限制。

(3)server:設置上層的NTP服務器

server [ip或主機名]  [prefer]

四、服務器NTP服務的啟動

#/etc/init.d/ntpd start    #啟動服務
#chkconfig ntpd on         #開機自啟

#tail /var/log/messages    #查看日志


查看端口:
[root@node1 ~]# netstat -tulnp | grep ntp
udp        0      0 192.168.209.128:123         0.0.0.0:*                               2766/ntpd           
udp        0      0 127.0.0.1:123               0.0.0.0:*                               2766/ntpd           
udp        0      0 0.0.0.0:123                 0.0.0.0:*                               2766/ntpd           
udp        0      0 fe80::20c:29ff:fe67:be62:123 :::*                                    2766/ntpd           
udp        0      0 ::1:123                     :::*                                    2766/ntpd           
udp        0      0 :::123                      :::*                                    2766/ntpd

通常啟動NTP15分鐘后才會和上層NTP服務器順利連接上。


#ntpstat 查看ntp服務器是否與上層連接。
synchronised to NTP server (xx.xx.xx.xx) at stratum 3 
   time correct to within 538 ms
   polling server every 128 s

   
      
[root@node1 ~]# ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 85.199.214.101  .GPS.            1 u   55   64    1  245.097  179.415   0.000

 
remote: NTP主機的IP或者主機名
    * 代表目前正在作用當中的上層NTP
      代表已經連接成功,可以作為下一個提供更新時間的候選者
refid:NTP服務器使用的更高一級服務器的名稱
st: stratum階層
when:幾秒前曾經做過時間同步化更新的操作.上一次成功請求之后到現在的秒數
poll:下一次更新在幾秒鐘之后.本地和遠程服務器多少時間進行一次同步,單位秒,在一開始運行NTP的時候這個poll值會比較小,服務器同步的頻率大,可以盡快調整到正確的時間范圍,之后poll值會逐漸增大,同步的頻率也就會相應減小
reach:已經向上層NTP服務器要求更新的次數.用來測試能否和服務器連接,是一個八進制值,每成功連接一次它的值就會增加
delay:網絡傳輸過程當中延遲的時間.從本地機發送同步要求到ntp服務器的往返時間
offset:時間補償的結果.主機通過NTP時鐘同步與所同步時間源的時間偏移量,單位為毫秒,offset越接近于0,主機和ntp服務器的時間越接近
jitter:Linux系統時間與硬件時間的差異時間。這個數值的絕對值越小,主機的時間就越精確

五、客戶端同步NTP服務器的時間

方法1:
    ntpdate 192.168.209.128
    編輯定時任務crontab,每隔30分鐘自動同步,并寫入硬件時鐘。
    */30  * * * * ( /usr/sbin/ntpdate 192.168.209.128 && hwclock -w ) &>/dev/null
    
方法2:
    修改/etc/ntp.conf配置文件,開啟ntpd服務,使其自動去同步上層ntp服務器。
     添加server 1.cn.pool.ntp.org    
     
     /etc/init.d/ntpd start
     chkconfig ntpd on

更多關于云服務器域名注冊,虛擬主機的問題,請訪問三五互聯官網:m.shinetop.cn

贊(0)
聲明:本網站發布的內容(圖片、視頻和文字)以原創、轉載和分享網絡內容為主,如果涉及侵權請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網站立場,如需處理請聯系客服。郵箱:3140448839@qq.com。本站原創內容未經允許不得轉載,或轉載時需注明出處:三五互聯知識庫 » 9.linux ntp服務器搭建

登錄

找回密碼

注冊

主站蜘蛛池模板: 高清有码国产一区二区| 亚洲国产精品区一区二区| 国产精品中文第一字幕| 镇平县| 成人爽a毛片免费| av午夜福利一片免费看久久| 又爽又黄无遮挡高潮视频网站| 97色成人综合网站| 国产精品国产三级国快看| 精品无码久久久久国产电影| 人人玩人人添人人澡超碰| 亚洲综合国产一区二区三区| 亚洲欧美电影在线一区二区| 亚洲无人区一码二码三码| 亚洲成色精品一二三区| 日本不卡一区| 加勒比无码人妻东京热| 不卡一区二区国产在线| 礼泉县| 久久久久久九九99精品| 久9视频这里只有精品| 久久人人爽人人爽人人av| 亚洲人成网站在线在线观看| 精品国产一区二区三区av性色| 色琪琪丁香婷婷综合久久| 国产精品久久人妻无码网站一区 | 免费可以在线看a∨网站| 18禁一区二区每日更新| 免费看美女被靠到爽的视频| 中文字幕一区二区久久综合| 亚洲欧洲精品日韩av| 陆良县| AV最新高清无码专区| 蜜桃在线一区二区三区| 精品偷拍一区二区三区| 精品人妻码一区二区三区| 在线精品国产成人综合| 天津市| 日韩一区二区三区女优丝袜| 成人动漫综合网| 国产精品自在拍首页视频8|