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  #解除挂载

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章