[root@bogon ~]# yum install -y nfs-utils rpcbind #安裝NFS服務器
[root@bogon ~]# rpm -qa nfs-utils rpcbind #檢查安裝情況
rpcbind-0.2.0-13.el6_9.1.x86_64
nfs-utils-1.2.3-75.el6.x86_6
[root@bogon ~]# setenforce 0 #關閉selinux
[root@bogon ~]# /etc/init.d/iptables stop #關閉防護牆
[root@bogon ~]# /etc/init.d/rpcbind start #首先開啓RPC 服務
[root@bogon ~]# /etc/init.d/nfs start #其次開啓NFS 服務
Starting NFS services: [ OK ]
Starting NFS mountd: [ OK ]
Starting NFS daemon: [ OK ]
Starting RPC idmapd: [ OK ]
[root@bogon ~]# vi /etc/exports #配置NFS服務器掛載參數
/data 10.41.1.0/24(rw,sync)
[root@bogon ~]# showmount -e 10.41.1.80
Export list for 10.41.1.80:
[root@bogon ~]# /etc/init.d/nfs reload #重啓NFS服務
[root@bogon ~]# showmount -e 10.41.1.80 #查看測試掛載
Export list for 10.41.1.80:
/data 10.41.1.0/24
[root@bogon ~]# cat /var/lib/nfs/etab #查看掛載權限
/data 10.41.1.0/24(rw,sync,wdelay,hide,nocrossmnt,secure,root_squash,no_all_squash,no_subtree_check,secure_locks,acl,anonuid=65534,anongid=65534,sec=sys,rw,root_squash,no_all_squash)
[root@bogon ~]# rpcinfo -p localhost
[root@bogon ~]# mount -t nfs 10.41.1.80:/data /mnt # 本地關注測試
[root@bogon ~]# df -h #查看掛載情況
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 189G 741M 179G 1% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 35M 145M 20% /boot
10.41.1.80:/data 189G 741M 179G 1% /mnt
[root@NFS-client01 data2]# mount -t nfs 10.41.1.80:/data /mnt #客戶端掛載
[root@NFS-client01 data2]# df -h
df: `/data1': Stale file handle
df: `/data2': Stale file handle
Filesystem Size Used Avail Use% Mounted on
/dev/sda2 189G 741M 179G 1% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
/dev/sda1 190M 35M 145M 20% /boot
10.41.1.80:/data 189G 741M 179G 1% /mnt
[root@bogon ~]# chown -R nfsnobody.nfsnobody /data/ #權限設置,nfsnobody 配合本地目錄權限管理。
###NFS的RPC服務在Centos5.X下爲portmap,在Centos6.X下爲rpcbind
#########NFS常用文件夾###########
/etc/exports #NFS配置文件
/usr/sbin/exportfs #NFS配置管理命令
[root@bogon ~]# exportfs -rv #加載配置生效相當於 /etc/init.d/nfs reload
/usr/sbin/showmount #常用在客戶端查看NFS配置及掛載結果的命令
[root@bogon ~]# showmount -e 10.41.1.80 #查看掛載情況
/var/lib/nfs/etab #NFS配置文件的完整參數文件(有很多沒有配置但默認卻有的參數)
/proc/mount #記錄客戶端掛載參數文件
重要問題:NFS客戶端普通用戶寫NFS的問題
1、生產場景基本上上都是用的普通用戶
2、要讓普通用戶有寫的權限,需在服務端配置 /etc/exports 中加入 all_quash參數
例如 /data 10.41.1.0/24(rw,sync,all_quash)