CentOS 7 安装、配置并挂载NFS路径

编程入门 行业动态 更新时间:2024-10-24 20:20:25

CentOS 7 安装、配置并挂载NFS<a href=https://www.elefans.com/category/jswz/34/1771438.html style=路径"/>

CentOS 7 安装、配置并挂载NFS路径

两台centos7虚拟机,分别记为A(服务端10.128.0.96) B(客户端192.168.0.101)

1.在A服务端安装对应nfs服务,并修改对应端口

[root@localhost ~]# yum -y install rpcbind nfs-utils
[root@localhost ~]# vi /etc/sysconfig/nfs设置各种*port=...参数# TCP port rpc.lockd should listen on.
LOCKD_TCPPORT=32803
# UDP port rpc.lockd should listen on.
LOCKD_UDPPORT=32769# Port rpc.statd should listen on.
STATD_PORT=662
# Outgoing port statd should used. The default is port
# is random
STATD_OUTGOING_PORT=2020

2.设置开机启动并启动对应服务

开机自动启动
systemctl enable rpcbind
systemctl enable nfs
systemctl enable nfs-lock
systemctl enable nfs-idmap启动服务
systemctl start rpcbind
systemctl start nfs
systemctl start nfs-lock
systemctl start nfs-idmap

3.查看端口占用,并通过防火墙 或者暂时关闭防火墙

[root@localhost ~]# rpcinfo -pprogram vers proto   port  service100000    4   tcp    111  portmapper100000    3   tcp    111  portmapper100000    2   tcp    111  portmapper100000    4   udp    111  portmapper100000    3   udp    111  portmapper100000    2   udp    111  portmapper100005    1   udp  20048  mountd100005    1   tcp  20048  mountd100005    2   udp  20048  mountd100005    2   tcp  20048  mountd100005    3   udp  20048  mountd100005    3   tcp  20048  mountd100003    3   tcp   2049  nfs100003    4   tcp   2049  nfs100227    3   tcp   2049  nfs_acl100003    3   udp   2049  nfs100003    4   udp   2049  nfs100227    3   udp   2049  nfs_acl100021    1   udp  55264  nlockmgr100021    3   udp  55264  nlockmgr100021    4   udp  55264  nlockmgr100021    1   tcp  43310  nlockmgr100021    3   tcp  43310  nlockmgr100021    4   tcp  43310  nlockmgr100024    1   udp  47115  status100024    1   tcp  47466  status开启以下端口
[root@localhost ~]# firewall-cmd --zone=public --add-port=111/tcp --permanent
[root@localhost /]# firewall-cmd --zone=public --list-ports
20048/udp 20048/tcp 2049/udp 2049/tcp 111/udp 111/tcp

4.设置需要共享的目录(以/home目录为例),并加载

[root@localhost ~]# vi /etc/exports#填入以下内容 ip为B客户端网段/home 192.168.0.101/24(rw,root_squash,all_squash,sync,anonuid=1000,anongid=1000)#或者是网段/home 192.168.0.0/24(rw,sync)[root@localhost ~]# exportfs -r

4.在B(客户端)安装nfs-utils,并查看A服务端分享目录

[root@localhost ~]# yum -y install nfs-utils查看可分享内容
[root@localhost ~]# showmount -e 10.128.0.96
Export list for 10.128.0.96:
/home 192.168.0.101/24

5.挂载分享的硬盘,可以看到已经挂载成功

[root@localhost /]# mkdir /data
[root@localhost /]# mount -t nfs 10.128.0.96:/home /data
[root@localhost /]# df -h
Filesystem               Size  Used Avail Use% Mounted on
devtmpfs                 1.9G     0  1.9G   0% /dev
tmpfs                    1.9G     0  1.9G   0% /dev/shm
tmpfs                    1.9G  8.5M  1.9G   1% /run
tmpfs                    1.9G     0  1.9G   0% /sys/fs/cgroup
/dev/mapper/centos-root   50G  1.4G   49G   3% /
/dev/vda1               1014M  150M  865M  15% /boot
/dev/mapper/centos-home   46G   33M   46G   1% /home
tmpfs                    379M     0  379M   0% /run/user/0
10.128.0.96:/home         46G   32M   46G   1% /data

6.开机自动挂载

[root@localhost /]# vi /etc/rc.local添加以下
mount -t nfs 10.128.0.96:/home /data[root@localhost ~]# chmod +x /etc/rc.local

更多推荐

CentOS 7 安装、配置并挂载NFS路径

本文发布于:2024-03-08 18:34:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1721838.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:路径   CentOS   NFS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!