在CentOS系统上挂载共享文件夹通常涉及使用Samba(SMB/CIFS)或NFS协议。以下是使用这两种协议的详细挂载步骤:
安装必要的软件包:
sudo yum install cifs-utils -y
创建挂载点:
sudo mkdir /mnt/shared
挂载共享文件夹:
sudo mount -t cifs //server_ip/shared_folder /mnt/shared -o username=your_username,password=your_password
例如:
sudo mount -t cifs //192.168.1.100/myshare /mnt/shared -o username=user,password=pass
开机自动挂载(可选):
编辑 /etc/fstab
文件,添加以下行:
//server_ip/shared_folder /mnt/shared cifs username=your_username,password=your_password,uid=1000,gid=1000,iocharset=utf8 0 0
保存并退出编辑器后,使用以下命令测试挂载:
sudo mount -a
验证挂载:
使用 df -h
命令查看已挂载的共享文件夹,或者直接访问 /mnt/shared
目录来确认文件是否可用。
安装NFS服务:
sudo yum install nfs-utils -y
创建共享目录:
sudo mkdir /srv/nfs_shared
配置NFS共享:
编辑 /etc/exports
文件,添加以下内容:
/path/to/your/folder 192.168.1.0/24(rw,sync,no_root_squash)
启动NFS服务:
sudo systemctl start nfs-server
sudo systemctl enable nfs-server
在客户端挂载NFS共享:
sudo mount -t nfs 192.168.1.1:/path/to/your/folder /mnt/nfs_shared
验证挂载:
使用 df -h
命令查看已挂载的共享文件夹。