天天看点

centos7下搭建samba

参考:https://www.cnblogs.com/muscleape/p/6385583.html

分几步走:

  1. 防火墙关闭
[[email protected] ~]$ systemctl stop firewalld.service 
	[[email protected] ~]$ systemctl disable firewalld.service 
	Removed symlink /etc/systemd/system/multi-user.target.wants/firewalld.service.
	Removed symlink /etc/systemd/system/dbus-org.fedoraproject.FirewallD1.service.
           
  1. 查看SeLinux状态
    [[email protected] ~]$ sestatus 
    SELinux status:                 enabled
    SELinuxfs mount:                /sys/fs/selinux
    SELinux root directory:         /etc/selinux
    Loaded policy name:             targeted
    Current mode:                   enforcing
    Mode from config file:          enforcing
    Policy MLS status:              enabled
    Policy deny_unknown status:     allowed
    Max kernel policy version:      28
               
    临时关闭SeLinux

    [[email protected] ~]# setenforce 0

    永久关闭SeLinux,需要重启机器

    修改配置文件/etc/selinux/config,将SELINU置为disabled

  2. 安装samba服务
    [[email protected] ~]$ sudo yum install samba
    已加载插件:fastestmirror, langpacks
    Loading mirror speeds from cached hostfile
     * base: mirrors.aliyun.com
     * extras: mirrors.aliyun.com
     * updates: mirrors.aliyun.com
    正在解决依赖关系
    ..............................
    不再赘述
               
    查看安装结果:
    [[email protected] ~]$ rpm -qa | grep samba
    samba-common-4.8.3-6.el7_6.noarch
    samba-common-tools-4.8.3-6.el7_6.x86_64
    samba-client-libs-4.8.3-6.el7_6.x86_64
    samba-4.8.3-6.el7_6.x86_64
    samba-common-libs-4.8.3-6.el7_6.x86_64
    samba-client-4.8.3-6.el7_6.x86_64
    samba-libs-4.8.3-6.el7_6.x86_64
               
    查看samba状态:
    [[email protected] ~]$ service smb status
    Redirecting to /bin/systemctl status smb.service
    ● smb.service - Samba SMB Daemon
    Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
    Active: inactive (dead)
    Docs: man:smbd(8)
    man:samba(7)
    man:smb.conf(5)
               
    启动samba,并再次查看:
    [[email protected] ~]$ systemctl start smb
    [[email protected] ~]$ service smb status
    Redirecting to /bin/systemctl status smb.service
    ● smb.service - Samba SMB Daemon
    Loaded: loaded (/usr/lib/systemd/system/smb.service; disabled; vendor preset: disabled)
    Active: active (running) since 一 2019-09-16 14:07:00 CST; 14s ago
     Docs: man:smbd(8)
           man:samba(7)
           man:smb.conf(5)
     Main PID: 45643 (smbd)
    Status: "smbd: ready to serve connections..."
    CGroup: /system.slice/smb.service
           ├─45643 /usr/sbin/smbd --foreground --no-process-group
           ├─45649 /usr/sbin/smbd --foreground --no-process-group
           ├─45650 /usr/sbin/smbd --foreground --no-process-group
           └─45652 /usr/sbin/smbd --foreground --no-process-group
    
    9月 16 14:07:00 localhost.localdomain systemd[1]: Starting Samba SMB Daemon...
    9月 16 14:07:00 localhost.localdomain smbd[45643]: [2019/09/16 14:07:00.4849...
    9月 16 14:07:00 localhost.localdomain systemd[1]: Started Samba SMB Daemon.
    9月 16 14:07:00 localhost.localdomain smbd[45643]:   daemon_ready: STATUS=da...
    Hint: Some lines were ellipsized, use -l to show in full.
               
    设置samba开机自启动:
    [[email protected] ~]$ systemctl enable smb
    Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
               
  3. 再来就是搞samba配置文件

    配置文件是/etc/samba/smb.conf,我的配置文件内容如下:

    # See smb.conf.example for a more detailed config file or
    # read the smb.conf manpage.
    # Run 'testparm' to verify the config is correct after
    # you modified it.
    
    [global]
        #workgroup = SAMBA
        
        workgroup = MYGROUP
        server string = Samba Server Version %v
    
        log file = /var/log/samba/log.%m
        max log size = 50
    
        security = user
    
        passdb backend = tdbsam
    
        printing = cups
        printcap name = cups
        load printers = yes
        cups options = raw
    
    [homes]
        comment = Home Directories
        valid users = %S, %D%w%S
        browseable = No
        read only = No
        inherit acls = Yes
    [printers]
        comment = All Printers
        path = /var/tmp
        printable = Yes
        create mask = 0600
        browseable = No
    
    [print$]
        comment = Printer Drivers
        path = /var/lib/samba/drivers
        write list = @printadmin root
        force group = @printadmin
        create mask = 0664
        directory mask = 0775
    [zuoypshare]
        comment = zuoyp share
        path = /mnt/data/zuoyp
        browseable = yes
        writeable = yes
        guest ok = yes
        public = yes
    
               

    各个参数的含义大家可以自行查资料,这里仅提供配置文件内容。

    其中最后一项[zuoypshare]是我自己添加的,我的共享目录的内容,包括comment—注释,path—路径等等。其中这个path就是你使用samba访问的共享文件夹。另外,这个[zuoypshare]字段要留意下,后面使用windows下映射磁盘时需要它的名字。

    你可以在/mnt/data/zuoyp这个目录下,随便touch几个文件,等会方便看。

    比如:

    centos7下搭建samba
    搞定后,重启samba服务,查看状态
    [[email protected] zuoyp]$ systemctl restart smb
    [[email protected] zuoyp]$ systemctl status smb
               
    测试smb.conf配置是否正确
    [[email protected] zuoyp]$ testparm
    Load smb config files from /etc/samba/smb.conf
    rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
    Processing section "[homes]"
    Processing section "[printers]"
    Processing section "[print$]"
    Processing section "[zuoypshare]"
    Loaded services file OK.
    Server role: ROLE_STANDALONE
    
    Press enter to see a dump of your service definitions
    
    # Global parameters
    [global]
    	log file = /var/log/samba/log.%m
    	max log size = 50
    	printcap name = cups
    	security = USER
    	server string = Samba Server Version %v
    	workgroup = MYGROUP
    	idmap config * : backend = tdb
    	cups options = raw
    
    
    [homes]
    	browseable = No
    	comment = Home Directories
    	inherit acls = Yes
    	read only = No
    	valid users = %S %D%w%S
    
    
    [printers]
    	browseable = No
    	comment = All Printers
    	create mask = 0600
    	path = /var/tmp
    	printable = Yes
    
    
    [print$]
    	comment = Printer Drivers
    	create mask = 0664
    	directory mask = 0775
    	force group = @printadmin
    	path = /var/lib/samba/drivers
    	write list = @printadmin root
    
    
    [zuoypshare]
    	comment = zuoyp share
    	guest ok = Yes
    	path = /mnt/data/zuoyp
    	read only = No
    [[email protected] zuoyp]$ smbc
    smbcacls    smbclient   smbcontrol  smbcquotas  
    [[email protected] zuoyp]$ smbc
    smbcacls    smbclient   smbcontrol  smbcquotas  
               

    下一步就是在windows下映射了,但在这之前你必须要做一件事:

    为你的当前用户配置samba密码:

    [[email protected] zuoyp]$ sudo smbpasswd -a zuoyp
    [sudo] zuoyp 的密码:
    New SMB password:
    Retype new SMB password:
    Added user zuoyp.
               
    如果你不做这一步,那么你在映射输入密码时,就会一直提示密码错误。
  4. windows下映射驱动器
    centos7下搭建samba
    centos7下搭建samba
    xx.xx.xx.xx是你虚拟机的ip地址,zuoypshare就是上面说到的samba配置时的标签名。然后点击完成,输入你上一步设置的用户名和samba密码即可访问啦。
    centos7下搭建samba

继续阅读