NFS

NFS的应用场景

nfs有很多实际应用场景,以下是一些常用的场景:

  • 多个机器共享一台CDROM或其他设备。这对于在多台机器中安装软件来说更加便宜与方便
  • 在大型网络中,配置一台中心NFS服务器用来放置所有用户的home目录可能会带来便利。这些目录能被输出到网络以便用户不管在哪台工作站上登录,总能得到相同的home目录
  • 不同客户端可在NFS上观看影视文件,节省本地空间
  • 在客户端完成的工作数据,可以备份保存到NFS服务器上用户自己的路径下

NFS的优点

  • 节省本地存储空间,将常用的数据存放在一台NFS服务器上且可以通过网络访问,那么本地终端将可以减少自身存储空间的使用
  • 用户不需要在网络中的每个机器上都建有Home目录,Home目录可以放在NFS服务器上且可以在网络上被访问使用
  • 一些存储设备如软驱、CDROM和Zip(一种高储存密度的磁盘驱动器与磁盘)等都可以在网络上被别的机器使用。这可以减少整个网络上可移动介质设备的数量

NFS的配置

//服务端安装NFS
[root@server ~]# yum -y install nfs-utils
//启动NFS服务器,其中111和2049为固定端口 其他为随机端口
[root@server ~]# systemctl enable rpcbind nfs-server
Created symlink from /etc/systemd/system/multi-user.target.wants/nfs-server.service to /usr/lib/systemd/system/nfs-server.service.
[root@server ~]# systemctl start rpcbind nfs-server
root@server ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      128       *:111                   *:*                  
LISTEN      0      128       *:20048                 *:*                  
LISTEN      0      128       *:22                    *:*                  
LISTEN      0      100    127.0.0.1:25                    *:*                  
LISTEN      0      64        *:2049                  *:*                  
LISTEN      0      128       *:43655                 *:*                  
LISTEN      0      64        *:36649                 *:*                  
LISTEN      0      128      :::111                  :::*                  
LISTEN      0      128      :::20048                :::*                  
LISTEN      0      128      :::22                   :::*                  
LISTEN      0      100     ::1:25                   :::*                  
LISTEN      0      64       :::34145                :::*                  
LISTEN      0      64       :::2049                 :::*                  
LISTEN      0      128      :::39687                :::*                  
//创建共享文件目录 所有用户都可以用
[root@server ~]# mkdir -p /nfs/shared
[root@server ~]# vim /etc/exports
[root@server ~]# cat /etc/exports
/nfs/shared
[root@server ~]# cd /nfs/shared/
[root@server shared]# touch hehe
//在客户端查看
[root@client ~]# mount -t nfs 192.168.194.129:/nfs/shared /gongxiang/
[root@client ~]# df -Th
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root       xfs        17G  1.1G   16G    7% /
devtmpfs                    devtmpfs  901M     0  901M    0% /dev
tmpfs                       tmpfs     912M     0  912M    0% /dev/shm
tmpfs                       tmpfs     912M  8.7M  903M    1% /run
tmpfs                       tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda1                   xfs      1014M  143M  872M   15% /boot
tmpfs                       tmpfs     183M     0  183M    0% /run/user/0
/dev/sr0                    iso9660   3.8G  3.8G     0  100% /mnt
192.168.194.129:/nfs/shared nfs4       17G  1.2G   16G    7% /gongxiang
[root@client ~]# cd /gongxiang/
[root@client gongxiang]# ls
hehe
[root@client gongxiang]# showmount -e 192.168.194.129
Export list for 192.168.194.129:
/nfs/shared *
//创建一个新共享目录 只给客户机使用并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300
[root@server ~]# mkdir /nfs/upload
[root@server ~]# vim /etc/exports
[root@server ~]# cat /etc/exports
/nfs/shared
/nfs/upload 192.168.194.0/24(rw,anonuid=300,anongid=300)
[root@server ~]# cd /nfs/upload/
[root@server upload]# touch haha
[root@server upload]# ls
haha
[root@server ~]# groupadd -g 300 nfs-upload
[root@server ~]# useradd -g 300 -u 300 nfs-upload
//客户机命令
[root@client ~]# mount -t nfs 192.168.194.129:/nfs/upload /gx2/
[root@client ~]# df -Th
文件系统                    类型      容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root       xfs        17G  1.1G   16G    7% /
devtmpfs                    devtmpfs  901M     0  901M    0% /dev
tmpfs                       tmpfs     912M     0  912M    0% /dev/shm
tmpfs                       tmpfs     912M  8.7M  904M    1% /run
tmpfs                       tmpfs     912M     0  912M    0% /sys/fs/cgroup
/dev/sda1                   xfs      1014M  143M  872M   15% /boot
tmpfs                       tmpfs     183M     0  183M    0% /run/user/0
/dev/sr0                    iso9660   3.8G  3.8G     0  100% /mnt
192.168.194.129:/nfs/upload nfs4       17G  1.2G   16G    7% /gx2
[root@client ~]# cd /gx2/
[root@client gx2]# touch 123
touch: 无法创建"123": 权限不够
//权限不够回到服务端 修改目录属组属主
[root@server ~]# chown -R nfs-upload.nfs-upload /nfs/upload/
[root@server ~]# systemctl restart nfs-server
//回到客户端
[root@client ~]# umount /gx2/
[root@client ~]# mount -t nfs 192.168.194.129:/nfs/upload /gx2/
[root@client gx2]# touch hehe
[root@client gx2]# ll
总用量 0
-rw-r--r--. 1 300 300 0 10月 24 15:47 haha
-rw-r--r--. 1 300 300 0 10月 24 16:09 hehe

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值