Linux 7下安装配置nfs

环境:CentOS 7.6 (注意:不同linux版本下安装和启动方法有差异,假如环境不能联网就用源码或rpm方法去安装吧)

1、安装

yum install nfs-utils nfs-utils-lib -y

2、修改配置

vim /etc/exports

/pubic 192.168.101.0/24(rw,sync)   #允许该网段用户读写,用绝对路径,sync文件同时写入硬盘和内存

/mnt *(ro,sync)   #允许所有用户访问,只读

(后续修改使配置生效 exportfs -r)

3、重启服务(按顺序)

systemctl restart rpcbind
systemctl restart nfs-server
systemctl restart nfs-lock
systemctl restart nfs-idmap

4、关闭SELinux、关闭或配置防火墙

setenforce 0  (临时关闭SELinux)-> getenforce (确认) -> vim /etc/selinux/config (修改配置文件永久关闭,SELINUX=disabled)

关闭防火墙

systemctl stop firewalld     #关闭

systemctl disable firewalld   #禁开机启动

systemctl status firewalld   #检查状态是否inactive

配置防火墙

firewall-cmd --permanent --add-port=111/tcp     #放开rpc的tcp端口
firewall-cmd --permanent --add-port=2049/tcp     #放开nfs的tcp端口
firewall-cmd --permanent --zone=public --add-service=nfs     #放开nfs服务
firewall-cmd --reload    #重启

5、测试

showmount -e 127.0.0.1  -> 返回没报错

mount -t nfs 127.0.0.1:/mnt /tmp/www/    #挂载nfs目录到指定目录,该目录要提前建好

[root@localhost mnt]# mount -t nfs 192.168.101.228:/mnt /mnt/
mount: wrong fs type, bad option, bad superblock on 192.168.101.228:/mnt,
       missing codepage or helper program, or other error
       (for several filesystems (e.g. nfs, cifs) you might
       need a /sbin/mount.<type> helper program)

       In some cases useful info is found in syslog - try
       dmesg | tail or so.
[root@localhost tmp]# yum install nfs-utils -y  #在本地可以mount,同网络的别机器mount不了就装下nfs工具就好
......
[root@localhost mnt]# mount -t nfs 192.168.101.228:/mnt /mnt/
[root@localhost tmp]# mount | grep mnt
192.168.101.128:/mnt on /tmp/www type nfs4 (rw,relatime,vers=4.1,rsize=131072,wsize=131072,namlen=255,hard,proto=tcp,timeo=600,retrans=2,sec=sys,clientaddr=192.168.101.130,local_lock=none,addr=192.168.101.128)
[root@localhost tmp]# ls www/
test.txt
[root@localhost tmp]# 

mount | grep mnt  #看是否挂载成功。或者新建个文件在/mnt,然后去/tmp/www下看是否有这文件

umount /tmp/www  #解除挂载

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值