通過NFS服務共享訪問

<!-- /* Font Definitions */ @font-face {font-family:宋體; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-alt:SimSun; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} @font-face {font-family:"Cambria Math"; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:1; mso-generic-font-family:roman; mso-font-format:other; mso-font-pitch:variable; mso-font-signature:0 0 0 0 0 0;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4; mso-font-charset:0; mso-generic-font-family:swiss; mso-font-pitch:variable; mso-font-signature:-1610611985 1073750139 0 0 159 0;} @font-face {font-family:"/@宋體"; panose-1:2 1 6 0 3 1 1 1 1 1; mso-font-charset:134; mso-generic-font-family:auto; mso-font-pitch:variable; mso-font-signature:3 135135232 16 0 262145 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:""; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋體; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} p {mso-style-noshow:yes; mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0cm; mso-margin-bottom-alt:auto; margin-left:0cm; mso-pagination:widow-orphan; font-size:12.0pt; font-family:宋體; mso-bidi-font-family:宋體;} p.MsoListParagraph, li.MsoListParagraph, div.MsoListParagraph {mso-style-priority:34; mso-style-unhide:no; mso-style-qformat:yes; margin:0cm; margin-bottom:.0001pt; text-align:justify; text-justify:inter-ideograph; text-indent:21.0pt; mso-char-indent-count:2.0; mso-pagination:none; font-size:10.5pt; mso-bidi-font-size:11.0pt; font-family:"Calibri","sans-serif"; mso-ascii-font-family:Calibri; mso-ascii-theme-font:minor-latin; mso-fareast-font-family:宋體; mso-fareast-theme-font:minor-fareast; mso-hansi-font-family:Calibri; mso-hansi-theme-font:minor-latin; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi; mso-font-kerning:1.0pt;} .MsoChpDefault {mso-style-type:export-only; mso-default-props:yes; mso-bidi-font-family:"Times New Roman"; mso-bidi-theme-font:minor-bidi;} /* Page Definitions */ @page {mso-page-border-surround-header:no; mso-page-border-surround-footer:no;} @page Section1 {size:612.0pt 792.0pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:36.0pt; mso-footer-margin:36.0pt; mso-paper-source:0;} div.Section1 {page:Section1;} /* List Definitions */ @list l0 {mso-list-id:1350183042; mso-list-type:hybrid; mso-list-template-ids:838747970 2096528748 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l0:level1 {mso-level-number-format:alpha-upper; mso-level-text:"%1/)"; mso-level-tab-stop:none; mso-level-number-position:left; margin-left:39.0pt; text-indent:-18.0pt;} @list l1 {mso-list-id:2120485736; mso-list-type:hybrid; mso-list-template-ids:-1013284096 -2129602268 67698713 67698715 67698703 67698713 67698715 67698703 67698713 67698715;} @list l1:level1 {mso-level-text:%1); mso-level-tab-stop:none; mso-level-number-position:left; margin-left:18.0pt; text-indent:-18.0pt;} ol {margin-bottom:0cm;} ul {margin-bottom:0cm;} -->

1)  招聘網站系統應用環境圖如下:

2)  設計 Tomcat 服務器 172.21.96.108 NFS 服務器,配置如下:

A)      新建目錄: mkdir /home/share

B)      增加到 root 組: chown root /home/share

注:如果需要共享的目錄已經存在,則不需要上述步驟;

C)      啓動 NFS 服務,運行 setup 命令,在“系統服務”中,找到“ NFS ”選中;

D)      修改 NFS 配置文件 vim  /etc/ exports, 在其中加入以下內容:

/home/share 172.21.96.105(rw,sync) 172.21.96.106(rw,sync) 172.21.96.107(rw,sync) 172.21.96.106(r,sync)

wq 保存

以上參數表明,支持客戶端 172.21.96.105-107 對共享目錄進行讀寫,103 對共享目錄具有隻讀權限。

E)       重啓服務

# /etc/rc.d/init.d/portmap start

( 第一次剛用NFS, 這一步一定要, 不然會出現這樣的錯誤:root_nfs failed, reason given by server: 權限不夠)

/etc/rc.d/init.d/nfs start

F)       驗證:在 172.21.96.105 上執行以下命令,驗證共享服務是否正常

showmount -e 172.21.96.108

如果顯示以下信息說明共享服務配置正常

         Export list for 192.168.102.47:

        /home/share

3)  在客戶端加載共享目錄

分別在每個需要加載共享目錄的機器上執行以下命令:

mount -t nfs172.21.96.108:/home/share /mnt 這條指令表明將目標服務器 172.21.96.108 上的共享目錄 /home/share 加載到客戶端本地 /mnt 下。

4)  卸載共享目錄

Umount /mnt

這條指令表明,將掛在在本地 /mnt 目錄下的共享卸載掉。

5)  開機自動掛載

寫一個 Shell

Vim mount_nfs

寫入以下內容:

mount -t nfs172.21.96.108:/home/share /mnt

wq 保存

chmod 777 mount_nfs 設置可執行權限

cp mount_nfs /usr/sbin/ shell 文件 copy 到可執行目錄下

Vim /etc/rc.d/rc.local

增加一行 mount_nfs

Wq 保存

6)  Exports 文件配置參數語法

這個文件的內容非常簡單,每一行由拋出路徑,客戶名列表以及每個客戶名後緊跟的訪問選項構成: 共享的目錄] [ 主機名或IP( 參數, 參數)]

其中參數是可選的,當不指定參數時,nfs 將使用默認選項。默認的共享選項是 sync,ro,root_squash,no_delay

當主機名或IP 地址爲空時,則代表共享給任意客戶機提供服務。

當將同一目錄共享給多個客戶機,但對每個客戶機提供的權限不同時,可以這樣:

      [ 共享的目錄] [ 主機名1IP1( 參數1, 參數2)] [ 主機名2IP2( 參數3, 參數4)]

下面是一些NFS 共享的常用參數:

    ro                      只讀訪問

  rw                      讀寫訪問

  sync                    所有數據在請求時寫入共享

  async                   NFS 在寫入數據前可以相應請求

   secure                  NFS 通過1024 以下的安全TCP/IP 端口發送

  insecure                NFS 通過1024 以上的端口發送

  wdelay                  如果多個用戶要寫入NFS 目錄,則歸組寫入(默認)

     no_wdelay                如果多個用戶要寫入NFS 目錄,則立即寫入,當使用async 時,無需此設置。

     hide                    NFS 共享目錄中不共享其子目錄

     no_hide                 共享NFS 目錄的子目錄

       subtree_check           如果共享/usr/bin 之類的子目錄時,強制NFS 檢查父目錄的權限(默認)

      no_subtree_check        和上面相對,不檢查父目錄權限

     all_squash              共享文件的UIDGID 映射匿名用戶anonymous ,適合公用目錄。

    no_all_squash           保留共享文件的UIDGID (默認)

    root_squash             root 用戶的所有請求映射成如anonymous 用戶一樣的權限(默認)

     no_root_squas           root 用戶具有根目錄的完全管理訪問權限

       anonuid=xxx             指定NFS 服務器/etc/passwd 文件中匿名用戶的UID

    anongid=xxx             指定NFS 服務器/etc/passwd 文件中匿名用戶的GID
發佈了93 篇原創文章 · 獲贊 5 · 訪問量 43萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章