歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux基礎 >> Linux技術 >> NFS網絡文件共享設置

NFS網絡文件共享設置

日期:2017/3/3 13:08:33   编辑:Linux技術

NFS網絡文件共享服務,一般用來linux之間共享資源

配置步驟

1.編輯/etc/exports

通過編輯/etc/exports來定義需要共享的文件,以及共享給誰[root@node2 ~]# mkdir /nfs_share

[root@node2 ~]# mkdir /nfs_orabak

[root@node2 ~]# cd /nfs_share/

[root@node2 nfs_share]# echo sssss >r.test

[root@node2 nfs_share]# ls

r.test

[root@node2 nfs_share]# cd /nfs_orabak/

[root@node2 nfs_orabak]# echo ssss >rw.test

[root@node2 nfs_orabak]# ls

rw.test

[root@node2 ~]# vim /etc/exports

/nfs_orabak 192.168.100.11/24(rw,no_root_squash)

/nfs_share *

第一行代表只允許客戶端192.168.100.11掛載,並且擁有讀寫權限

第二行的代表允許所有客戶端訪問,默認權限是只讀

參數no_root_squash 其作用是:登入 NFS 主機使用分享目錄的使用者,如果是 root 的話,那麼對於這個分享的目錄來說,他就具有root 的權限。默認情況使用的是相反參數root_squash:在登入 NFS 主機使用分享之目錄的使用者如果是 root 時,那麼這個使用者的權限將被壓縮成為匿名使用者,通常他的UID 與 GID 都會變成 nobody 那個身份。

2.啟動NFS服務

如果NFS未安裝需先安裝yum install nfs*先把防火牆服務關閉,後續需要再啟動

[root@node2 ~]# /etc/init.d/iptables stop

[root@node2 ~]# /etc/init.d/ip6tables stop

[root@node2 ~]# chkconfig iptables off

[root@node2 ~]# chkconfig ip6tables off

[root@node2 ~]# chkconfig --list iptables

iptables 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉

[root@node2 ~]# chkconfig --list ip6tables

ip6tables 0:關閉 1:關閉 2:關閉 3:關閉 4:關閉 5:關閉 6:關閉

[root@node2 ~]# service nfs start

啟動 NFS 服務: exportfs: No options for /nfs_share *: suggest *(sync) to avoid warning

[確定]

關掉 NFS 配額: [確定]

啟動 NFS 守護進程: [確定]

啟動 NFS mountd: [確定]

[root@node2 ~]#

上面的提示表示/nfs_share那行表示,建議添加(sync)同步的參數

[root@node2 ~]# chkconfig --level 35 nfs on

[root@node2 ~]# chkconfig --list nfs

nfs 0:關閉 1:關閉 2:關閉 3:啟用 4:關閉 5:啟用 6:關閉

3.客戶端查看服務端共享信息

客戶端使用命令showmount –e IP來查看服務器端共享的NFS文件信息客戶端使用命令rpcinfo –p IP來查看服務器端rpc協議的工作狀態,nfs底層依賴於portmapper協議,通過rpc可以訪問portmapper,其中端口號都是隨機的,如果我們通過showmount看不到任何信息輸出的時候,需要用rpcinfo來查看底層portmapper是否是正常工作的,如果不正常工作,rpc服務是不正常的。如果rpc是正常的,通過showmount看不到信息是配置有問題。

[root@node1 ~]# showmount -e 192.168.100.12

Export list for 192.168.100.12:

/nfs_share *

/nfs_orabak 192.168.100.11/24

[root@node1 ~]# rpcinfo -p 192.168.100.12

程序 版本 協議 端口

100000 2 tcp 111 portmapper

100000 2 udp 111 portmapper

100024 1 udp 621 status

100024 1 tcp 624 status

100011 1 udp 878 rquotad

100011 2 udp 878 rquotad

100011 1 tcp 881 rquotad

100011 2 tcp 881 rquotad

100003 2 udp 2049 nfs

100003 3 udp 2049 nfs

100003 4 udp 2049 nfs

100021 1 udp 25200 nlockmgr

100021 3 udp 25200 nlockmgr

100021 4 udp 25200 nlockmgr

100003 2 tcp 2049 nfs

100003 3 tcp 2049 nfs

100003 4 tcp 2049 nfs

100021 1 tcp 20385 nlockmgr

100021 3 tcp 20385 nlockmgr

100021 4 tcp 20385 nlockmgr

100005 1 udp 892 mountd

100005 1 tcp 895 mountd

100005 2 udp 892 mountd

100005 2 tcp 895 mountd

100005 3 udp 892 mountd

100005 3 tcp 895 mountd

4.客戶端掛載

