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 -p
   program vers proto   port  service
    100000    4   tcp    111  portmapper
    100000    3   tcp    111  portmapper
    100000    2   tcp    111  portmapper
    100000    4   udp    111  portmapper
    100000    3   udp    111  portmapper
    100000    2   udp    111  portmapper
    100005    1   udp  20048  mountd
    100005    1   tcp  20048  mountd
    100005    2   udp  20048  mountd
    100005    2   tcp  20048  mountd
    100005    3   udp  20048  mountd
    100005    3   tcp  20048  mountd
    100003    3   tcp   2049  nfs
    100003    4   tcp   2049  nfs
    100227    3   tcp   2049  nfs_acl
    100003    3   udp   2049  nfs
    100003    4   udp   2049  nfs
    100227    3   udp   2049  nfs_acl
    100021    1   udp  55264  nlockmgr
    100021    3   udp  55264  nlockmgr
    100021    4   udp  55264  nlockmgr
    100021    1   tcp  43310  nlockmgr
    100021    3   tcp  43310  nlockmgr
    100021    4   tcp  43310  nlockmgr
    100024    1   udp  47115  status
    100024    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

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值