--第一步,安装软件
[root@serv01 ~]#
yum install nfs* -y
--第二步,修改配置文件
[root@serv01 ~]# vim /etc/exports
[root@serv01 ~]# cat /etc/exports
/share *(ro)
#共享目录 共享
IP地址或者网段 共享参数
[root@serv01 ~]# mkdir /share
--第三步,重启服务
[root@serv01 ~]# /etc/init.d/rpcbind restart
Stopping rpcbind: [ OK ]
Starting rpcbind: [ OK ]
[root@serv01 ~]# /etc/init.d/nfs restart
Shutting down NFS
mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@serv01 ~]# exportfs -v
/share <world>(ro,wdelay,root_squash,no_subtree_check)
--第四步,serv02挂载
#serv02
[root@serv02 ~]# mount192.168.1.11:/share /mnt
mount: wrong fs type, bad option, badsuperblock on 192.168.1.11:/share,
missing codepage or helper program, or other error
(for several filesystems (e.g. nfs, cifs) you might
need a /sbin/mount.<type> helper program)
In some cases useful info is found in syslog - try
dmesg | tail or so
#出现这个错误,安装nfs相关的包
[root@serv02 ~]# yum install nfs* -y
[root@serv02 ~]# mount 192.168.1.11:/share/mnt
[root@serv02 ~]# cd /mnt
[root@serv02 /]# umount /mnt
[root@serv02 /]# mkdir /data
[root@serv02 /]# mount 192.168.1.11:/share/data
[root@serv02 /]# df -h
Filesystem Size U
sed Avail Use% Mounted on
/dev/sda2 9.7G 1.1G 8.1G 12% /
tmpfs 188M 0 188M 0% /dev/shm
/dev/sda1 194M 25M 160M 14% /boot
/dev/sda5 4.0G 137M 3.7G 4% /opt
/dev/sr0 3.4G 3.4G 0 100% /iso
192.168.1.11:/share 9.7G 1.1G 8.1G 12% /data
--第五步,拷贝文件
#serv01
[root@serv01 share]# cp /boot/* . -rvf
[root@serv02 /]# cd /data
[root@serv02 data]# ll
total 18592
-rw-r--r--. 1 4294967294 4294967294 100182 Aug 12 21:45config-2.6.32-131.0.15.el6.x86_64
drwxr-xr-x. 3 4294967294 4294967294 4096Aug 12 21:45 efi
drwxr-xr-x. 2 4294967294 4294967294 4096 Aug 12 21:45
grub
-rw-r--r--. 1 4294967294 4294967294 12587318Aug 12 21:45 initramfs-2.6.32-131.0.15.el6.x86_64.img
drwx------. 2 4294967294 4294967294 4096 Aug 12 21:45 lost+found
-rw-r--r--. 1 4294967294 4294967294 165812 Aug 12 21:45symvers-2.6.32-131.0.15.el6.x86_64.gz
-rw-r--r--. 1 4294967294 4294967294 2278446 Aug 12 21:45System.map-2.6.32-131.0.15.el6.x86_64
-rwxr-xr-x. 1 4294967294 4294967294 3881120 Aug 12 21:45 vmlinuz-2.6.32-131.0.15.el6.x86_64
[root@serv02 data]# cpvmlinuz-2.6.32-131.0.15.el6.x86_64 /root -rvf
`vmlinuz-2.6.32-131.0.15.el6.x86_64' ->`/root/vmlinuz-2.6.32-131.0.15.el6.x86_64'
#不能创建文件,修改配置文件
[root@serv02 data]# touch aa01.txt
touch: cannot touch `aa01.txt': Read-onlyfile system
[root@serv01 share]# vim /etc/exports
[root@serv01 share]# cat /etc/exports
/share *(rw)
#重启服务
[root@serv01 share]# /etc/init.d/nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
#没有权限解决
[root@serv02 data]# touch aa01.txt
touch: cannot touch `aa01.txt': Permissiondenied
[root@serv01 share]# ls -l /share/ -d
drwxr-xr-x. 5 root root 4096 Aug 12 21:45/share/
[root@serv01 share]# chmod 777 /share
[root@serv01 share]# ls -l /share/ -d
drwxrwxrwx. 5 root root 4096 Aug 12 21:45/share/
[root@serv02 data]# touch aa01.txt
[root@serv02 data]# ll aa01.txt
-rw-r--r—. 1 4294967294 4294967294 0 Aug 1221:50 aa01.txt
#mount过去后不再是root用户
[root@serv01 share]# ll aa01.txtconfig-2.6.32-131.0.15.el6.x86_64
-rw-r--r--. 1 nfsnobody nfsnobody 0 Aug 12 21:50 aa01.txt
-rw-r--r—. 1 root root 100182 Aug 12 21:45 config-2.6.32-131.0.15.el6.x86_64
#普通用户默认不切换身份
#添加用户
[root@serv02 data]# useradd zhink
#切换到普通用户
[root@serv02 data]# su - zhink
[zhink@serv02 ~]$ cd /data
#创建文件
[zhink@serv02 data]$ touch aa02.txt
[zhink@serv02 data]$ ll aa02.txt
-rw-rw-r—. 1 4294967294 4294967294 0 Aug 1221:57 aa02.txt
#共享目录里查看文件权限
[root@serv01 share]# useradd zhink
[root@serv01 share]# ll aa02.txt
-rw-rw-r—. 1 zhink zhink 0 Aug 12 21:57aa02.txt
#serv02删除用户,发现用户变成编号了
[root@serv01 share]# userdel zhink -rf
[root@serv01 share]# ll aa02.txt
-rw-rw-r—. 1 500 500 0 Aug 12 21:57 aa02.txt
#添加新用户,发现文件的拥有者和组又变成新添加的用户,也就是没法区分
[root@serv01 share]# useradd larry
[root@serv01 share]# ll aa02.txt
-rw-rw-r—. 1 larry larry 0 Aug 12 21:57aa02.txt
[root@serv02 ~]# cd /data
[root@serv02 data]# touch aa03.txt
[zhink@serv02 data]$ su -
Password:
[root@serv02 ~]# userdel -rf zhink
[root@serv01 share]# ll aa03.txt
-rw-r--r—. 1 nfsnobody nfsnobody 0 Aug 1222:00 aa03.txt
#root用户不转换
[root@serv01 share]# vim /etc/exports
[root@serv01 share]# cat /etc/exports
/share *(rw,no_root_squash)
[root@serv01 share]# /etc/init.d/nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Shutting down NFS services: [ OK ]
Starting NFS services: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
#重新挂载
[root@serv02 data]# cd /
[root@serv02 data]# umount /data
[root@serv02 data]# mount 192.168.1.11:/share/data
#创建文件
[root@serv02 data]# touch aa04.txt
#查看文件属性,发现变化成root用户
[root@serv01 share]# ll aa04.txt
-rw-r--r--. 1 root root 0 Aug 12 22:03 aa04.txt
#查看帮助文件
[root@serv01 share]# man exports
#远程接口调用,NFS借助此服务
[root@serv01 share]# /etc/init.d/rpcbindrestart
#映射成其他用户
[root@serv01 share]# useradd linux
[root@serv01 share]# id linux
uid=501(linux) gid=501(linux)groups=501(linux)
[root@serv01 share]# vim /etc/exports
[root@serv01 share]# cat /etc/exports
/share*(rw,all_squash,anonuid=501,anongid=501)
[root@serv01 share]# /etc/init.d/nfs restart
Shutting down NFS mountd: [ OK ]
Shutting down NFS daemon: [ OK ]
Starting NFS services: [ OK ]
Starting NFS daemon: [ OK ]
Starting NFS mountd: [ OK ]
[root@serv02 /]# umount /data
[root@serv02 /]# mount 192.168.1.11:/share/data
[root@serv02 /]# cd /data
[root@serv02 data]# ll
[root@serv01 share]# ll aa05.txt
-rw-r--r--. 1 linux linux 0 Aug 12 22:14aa05.txt
[root@serv02 data]# useradd larry
[root@serv02 data]# su - larry
[larry@serv02 ~]$ cd /data
[larry@serv02 data]$ touch aa06.txt
[root@serv01 share]# ll aa06.txt
-rw-rw-r--. 1 linux linux 0 Aug 12 22:15aa06.txt