您的位置:首页 > 理论基础 > 计算机网络

NFS网络文件共享设置

2016-05-07 23:16 585 查看
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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: