Linux挂载Windows共享、Linux共享

引用地址:Linux挂载Windows共享、Linux共享_linux挂载windows共享目录-CSDN博客

1. Linux挂载Windows共享
1.0 Samba


1.1 Windows共享文件夹

在192.168.20.196Windows服务器共享ccd文件夹

1.2 Linux挂载

创建挂载目录mkdir /root/win

以cifs格式挂载“源文件夹”//192.168.20.196/sharedir

使用-o添加挂载选项,指定登录Windows服务器的用户名和密码username=administrator,password=2021026
1.2.1 临时挂载(重启后无效)

mount -t cifs -o username=administrator,password=2021026 //192.168.20.196/sharedir /root/win
1.2.2 永久挂载(重启自动加载)

1) 在/etc/fstab文件中添加
//192.168.20.196/sharedir /root/win cifs username=administrator,password=2021026 0 0

2) 使用命令mount -a,加载/etc/fstab
1.3 查看与卸载

df -h查看当前服务器已经挂载的所有“设备”
使用umount /root/win卸载Windows挂载
2. Linux挂载Linux共享
2.0 NFS环境准备

Linux系统之间目录共享,使用网络文件系统NFS协议
需要在源系统Linux A和目的系统Linux B都安装nfs服务
yum -y install nfs-utils rpcbind

关闭stop并禁用disable Linux A服务器的防火墙,或者在防火墙配置nfs规则,否则无法共享目录
2.1 Linux A共享目录
2.1.1 配置/etc/exports

在192.168.0.104服务器的/etc/exports中添加要共享的目录/root/sharedir
格式如下

    /root/sharedir *(rw,sync,no_root_squash)
    #客户机地址 可以是 : 主机名、IP地址、网段地址、或者"、?"通配符;
    #权限选项:rw表示允许读写(ro为只读)
    # sync表示同步写
    # no_root_squash表示当前客户机以root身份访问时,赋予本地root权限(默认是root_squash,将作为nfsnobody用户降权对待) (NFS 服务器共享目录用户的属性,如果用户是 root,那么对于这个共享目录来说就具有 root 的权限。)
    # 给多个地址授权
    /data/share 192.168.0.2(rw,sync,no_root_squash) 192.168.0.3(rw,sync,no_root_squash)
    # 给某个网段内所有IP授权
    /data/share 192.168.0.(rw,sync,no_root_squash)

2.1.2 启动或重启nfs服务、rpcbind服务

启动
systemctl start rpcbind,systemctl start nfs

Linux A需要enable开机启动,否则服务器重启会导致共享失败,Linux B无法正常使用(df -h无法使用,共享目录无法使用)
systemctl enable rpcbind,systemctl enable nfs

重启
systemctl restart rpcbind,systemctl restart nfs

查看已经共享的规则showmount -e
2.2 Linux B挂载

确定已经安装nfs服务,否则将无法使用nfs协议挂载共享目录
yum -y install nfs-utils

创建挂载目录mkdir /root/linux

以nfs格式挂载Linux A服务器共享的“源文件夹”192.168.0.104:/root/sharedir
2.2.1 临时挂载(重启后无效)

mount -t nfs 192.168.0.104:/root/sharedir /root/linux
2.2.2. 永久挂载(重启后自动加载)

1) 在/etc/fstab文件中添加
192.168.0.104:/root/sharedir /root/linux nfs defaults 0 0

192.168.0.104:/root/sharedir /root/linux nfs proto=tcp,vers=4.0 0 0 可以一定程度上解决远程挂载卡死的问题,(strace df -h卡在挂载的目录下)

2) 使用命令mount -a,加载/etc/fstab
2.3 查看与卸载

df -h查看当前服务器已经挂载的所有“设备”
使用umount /root/linux卸载Linux A挂载
————————————————

                            版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
                        
原文链接:https://blog.csdn.net/u010420859/article/details/125747494

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值