在 RHEL 7 上配置 NFS 共享
要配置 NFS 服务,我们必须安装 nfs-utils 包。
通常,此软件包会在安装 Red Hat Enterprise Linux (RHEL) 7 期间自动安装。
但是,我们可以随时从 yum span> 存储库安装它。
[root@ipaserver ~]# yum install -y nfs-utils Loaded plugins: langpacks, product-id, subscription-manager This system is not registered to Red Hat Subscription Management. You can use subscription-manager to register. Package 1:nfs-utils-1.3.0-0.el7.x86_64 already installed and latest version Nothing to do [root@ipaserver ~]#
nfs-utils 已经安装在我们的系统上。
创建一个目录以与其他客户端共享。
[root@ipaserver ~]# mkdir /nfsshare [root@ipaserver ~]# chgrp dba /nfsshare/ [root@ipaserver ~]# chmod 2770 /nfsshare/
我们创建了一个目录 /nfsshare ,将其用户组更改为 dba 并且已将 2770 权限授予用户组。
因此,组成员可以在此共享目录上创建文件。
调整 /nfsshare 目录的 SELinux 类型。
[root@ipaserver ~]# semanage fcontext -a -t nfs_t "/nfsshare(/.*)?" [root@ipaserver ~]# restorecon -Rv /nfsshare/ restorecon reset /nfsshare context unconfined_u:object_r:default_t:s0->unconfined_u:object_r:nfs_t:s0
如果 semanage 命令在系统上不可用,则安装 policycoreutils-python 包。
现在将此目录导出/共享给特定客户端。
[root@ipaserver ~]# echo '/nfsshare *.onitroad.com(rw,sync)' >> /etc/exports [root@ipaserver ~]# exportfs -r
启用并启动 nfs-server 服务。
[root@ipaserver ~]# systemctl start nfs-server ; systemctl enable nfs-server ln -s '/usr/lib/systemd/system/nfs-server.service' '/etc/systemd/system/nfs.target.wants/nfs-server.service'
允许 nfs 和其他必需的服务通过防火墙。
[root@ipaserver ~]# firewall-cmd --permanent --add-service={mountd,nfs,rpc-bind} success [root@ipaserver ~]# firewall-cmd --reload success
查看更多教程 https://on itroad.com
在 RHEL 7 上挂载 NFS 共享
连接到 client2.onitroad.com 并安装 nfs-utils 包。
[root@client2 ~]# yum install -y nfs-utils [root@client2 ~]#
创建一个目录,从 ipaserver.onitroad.com 挂载共享目录。
[root@client2 ~]# mkdir /mnt/nfsshare
检查来自 ipaserver.onitroad.com 的共享目录。
[root@client2 ~]# showmount -e ipaserver.onitroad.com Export list for ipaserver.onitroad.com: /nfsshare *.onitroad.com [root@client2 ~]#
通过在 /etc/fstab 中添加以下条目来永久挂载此共享目录。
[root@client2 ~]# echo 'ipaserver.onitroad.com:/nfsshare /mnt/nfsshare nfs defaults,_netdev 0 0' >> /etc/fstab [root@client2 ~]# mount -a [root@client2 ~]#
检查挂载目录的状态。
[root@client2 mnt]# mount | grep nfsshare ipaserver.onitroad.com:/nfsshare on /mnt/nfsshare type nfs4 (rw,relatime,vers=4.0,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,port=0,timeo=600,retrans=2,sec=sys,clientaddr=192.168.1.202,local_lock=none,addr=192.168.1.200,_netdev)
使用 dba 组成员的用户登录。
并在此共享目录中创建一个文件,以验证文件权限。
[root@client2 ~]# su - imran Last login: Wed Aug 1 08:29:23 PDT 2018 on pts/0 [imran@client2 ~]$ cd /mnt/nfsshare/ [imran@client2 nfsshare]$ touch test2 [imran@client2 nfsshare]$ ls -al total 0 drwxrws---. 2 root dba 30 Aug 1 08:34 . drwxr-xr-x. 4 root root 31 Jul 31 07:23 .. -rw-rw-r--. 1 imran dba 0 Aug 1 08:34 test2 [imran@client2 nfsshare]$
日期:2020-09-17 00:12:46 来源:oir作者:oir