[root@node1 ~]# mkdir /node2_nfs[root@node1 ~]# mkdir /node2_orabak

[root@node1 ~]# mount 192.168.100.12:/nfs_share /node2_nfs

[root@node1 ~]# mount 192.168.100.12:/nfs_orabak /node2_orabak

[root@node1 ~]# df -Th

文件系統 類型 容量 已用 可用 已用% 掛載點

/dev/sda3 ext3 93G 10G 79G 12% /

/dev/sda1 ext3 190M 12M 169M 7% /boot

tmpfs tmpfs 2.0G 792M 1.3G 39% /dev/shm

192.168.100.12:/nfs_share

nfs 93G 7.0G 82G 8% /node2_nfs

192.168.100.12:/nfs_orabak

nfs 93G 7.0G 82G 8% /node2_orabak

如果需要開機掛載:

vim /etc/fstab 添加如下內容

192.168.100.12:/nfs_share /node2_nfs nfs defaults 0 0

192.168.100.12:/nfs_orabak /node2_orabak nfs defaults 0 0

5.測試

[root@node1 ~]# cd /node2_nfs/[root@node1 node2_nfs]# echo aaaa >>a.txt

-bash: a.txt: 只讀文件系統

[root@node1 node2_nfs]# ll

總計 4

-rw-r--r-- 1 root root 6 05-07 22:26 r.test

[root@node1 node2_nfs]# cat r.test

sssss

[root@node1 node2_nfs]# cd /node2_orabak/

[root@node1 node2_orabak]# echo aaa >>a.txt

[root@node1 node2_orabak]# ll

總計 8

-rw-r--r-- 1 root root 4 05-07 22:29 a.txt

-rw-r--r-- 1 root root 5 05-07 22:27 rw.test

[root@node1 node2_orabak]# cat rw.test

ssss

下面是oracle導出測試:

[root@node1 node2_orabak]# su - oracle

[oracle@node1 ~]$ exp \'/ as sysdba\' file=/node2_orabak/scott.dmp log=/node2_orabak/scott.log owner=scott

Export: Release 11.2.0.1.0 - Production on Sat May 7 22:32:05 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

EXP-00028: failed to open /node2_orabak/scott.log for write

EXP-00000: Export terminated unsuccessfully

[oracle@node1 ~]$ exit

[root@node1 node2_orabak]# chown -R oracle:oinstall /node2_orabak/

[root@node1 node2_orabak]# su - oracle

[oracle@node1 ~]$ exp \'/ as sysdba\' file=/node2_orabak/scott.dmp log=/node2_orabak/scott.log owner=scott

Export: Release 11.2.0.1.0 - Production on Sat May 7 22:35:09 2016

Copyright (c) 1982, 2009, Oracle and/or its affiliates. All rights reserved.

Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production

With the Partitioning, OLAP, Data Mining and Real Application Testing options

Export done in AL32UTF8 character set and AL16UTF16 NCHAR character set

server uses ZHS16GBK character set (possible charset conversion)

About to export specified users ...

. exporting pre-schema procedural objects and actions

. exporting foreign function library names for user SCOTT

. exporting PUBLIC type synonyms

. exporting private type synonyms

. exporting object type definitions for user SCOTT

About to export SCOTT's objects ...

. exporting database links

. exporting sequence numbers

. exporting cluster definitions

. about to export SCOTT's tables via Conventional Path ...

. . exporting table DEPT 4 rows exported

EXP-00091: Exporting questionable statistics.

EXP-00091: Exporting questionable statistics.

. . exporting table EMP 14 rows exported

EXP-00091: Exporting questionable statistics.

EXP-00091: Exporting questionable statistics.

. . exporting table SALGRADE 5 rows exported

EXP-00091: Exporting questionable statistics.

. exporting synonyms

. exporting views

. exporting stored procedures

. exporting operators

. exporting referential integrity constraints

. exporting triggers

. exporting indextypes

. exporting bitmap, functional and extensible indexes

. exporting posttables actions

. exporting materialized views

. exporting snapshot logs

. exporting job queues

. exporting refresh groups and children

. exporting dimensions

. exporting post-schema procedural objects and actions

. exporting statistics

Export terminated successfully with warnings.

[root@node2 nfs_orabak]# ll -h

總計 36K

-rw-r--r-- 1 oracle oinstall 4 05-07 22:29 a.txt

-rw-r--r-- 1 oracle oinstall 5 05-07 22:27 rw.test

-rw-r--r-- 1 oracle oinstall 24K 05-07 22:35 scott.dmp

-rw-r--r-- 1 oracle oinstall 1.8K 05-07 22:35 scott.log

[root@node2 nfs_orabak]# cat rw.test

ssss

Copyright © Linux教程網 All Rights Reserved