搭建NFS服务器

搭建环境

  • 服务器地址为192.168.93.130/24,客户端地址为192.168.93.129/24

1.开放/nfs/shared目录,供所有用户查阅资料

  • 在服务端配置:
(1)关闭防火墙
[root@server ~]# systemctl stop firewalld
[root@server ~]# systemctl disable firewalld
[root@server ~]# vim /etc/selinux/config 
[root@server ~]# getenforce 
Enforcing
(2)安装nfs服务
[root@server ~]# yum -y install nfs-utils
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
无须任何处理
(3)启动nfs服务 和 rpcbind
[root@server ~]# systemctl start rpcbind nfs-server
[root@server ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      50       *:139                  *:*                  
LISTEN      0      128      *:111                  *:*                  
LISTEN      0      128      *:20048                *:*                  
LISTEN      0      128      *:57232                *:*                  
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      100    127.0.0.1:25                   *:*                  
LISTEN      0      50       *:445                  *:*                  
LISTEN      0      64       *:2049                 *:*                  
LISTEN      0      64       *:34821                *:*                  
LISTEN      0      50      :::139                 :::*                  
LISTEN      0      128     :::111                 :::*                  
LISTEN      0      128     :::20048               :::*                  
LISTEN      0      64      :::36148               :::*                  
LISTEN      0      128     :::39380               :::*                  
LISTEN      0      128     :::22                  :::*                  
LISTEN      0      100    ::1:25                  :::*                  
LISTEN      0      50      :::445                 :::*                  
LISTEN      0      64      :::2049                :::* 
(4)创建/nfs/shared共享目录
[root@server ~]# mkdir /nfs
[root@server ~]# cd /nfs
[root@server nfs]# ls
[root@server nfs]# mkdir /shared
[root@server nfs]# ls
shared 
(5)修改/etc/exports文件
[root@server ~]# vim /etc/exports
[root@server ~]# cat /etc/exports
/nfs/shared *(ro,sync)
(6)重启nfs
[root@server ~]# systemctl restart nfs-server rpcbind
  • 在客户端配置:
(1)关闭防火墙
[root@jxy ~]# systemctl stop firewalld
[root@jxy ~]# systemctl disable firewalld
[root@jxy ~]# vim /etc/selinux/config 
[root@jxy ~]# getenforce 
Enforcing
(2)搭建nfs服务
[root@jxy ~]# yum -y install nfs-utils
已加载插件:product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
软件包 1:nfs-utils-1.3.0-0.48.el7.x86_64 已安装并且是最新版本
无须任何处理
(3)启动,查看nfs服务
[root@jxy ~]# systemctl start rpcbind nfs-server
[root@jxy ~]# ss -antl
State       Recv-Q Send-Q Local Address:Port               Peer Address:Port              
LISTEN      0      50       *:139                  *:*                  
LISTEN      0      64       *:35661                *:*                  
LISTEN      0      128      *:111                  *:*                  
LISTEN      0      128      *:20048                *:*                  
LISTEN      0      128      *:55761                *:*                  
LISTEN      0      128      *:22                   *:*                  
LISTEN      0      100    127.0.0.1:25                   *:*                  
LISTEN      0      50       *:445                  *:*                  
LISTEN      0      64       *:2049                 *:*                  
LISTEN      0      50      :::139                 :::*                  
LISTEN      0      128     :::45422               :::*                  
LISTEN      0      128     :::111                 :::*                  
LISTEN      0      128     :::20048               :::*                  
LISTEN      0      128     :::22                  :::*                  
LISTEN      0      100    ::1:25                  :::*                  
LISTEN      0      50      :::445                 :::*                  
LISTEN      0      64      :::2049                :::*                  
LISTEN      0      64      :::40258               :::*        
(4)验证nfs服务端的共享目录
[root@jxy ~]# showmount -e 192.168.93.130
Export list for 192.168.93.130:
/nfs/shared 192.168.93.130
(5)创建和挂载共享目录站点
[root@jxy ~]# mkdir /gege
[root@jxy ~]# mount -t nfs 192.168.93.130:/nfs/shared /gege
[root@jxy /]# df -h
文件系统                      容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root          17G  1.7G   16G   10% /
devtmpfs                      901M     0  901M    0% /dev
tmpfs                         912M     0  912M    0% /dev/shm
tmpfs                         912M  8.7M  903M    1% /run
tmpfs                         912M     0  912M    0% /sys/fs/cgroup
/dev/sr0                      3.8G  3.8G     0  100% /mnt
/dev/sda1                    1014M  143M  872M   15% /boot
tmpfs                         183M     0  183M    0% /run/user/0
192.168.93.130:/jiangxiuying   17G  1.7G   16G   10% /nfs
(6)在服务端创建文件或者目录
[root@server ~]# cd /nfs/shared/
[root@server shared]# touch 111
[root@server shared]# ls
111
[root@server shared]# mkdir 222
[root@server shared]# ls
111  222
(7)在客户端查看
[root@jxy ~]# cd /nfs/shared/
[root@jxy shared]# ls
111  222

2.开放/nfs/upload目录为172.16.12.0/24网段的数据上传目录,并将所有用户及所属的用户组都映射为nfs-upload,其UID与GID均为300

  • 在服务端上的配置:
(1)创建/nfs/upload目录
[root@server ~]# cd /nfs
[root@server nfs]# ls
shared
[root@server nfs]# mkdir upload
[root@server nfs]# ls
shared  upload
(2)创建用户nfs-upload,UID和GID为300
[root@server ~]# useradd -r -u 300 nfs-upload
[root@server ~]# id nfs-upload
uid=300(nfs-upload) gid=300(nfs-upload) 组=300(nfs-upload)
(3)修改/nfs/exports文件
[root@server ~]# cat /etc/exports
/nfs/upload 192.168.93.0/24(rw,anonuid=300,anongid=300,sync)
(4)重启NFS
[root@server ~]# systemctl restart nfs-server rpcbind
  • 在客户端配置:
(5)查看NFS服务器的共享目录
[root@jxy ~]# showmount -e 192.168.93.130
Export list for 192.168.93.130:
/nfs/upload 192.168.93.0/24
(6)挂载共享目录
[root@jxy ~]# mount -t nfs 192.168.93.130:/nfs/upload/ /jxy
[root@jxy ~]# df -h
文件系统                             容量  已用  可用 已用% 挂载点
/dev/mapper/rhel-root                 17G  1.7G   16G   10% /
devtmpfs                             901M     0  901M    0% /dev
tmpfs                                912M     0  912M    0% /dev/shm
tmpfs                                912M  8.7M  903M    1% /run
tmpfs                                912M     0  912M    0% /sys/fs/cgroup
/dev/sr0                             3.8G  3.8G     0  100% /mnt
/dev/sda1                           1014M  143M  872M   15% /boot
tmpfs                                183M     0  183M    0% /run/user/0
192.168.93.130:/jiangxiuying          17G  1.7G   16G   10% /nfs
192.168.93.130:/jiangxiuying/upload   17G  1.7G   16G   10% /jxy
(7)在客户端创建文件和删除文件
[root@jxy ~]# cd /jxy
[root@jxy jxy]# ls
[root@jxy jxy]# touch 123
[root@jxy jxy]# ls
123
[root@jxy jxy]# mkdir 456
[root@jxy jxy]# ls
123  456
[root@jxy jxy]# rm -rf 123
[root@jxy jxy]# ls
456
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值