文章目录
1. Linux挂载Windows共享
1.0 Samba
略
1.1 Windows共享文件夹
在192.168.20.196
Windows服务器共享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挂载