公司有多个部门,例如软件部、财务部,需要一个共享存储空间,方便资源共享,协作文档。
使用需求如下:
根据以上需求,本文分别以Samba和NFS来实现。
CentOS7.x 64位
yum install -y samba 复制代码
# 备份原配置文件smb.conf cp /etc/samba/smb.conf /etc/samba/smb.conf.org vim /etc/samba/smb.conf # 添加如下配置 复制代码
[global] workgroup = WORKGROUP security = user server string = seal samba server %v netbios name = SealSamba # map to guest = Bad User passdb backend = tdbsam config file = /etc/samba/%G.smb.conf 复制代码
# 新建软件部配置文件software.smb.conf和财务部配置文件finance.smb.conf vim /etc/samba/software.smb.conf vim /etc/samba/finance.smb.conf # 添加如下配置 复制代码
[公共] comment = Public Stuff path = /home/share/public public = no read only = no writable = yes create mask = 0644 directory mask = 0755 force user = nobody force group = nobody valid users = @software admin users = @software read list = @software write list = @software [软件部] comment = 软件部 path = /home/share/software public = no valid users = @software admin users = @software read list = @software write list = @software read only = no writable = yes create mask = 0644 directory mask = 0755 复制代码
[公共] comment = 公共 path = /home/share/public public = no valid users = @finance admin users = @finance read list = @finance write list = @finance writable = yes create mask = 0644 directory mask = 0755 force user = nobody force group = nobody [财务部] comment = 财务部 path = /home/share/财务部 public = no valid users = @finance admin users = @finance read list = @finance write list = @finance writable = yes create mask = 0644 directory mask = 0755 复制代码
# 新建用户组:软件部 groupadd software # 新建用户组:财务部 groupadd finance # 新建用户:张三,并添加到软件部用户组 useradd -g software zhangsan # 新建用户:李四,并添加到财务部用户组 useradd -g finance lisi # 另,删除用户组和用户 groupdel 用户组 userdel 用户 # 添加到samba smbpasswd -a zhangsan smbpasswd -a lisi # 另,samba删除用户 smbpasswd -x 用户 复制代码
mkdir -p /home/share/public mkdir -p /home/share/software mkdir -p /home/share/财务部 # 修改用户组 chown -R nobody:nobody /home/share/public 复制代码
systemctl start smb 复制代码
yum install -y nfs-utils # 开启服务 systemctl start rpcbind systemctl start nfs # 防火墙配置 firewall-cmd --zone=public --permanent --add-service={rpc-bind,mountd,nfs} firewall-cmd --reload 复制代码
mkdir /data chmod 755 /data vim /etc/exports # 添加如下配置 复制代码
/data/ 192.168.0.0/24(rw,sync,no_root_squash,no_all_squash) 复制代码
# 保存后重启nfs服务 systemctl restart nfs # 检查本地共享存储目录 showmount -e localhost # 检查结果如下: 复制代码
Export list for localhost: /data 192.168.0.0/24 复制代码
Windows 安装 NFS 客户端,不同的 Windows 版本,安装方式不大一样
id root # uid=0(root) gid=0(root) groups=0(root) # 注意:本例以 root 为例,生产环境要考虑安全因素,请修改为相应的有权限的用户 复制代码
可以看到 uid=0, gid=0,需要在 Windows 客户端上进行配置
# 注册表配置 regedit 复制代码
mount 192.168.0.110:/data X: # 卸载 umount X: # 注意:通过此命令操作挂载,当服务器重启时,不会自动挂载。 复制代码
yum install -y nfs-utils systemctl enable rpcbind systemctl start rpcbind 复制代码
# 客户端查看 showmount -e 192.168.0.110 # 客户端创建目录 mkdir /data # 客户挂载 mount -t nfs 192.168.0.101:/data /data # 客户端查看挂载情况 mount 复制代码
cd /data touch 1.txt 复制代码
vim /etc/fstab # 添加如下配置: 复制代码
# # /etc/fstab # Created by anaconda on Thu May 25 13:11:52 2017 # # Accessible filesystems, by reference, are maintained under '/dev/disk' # See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info # /dev/mapper/cl-root / xfs defaults 0 0 UUID=414ee961-c1cb-4715-b321-241dbe2e9a32 /boot xfs defaults 0 0 /dev/mapper/cl-home /home xfs defaults 0 0 /dev/mapper/cl-swap swap swap defaults 0 0 192.168.0.110:/data /data nfs defaults 0 0 复制代码
# 修改了fstab,需要重新加载systemctl systemctl daemon-reload # mount查看挂载情况 mount 复制代码