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


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

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


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


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

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

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

                   -u   #卸载某一目录


客户端:

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

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


手动挂载

mount 172.25.254.127:/westos/nfs /mnt

挂载出错:

[root@150 ~]# mount 172.25.254.133:/westos/nfs /mnt    

mount.nfs: an incorrect mount option was specified


加上相应参数后挂载

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

[root@150 ~]# 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

自动挂载:

yum install autofs -y       #安装软件

systemctl restart autofs

挂载:


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


cd /net/172.25.254.127/westos/nfs

cd /net/westos/nfs


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

vim /etc/auto.nfs

[root@227 ~]# cat /etc/auto.nfs
nfs   -rw,noatme  172.25.254.127:/westos/nfs

 systemctl restart autofs.service


cd /net/172.25.254.127
[root@227 172.25.254.127]# cd /westos/linux/nfs
[root@227 nfs]# ls
[root@227 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
[root@227 ~]# cd /westos/linux/nfs
[root@227 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


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

[root@127 ~]# chmod 777 /westos/nfs

客户端


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

[student@227 nfs]$


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

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



  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值