CentOS 7下Samba服务部署


Samba,是种用来让UNIX系列的操作系统与微软Windows操作系统的SMB/CIFS(Server Message Block/Common Internet File System)网络协议做链接的自由软件。第三版不仅可访问及分享SMB的文件夹及打印机,本身还可以集成入Windows Server的网域,扮演为网域控制站(Domain Controller)以及加入Active Directory成员。简而言之,此软件在Windows与UNIX系列OS之间搭起一座桥梁,让两者的资源可互通有无。

一 服务端配置

1 安装所需软件

[root@CentOS7 ~]# yum install samba  samba-common -y

samba主要提供SMB服务所需的各项服务程序、相关的文件及其他和Samba相关的设置等
samba-common提供服务端和客户端都会用的的数据,包括主配置文件、语法检查等

2 添加Samba用户

添加smb1、smb2、smb3,所属组为centos组。
(1)添加系统用户,因为Samba用户必须是系统中已经存在的用户

[root@centos7 ~]# useradd smb1  -G centos
[root@centos7 ~]# useradd smb2  -G centos
[root@centos7 ~]# useradd smb3  -G centos

(2)设置系统用户为Samba用户并修改密码

    smbpasswd  [options]  USERNAME
        -a:添加
        -x:删除
        -d:禁用
        -e:启用
[root@centos7 ~]# smbpasswd -a smb1
New SMB password:
Retype new SMB password:
Added user smb1.
[root@centos7 ~]# smbpasswd -a smb2
New SMB password:
Retype new SMB password:
Added user smb2.
[root@centos7 ~]# smbpasswd -a smb3
New SMB password:
Retype new SMB password:
Added user smb3.

(3)查看Samba用户

    pdbedit
        -L:列出samba服务中的所有用户;
        -a, --create:添加用户为samba用户;
        -u, --user=USER:要管理的用户;
        -x, --delete:删除用户;
        -t, --password-from-stdin:从标准输出接收字符串作为用户密码;使用空提示符,而后将密码输入两次;
[root@centos7 ~]# pdbedit -L
smb1:1001:
smb3:1003:
smb2:1002:

3 新建用共享目录

(1)新建目录/samba作为共享目录

[root@centos7 ~]# mkdir /samba

(2)修改共享目录所属组,由于Samba用户都属于centos组

[root@centos7 ~]# chgrp centos /samba/

(3)修改共享目录的权限

[root@centos7 ~]# chmod  2770 /samba/
[root@centos7 ~]# ll /samba/ -d
drwxrwx--- 2 root centos 6 Jun  7 16:24 /samba/

4 编辑Samba配置文件

(1)修改主配置文件/etc/samba/smb.conf

[root@centos7 ~]# vim /etc/samba/smb.conf
[global]
    workgroup = MYGROUP ##工作组的名称
         security = user        ##指定用户通过密码才能访问

在最后添加如下几行

[samba]
    comment=My samba share  ##只是这个目录的说明而已
    path=/samba         ##共享的目录
    browseable=yes      ##是否让所有用户看到这个项目
    create mask = 0664      ##建立文件的权限
        directory mask = 0775   ##建立目录的权限
    write list=@centos      ##写入者包括哪些人

(2)检查配置文件语法

[root@centos7 ~]# testparm 
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[samba]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions
# Global parameters

[samba]
    comment = My samba share
    path = /samba
    create mask = 0664
    directory mask = 0775
    write list = @centos

5 启动服务

[root@centos7 ~]# systemctl start smb.service

smbd主要功能就是管理Samba主机共享的目录、文件与打印机

[root@centos7 ~]# systemctl start nmb.service
nmbd主要用来管理工作组、netBIOS name等的解析

二 客户端配置

1 安装所需软件

[root@centos7 ~]# yum install samba-client samba-common -y

samba-client提供Samba客户端所需的命令和工具,比如挂载文件格式的mount.cifs

2 使用smb1用户登录试试

[root@centos7 ~]# smbclient -L  //192.168.29.130 -U smb1
Enter smb1's password: 
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]  ##有时候OS=[Unix] 这个我也不知道为何

    Sharename       Type      Comment
    ---------       ----      -------
    samba           Disk      My samba share
    IPC$            IPC       IPC Service (Samba 4.4.4)
Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]

3 挂载

(1)新建本地挂载目录

[root@centos7 ~]# mkdir /smb/

(2)使用用户smb1挂载

[root@centos7 ~]# mount -t cifs //192.168.29.130/samba  /smb/ -o  username=smb1,password=1234

(3)查看挂载

[root@centos7 ~]# df -h /smb
Filesystem              Size  Used Avail Use% Mounted on
//192.168.29.130/samba   10G  1.2G  8.9G  12% /smb

(4)设置开机挂载

[root@centos7 ~]# vim /etc/fstab

#
UUID=3ecec458-d4e7-4545-91bf-19cc36ce2ef7 /                       xfs     defaults        0 0
UUID=b7dbdf8d-753a-441b-b9ad-99c261908427 /boot             xfs     defaults        0 0
UUID=05838299-1ad0-4e0b-a113-74ab99ed00f7 swap              swap    defaults        0 0
//192.168.29.130/samba              /smb    cifs    defaults,username=smb1,password=1234  0  0

更多Samba相关教程见以下内容

CentOS 7.2 安装配置Samba服务器 

VMWare 虚拟机 Ubuntu 双网卡 访问 samba 速度 翻倍

Ubuntu 15.04安装Samba服务

samba安装使用图解 

CentOS7.2下源码搭建Samba文件服务器[原创]

CentOS 7.2 安装配置Samba服务器

CentOS部署Samba企业文件共享服务

Samba共享服务器的搭建优化 

如何在Ubuntu 16.04上安装和配置Samba服务器以进行文件共享 

CentOS 7下Samba服务安装与配置详解

Ubuntu 16.04下Samba相关配置 

Red Hat 6.5 下 Samba服务器搭建

相关内容

    暂无相关文章