NFS服务器

安装部署

yum install nfs-utils -y

systemctl start nfs
 firewall-cmd --list-all
 firewall-cmd --permanent --add-service=nfs
 firewall-cmd --reload
 firewall-cmd --permanent --add-service=rpc-bind
 firewall-cmd --reload
 firewall-cmd --permanent --add-service=mountd

 firewall-cmd --reload

NFS服务器

  mkdir /westos/nfs -p       #建立目录

    vim /etc/exports              #设置共享目录

NFS服务器

 exportfs -rv    #重新挂载/etc/exports 里面的设置,并将共享的目录显示到屏幕上

NFS服务器

                   -r    #重新挂载/etc/exports 里面的设置

                   -v   #在 export的时候,将共享的目录显示到屏幕上

                   -a   #全部挂载(或卸载) /etc/exports文件中设置

                   -u   #卸载某一目录


客户端:

showmount -a 172.25.254.133        #显示当前主机与客户端NFS连接状态

showmount -e 172.25.254.133        #显示某台主机的/etc/exports 所共享目录数据

NFS服务器

手动挂载

mount 172.25.254.127:/westos/nfs /mnt

挂载出错:

[[email protected] ~]# mount 172.25.254.133:/westos/nfs /mnt    

mount.nfs: an incorrect mount option was specified

NFS服务器

加上相应参数后挂载

mount -o vers=3,nfsvers=3 172.25.254.133:/westos/nfs /mnt          #至于为什么要加这个参数,主要是nfs v4的文件与用户ID对应比较麻烦,容易出现用户属主为nobody的问题

[[email protected] ~]# df
文件系统                      1K-块    已用    可用 已用% 挂载点
/dev/vda1                  10473900 3123308 7350592   30% /
devtmpfs                     927072       0  927072    0% /dev
tmpfs                        942660     140  942520    1% /dev/shm
tmpfs                        942660   17028  925632    2% /run
tmpfs                        942660       0  942660    0% /sys/fs/cgroup
172.25.254.133:/westos/nfs 10473984 3176448 7297536   31% /mnt
NFS服务器

自动挂载:

yum install autofs -y       #安装软件

systemctl restart autofs

挂载:

NFS服务器

 vim /etc/autofs.conf 修改默认挂载时间

NFS服务器

cd /net/172.25.254.127/westos/nfs

cd /net/westos/nfs

NFS服务器

修改挂载位置
  vim /etc/auto.master
/misc   /etc/auto.misc
/westos/linux /etc/auto.nfs                  #默认挂载点的上层目录 

vim /etc/auto.nfs

[[email protected] ~]# cat /etc/auto.nfs
nfs   -rw,noatme  172.25.254.127:/westos/nfs

 systemctl restart autofs.service


cd /net/172.25.254.127
[[email protected] 172.25.254.127]# cd /westos/linux/nfs
[[email protected] nfs]# ls
[[email protected] nfs]# df
Filesystem                 1K-blocks    Used Available Use% Mounted on
/dev/vda1                   10473900 3212016   7261884  31% /
devtmpfs                      493408       0    493408   0% /dev
tmpfs                         508996      80    508916   1% /dev/shm
tmpfs                         508996   13388    495608   3% /run
tmpfs                         508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo            483670    2339    451840   1% /home
172.25.254.127:/westos/nfs  10473984 3145856   7328128
[[email protected] ~]# cd /westos/linux/nfs
[[email protected] nfs]# df
Filesystem                 1K-blocks    Used Available Use% Mounted on
/dev/vda1                   10473900 3212016   7261884  31% /
devtmpfs                      493408       0    493408   0% /dev
tmpfs                         508996      80    508916   1% /dev/shm
tmpfs                         508996   13388    495608   3% /run
tmpfs                         508996       0    508996   0% /sys/fs/cgroup
/dev/mapper/vg0-vo            483670    2339    451840   1% /home

172.25.254.127:/westos/nfs  10473984 3145856   7328128  31% /westos/linux/nfs

NFS服务器

服务段设置权限
 vim /etc/exports
*(sync,rw,)
exportfs -rv
exporting *:/westos/nfs
[[email protected] ~]# cd /westos/linux/nfs
[[email protected] nfs]# touch file
touch: cannot touch ‘file’: Permission denied
服务端

[[email protected] ~]# chmod 777 /westos/nfs

客户端

NFS服务器

/westos/nfs     *(sync,rw,anonuid=1000,anongid=1000)  #该id用户可以读写
[[email protected] nfs]$ touch file
[[email protected] nfs]$ ls
[email protected] nfs]$ touch file
[[email protected] nfs]$ ls
file

[[email protected] nfs]$

NFS服务器

[[email protected] ~]# vim /etc/exports
[[email protected] ~]# exportfs -rv
exporting 172.25.254.200:/westos/nfs
exporting *:/westos/nfs
[[email protected] ~]# cat /etc/exports
/westos/nfs     172.25.254.200(sync,rw,no_root_squash) *(sync,ro)  #200主机可以读写,别的主机只读
[[email protected] ~]$ cd /westos/linux/nfs/
[[email protected] nfs]$ ls
file  file3  file9
[[email protected] nfs]$ touch file8

touch: cannot touch ‘file8’: Read-only file system

NFS服务器