Linux通过NFS挂载远程磁盘

Ubuntu安装

1)查询是否安装NFS服务

# dpkg -l | grep nfs

在这里插入图片描述

2)安装NFS服务

# apt-get install nfs-kernel-server

Centos安装

1)查询是否安装NFS服务

# rpm -aq | grep nfs

在这里插入图片描述

# rpm -aq | grep rpcbind

在这里插入图片描述

2)安装NFS服务

# yum -y install nfs-utils rpcbind
注:
1)设置开机自动启动服务
	chkconfig nfs on
	chkconfig rpcbind on
2)启动服务
	service rpcbind start
	service nfs start
或
	systemctl start rpcbind
	systemctl start nfs

文件服务器配置

创建共享目录
# mkdir /home/file

目录赋读写权限
# chmod -R 777 /home/file

配置exports文件
# vi /etc/exports
最后行加入
/home/file 192.168.1.2(rw,sync,no_root_squash,no_subtree_check)
注:ip地址为可挂载的服务器地址,可以为"192.168.1.*"
保存后刷新配置
# exportfs -a

查看挂载情况
# showmount -e

应用服务器安装

创建挂载目录
# mkdir /home/upload

挂载磁盘

1)直接挂载

# mount 192.168.1.2:/home/file /home/upload
#若挂载失败,错误提示如下:
mount: wrong fs type, bad option, bad superblock on 192.168.1.2:/xxx/xxx,
       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
#安装 nfs-utils 即可
	 yum install nfs-utils
#若挂载失败,错误提示如下:
# mount 192.168.1.2:/home/vsftpd/pactera /home/rddb/upload
	mount.nfs: rpc.statd is not running but is required for remote locking.
	mount.nfs: Either use '-o nolock' to keep locks local, or start statd.
执行命令后添加“-o nolock”
# mount 192.168.1.2:/home/file /home/upload  -o nolock

2)编辑fstab文件挂载

# vi /etc/fstab
添加
192.168.1.2:/home/file   /home/upload     nfs     rw,auto     0     1
保存后执行挂载
# mount -a
#若挂载失败,错误提示如下:
# mount -a
	mount.nfs: rpc.statd is not running but is required for remote locking.
	mount.nfs: Either use '-o nolock' to keep locks local, or start statd.

fstab文件中添加“nolock”参数
192.168.1.2:/home/file  /home/upload   nfs   rw,auto,nolock   0    1
保存后执行挂载
mount -a

在这里插入图片描述

其他

提示 "mount.nfs: No route to host" 错误
查看文件服务器防火墙,开放端口

查询端口
# rpcinfo -p
开放nfs,portmapper,mountd服务的端口

firewall-cmd --zone=public --add-port=111/tcp --permanent
firewall-cmd --zone=public --add-port=20048/tcp --permanent
firewall-cmd --zone=public --add-port=2049/tcp --permanent
firewall-cmd --zone=public --add-port=111/udp --permanent
firewall-cmd --zone=public --add-port=20048/udp --permanent
firewall-cmd --zone=public --add-port=2049/udp --permanent
注:需根据实际服务器情况配置
提示 "mount.nfs: access denied by server while mounting 10.200.1.64:/home/file"
应用服务器地址不允许挂载文件服务器
需要修改文件服务器exports配置
# vi /etc/exports
 /home/file 192.168.1.*(rw,sync,no_root_squash,no_subtree_check)

参数说明
/home/file  ---要共享的目录
192.168.0.*---允许访问的网段,也可以是ip地址、主机名(能够被服务器解析)、*(所有人都能访问)
(rw,sync,no_root_squash,no_subtree_check)---权限
rw:读/写权限
sync:数据同步写入内存和硬盘
no_root_squash:服务器允许远程系统以root特权存取该目录
no_subtree_check:关闭子树检查
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值