共享服務器配置與客戶端掛載

<!-- /* 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:宋體;} .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:595.3pt 841.9pt; margin:72.0pt 90.0pt 72.0pt 90.0pt; mso-header-margin:42.55pt; mso-footer-margin:49.6pt; mso-paper-source:0; layout-grid:15.6pt;} div.Section1 {page:Section1;} -->

服務器端配置

創建共享目錄

        # mkdir /home/share

        # chown root /home/share

創建或修改/etc/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

配置文件/etc/exports 內容如下:

        $ cat /etc/exports

 

        /home/share 192.168.102.15(rw,sync) 192.168.102.16(rw,sync) 。。。

配置說明: 對192.168.102.15 賦予讀寫權限,其他機器僅有隻讀權限。

重啓NFS 服務

         # /etc/init.d/nfs-kernel-server restart

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

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

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

 

在客戶機上查看NFS 的資源共享情況

        # showmount -e 192.168.102.47

 

        Export list for 192.168.102.47:

        /home/share (everyone)

使用mount 命令即可掛栽共享資源

在客戶機 192.168.102.15 上加載共享資源

        # mount 192.168.102.47:/home/share /mnt

 

        # cd /mnt

       

        # echo '12345'> 123

即可發現對服務器共享目錄可寫

        # umount /mnt

在客戶機 192.168.102.61 上加載共享資源

        # mount 192.168.102.47:/home/share /mnt

 

        # cd /mnt

 

        # ls

        123

 

        # touch 321

 

        touch: cannot touch `321': Permission denied

 

        # echo '123455' >123

 

        -bash: 123: Permission denied

即可發現對服務器共享目錄只有讀取權限,

這與我們在服務器端的權限設置是相符的。

是不是我們每次修改了配置文件都需要重啓nfs 服務呢? 這個時候我們就可以用exportfs 命令重新掃描/etc/exports 文件,來使改動立刻生效。

比如:

        # exportfs -au 卸載所有共享目錄

 

        # exportfs -rv 重新共享所有目錄並輸出詳細信息

exportfs 命令有軟件包 nfs-kernel-server 提供,詳細的 exportfs 命令說明請查看:

        man exportfs

中文的手冊說明可以查看這裏:

exportfs 聯機手冊

當完成資源共享, 我們如何知道發佈了哪些權限呢?這時我們可以查看 /var/lib/nfs/etab 文件,它是有 exportfs 命令根據 /etc/exports 生成的。

        # cat /var/lib/nfs/etab

 

        /home/share     192.168.102.15(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

        /home/share     *(ro,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,subtree_check,secure_locks,acl,mapping=identity,anonuid=65534,anongid=65534)

現在我們來查看服務器上有關NFS 服務器啓動了哪些端口:

        tonybox:/home/share# lsof -i|grep rpc

        portmap   1931 daemon    3u  IPv4   4289       UDP *:sunrpc

        portmap   1931 daemon    4u  IPv4   4290       TCP *:sunrpc (LISTEN)

        rpc.statd 3206  statd    3u  IPv4   7081       UDP *:1029

        rpc.statd 3206  statd    6u  IPv4   7072       UDP *:838

        rpc.statd 3206  statd    7u  IPv4   7085       TCP *:1031 (LISTEN)

        rpc.mount 3483   root    6u  IPv4   7934       UDP *:691

        rpc.mount 3483   root    7u  IPv4   7937       TCP *:694 (LISTEN)

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章