[Linux]挂载网络位置(NFS和Samba,带密码和域名等方式)

2021-01-21 6729点热度 3人点赞 1条评论

有时候,我们需要在Linux服务器里挂载其他服务器共享出来的NFS网络位置,或者NAS里分享出来的NFS/Samba网络位置,还有Windows下分享的共享位置。

MacOS挂载Windows里分享的Samba位置,请查看:https://blog.terrynow.com/2021/05/16/macos-access-windows-samba-share-specific-user-domain-hidden-share-etc/

挂在Linux共享的网络位置

192.168.1.1/var/share 共享给192.168.1.2为例

在待分享的机器上,编辑 vi /etc/export加上以下行

# 192.168.1.2是可以mount的白名单机器
# 可以是 * 代表允许全部机器来mount
# 也可以是网段 192.168.1.0/24
/var/share 192.168.1.2(rw,sync,no_root_squash)
注意,可能需要检查服务器端是否有安装NFS服务并检查111端口是否被防火墙阻挡
yum install nfs-utils
#or
apt-get install nfs-utils

systemctl enable rpcbind
systemctl enable nfs

在需要mount的机器(192.168.1.2)上,

手动挂载(mount)
# 把192.168.1.1分享出来的网络位置挂载到192.168.1.2的/mnt/share上
mkdir /mnt/share
mount -t nfs 192.168.1.1:/var/share /mnt/share
注意 ubuntu下可能还需要安装nfs-common
apt-get install nfs-common

上面介绍了手动挂载,但是如果服务器重启,就要手动挂载一次,比较麻烦,下面再介绍自动挂载

修改配置文件 vi /etc/fstab

最后一行加上:

192.168.1.1:/var/share /mnt/share nfs defaults 0 0

退出编辑模式,如果要马上生效,命令行输入:

# 重新根据/etc/fstab的内容重新mount
mount -a

# 查看mount的情况
mount

#取消mount
umount /mnt/share

#如果其他程序读取的情况下无法取消mount,可以使用强制 umount
umount -l /mnt/share

Linux机器mount Windows服务器或者NAS分享出来的Samba共享文件夹

首先检查Linux机器是否安装cifs-utils

yum install cifs-utils

假设Windows服务器192.168.1.3分享了/share文件夹

手动mount到192.168.1.1的/mnt/share上:

# 提供用户名,密码会在接下来要求输入
mount -t cifs -o username=<windows_user> 192.168.1.3:/share /mnt/share

# 提供用户名和密码
mount -t cifs -o username=<windows_user>,password=<windows_password> 192.168.1.3:/share /mnt/share

# 如果是域里面的机器,还可以提供域
mount -t cifs -o username=<windows_user>,password=<windows_password>,domain=<windows_domain> 192.168.1.3:/share /mnt/share
同样再介绍自动mount

修改配置文件 vi /etc/fstab

最后一行加上:

//10.22.1.3/share /mnt/share cifs username=root,password=root,sec=ntlmv2,uid=1000,gid=0,rw 0 0

然后使用mount -a使挂载点生效

admin

这个人很懒,什么都没留下

文章评论

  • graituall

    buying generic cialis online safe Balding Propecia Hair Follicles Progesterone Menopause With Free Shipping Secure Ordering Our team of doctors did not have a specic answer for Jeffs anxiety. Jvubvu Cialis

    2022-04-17
  • 您需要 登录 之后才可以评论