系统平台:
[root@localhost ~]# cat /etc/issue
CentOS release 6.6 (Final)
Kernel \r on an \m
[root@localhost ~]# service iptables status
iptables: Firewall is not running.
[root@localhost ~]# sestatus -v
SELinux status: enabled
setenforce 0 可以临时关闭,但重启之后还是会变成原来的状态。
修改/etc/sysconfig/selinux文件可以永久地禁用它
[root@localhost ~]# vi /etc/sysconfig/selinux
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
#SELINUX=enforcing
SELINUX=disabled
# SELINUXTYPE= can take one of these two values:
# targeted - Targeted processes are protected,
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# rpm -qa |grep nfs
[root@localhost ~]# rpm -qa |grep portmap
[root@localhost ~]#
[root@localhost ~]# yum -y install nfs-utils rpcbind
centos 5 :
yum -y install nfs-utils portmap
centos 6(在CentOS 6.3当中,portmap服务由rpcbind负责) :
yum -y install nfs-utils rpcbind
[root@localhost ~]# service rpcbind start
Starting rpcbind: [ OK ]
[root@localhost ~]# service nfs start
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@localhost ~]#
[root@localhost ~]# mkdir nfs
[root@localhost ~]# cd nfs
[root@localhost nfs]# mkdir test
[root@localhost test]# pwd
/root/nfs/test
[root@localhost ~]# vi /etc/exports
[root@localhost ~]# exportfs -r
注:配置文件说明:
/usr/local/test/ 为共享的目录,使用绝对路径。
192.168.1.15(rw,no_root_squash,no_all_squash,sync) 为客户端的地址及权限,地址可以是一个网段,一个IP地址或者是一个域名,域名支持通配符,如:*.youxia.com,地址与权限中间没有空格,权限说明:
rw:read-write,可读写;
ro:read-only,只读;
sync:文件同时写入硬盘和内存;
async:文件暂存于内存,而不是直接写入内存;
no_root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,也拥有root权限。显然开启这项是不安全的。
root_squash:NFS客户端连接服务端时如果使用的是root的话,那么对服务端分享的目录来说,拥有匿名用户权限,通常他将使用nobody或nfsnobody身份;
all_squash:不论NFS客户端连接服务端时使用什么用户,对服务端分享的目录来说都是拥有匿名用户权限;
anonuid:匿名用户的UID值,通常是nobody或nfsnobody,可以在此处自行设定;
anongid:匿名用户的GID值。
重起服务
[root@localhost ~]# service nfs restart
Shutting down NFS daemon: [ OK ]
Shutting down NFS mountd: [ OK ]
Shutting down NFS services: [ OK ]
Shutting down RPC idmapd: [ OK ]
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@localhost ~]# service rpcbind restart
Stopping rpcbind: [ OK ]
Starting rpcbind: [ OK ]
[root@localhost ~]#
[root@localhost nfs]# mount -t nfs 192.168.1.231:/root/nfs/test/ /root/nfs/test/
mount: wrong fs type, bad option, bad superblock on 192.168.1.231:/root/nfs/test/,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount. helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so
[root@localhost nfs]# yum install nfs-utils
[root@localhost nfs]# ls /sbin/mount*
/sbin/mount.nfs /sbin/mount.nfs4 /sbin/mount.tmpfs
[root@localhost nfs]# mount -t nfs 192.168.1.231:/root/nfs/test/ /root/nfs/test/
[root@localhost nfs]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
192.168.1.231:/root/nfs/test/ on /root/nfs/test type nfs (rw,vers=4,addr=192.168.1.231,clientaddr=192.168.1.232)
[root@localhost ~]# cd nfs/test/
[root@localhost test]# vi aaaa
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 26 Apr 15 17:54 aaaa
[root@localhost test]#
[root@localhost test]# ll
total 4
-rw-r--r--. 1 root root 26 Apr 16 2016 aaaa
七 :解除挂载
[root@localhost ~]# umount /root/nfs/test
[root@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
[root@localhost ~]# umount /root/nfs/test
umount.nfs: /root/nfs/test: device is busy
umount.nfs: /root/nfs/test: device is busy
[root@localhost ~]# fuser -m -v /root/nfs/test
USER PID ACCESS COMMAND
/root/nfs/test: root 1371 ..c.. bash
root 1384 F.c.. vi
[root@localhost ~]# kill -9 1371
[root@localhost ~]# kill -9 1384
[root@localhost ~]# umount /root/nfs/test
[root@localhost ~]# mount
/dev/sda3 on / type ext4 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
tmpfs on /dev/shm type tmpfs (rw,rootcontext="system_u:object_r:tmpfs_t:s0")
/dev/sda1 on /boot type ext4 (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)