Linux下文件的挂载

文件挂载:简单讲可理解为想将本机服务端的文件目录/var/test共享给其他电脑进行使用,在此过程操作中,需要注意ip和挂载的对象。
方法一:安装mount.nfs进行挂载(B)
(1)下载安装mount.nfs

[root@tandelin /]# yum install mount.nfs

(2)确定挂载路径,可默认,也可创建文件(B)
(3)进行挂载:从A挂载到B,ip是A的,B是被挂的。

[root@tandelin /]# mount -t nfs -o vers=3,proto=tcp,nolock,noacl,sync ${nfs_server_ip}: / /mnt/

(4)切换用户检查是否挂载成功(A)

[root@no /]#  ls -l /mnt/hdfs

方法二:安装安装nfs组件

(1)被挂载的主机操作

[root@tandelin /]#  yum install nfs-utils -y

(2)启动rpcbind服务,然后启动nfs服务

[root@tandelin /]#  service rpcbind start
[root@tandelin /]#  service nfs start

(3)使用命令查看可以挂在的目录

 [root@tandelin /]# showmount -e localhost 

(4)挂载的目录进行配置

[root@tandelin /]#  vi /etc/exports
 /mnt 192.169.0.21(rw,sync,no_root_squash)

其中 /mnt 192.169.0.21(rw,sync,no_root_squash):
192.169.0.21 是要将目录共享给他的电脑,及192.169.0.21可以访问/mnt下的所有文件权限
/mnt:是要共享的目录
rw:为权限,可读写
sync:文件写入硬盘和内存
no_root_squash:如果客户端是用root用户连接的服务端,则客户端对于服务端分享的目录也会有root权限

(5)共享挂载的电脑也要安装nfs组件(为了接受挂载文件信息,形成呼应)

[root@hdfs /]# yum install nfs-utils -y
此时可以查看服务端共享的目录了(192.168.6.23为服务端ip地址)
[root@hdfs /]# showmount –e 192.168.6.23

(6)客户端挂载服务端文件目录

[root@hdfs /]# mount -t nfs 192.168.6.23:/var/test /test

此时客户端配置已经完成,如果需要取消挂载可以使用umount命令

[root@hdfs /]# umount /test

但是,需要注意取消挂载命令,不能在挂载目录使用,会显示device is busy

(7)实现开机服务自启和自动挂载,即需要配置服务自启和自动挂载服务自启
可以使用chkconfig命令将某个服务设置为开机自动启动

[root@hdfs /]#  chkconfig nfs on

这样设置完后,nfs服务会在开机后自动启动(在服务端配置)

(8)自动挂载
自动挂载配置,是在客户端完成的,使用vi打开/etc/fstab,在文档最后一行输入以下信息即可完成配置

[root@hdfs /]#  vi /etc/fstab
192.168.6.23:/var/test /test nfs defaults 0 0

(9)注意事项(摘自:https://blog.csdn.net/edius12/article/details/78996015/)
服务端和客户端都要安装nfs-utils这个nfs组件
服务端需要配置共享目录,然后开启rpcbind和nfs服务
客户端需要配置目录将服务端共享目录与之关联
fs服务开机自启配置和开机自动挂载配置

猜你喜欢

转载自blog.csdn.net/tandelin/article/details/87109228
今日推荐