CentOS 7 samba共享

背景
原计划基于Windows(主)+Linux(从)搭建SQL server主从同步,基于共享同一个目录而尝试用samba
#测试之后发现无法实现,因为Linux和Windows存放数据的文件夹不同,双发无法识别(个人想法)

 

环境
[root@node1 ~]# lsb_release -a
LSB Version:    :core-4.1-amd64:core-4.1-noarch:cxx-4.1-amd64:cxx-4.1-noarch:desktop-4.1-amd64:desktop-4.1-noarch:languages-4.1-amd64:languages-4.1-noarch:printing-4.1-amd64:printing-4.1-noarch
Distributor ID:    CentOS
Description:    CentOS Linux release 7.5.1804 (Core)
Release:    7.5.1804
Codename:    Core

 

查看是否安装
rpm -qa samba


安装
yum -y install samba samba-client
samba配置
cd /etc/samba/
mv smb.conf smb.conf.origin
新建smb.conf
vim smb.conf

[global]
        workgroup = WORKGROUP
        server string = Ted Samba Server %v
        netbios name = TedSamba
        security = user
        map to guest = Bad User
        passdb backend = tdbsam

[FileShare]
        comment = share some files
        path = /smb/fileshare
        public = yes
        writeable = yes
        create mask = 0644
        directory mask = 0755

[WebDev]
        comment = project development directory
        path = /smb/webdev
        valid users = ted
        write list = ted
        printable = no
        create mask = 0644
        directory mask = 0755


注释:
workgroup 项应与 Windows 主机保持一致,这里是WORKGROUP
security、map to guest项设置为允许匿名用户访问
再下面有两个section,实际为两个目录,section名就是目录名(映射到Windows上可以看见)。
第一个目录名是FileShare,匿名、公开、可写
第二个目录吗是WebDev,限定ted用户访问
默认文件属性644/755(不然的话,Windows上在这个目录下新建的文件会有“可执行”属性)


创建用户
[root@base samba]# groupadd co3
[root@base samba]# useradd ted -g co3 -s /sbin/nologin
[root@base samba]# smbpasswd -a ted
New SMB password:
Retype new SMB password:
Added user ted.
[root@base samba]#
注意这里smbpasswd将使用系统用户。设置密码为1
创建共享目录
[root@base samba]# mkdir -p /smb/{fileshare,webdev}
[root@base samba]# chown nobody:nobody /smb/fileshare/
[root@base samba]# chown ted:co3 /smb/webdev/
注意设置属性,不然访问不了。
启动Samba服务,设置开机启动
[root@base samba]# systemctl start smb
[root@base samba]# systemctl enable smb
Created symlink from /etc/systemd/system/multi-user.target.wants/smb.service to /usr/lib/systemd/system/smb.service.
[root@base samba]#
开放端口
[root@base samba]# firewall-cmd --permanent --add-port=139/tcp
success
[root@base samba]# firewall-cmd --permanent --add-port=445/tcp
success
[root@base samba]# systemctl restart firewalld
[root@base samba]#
或者直接把防火墙关了也行。

注意:腾讯云后台有个安全组也要打开响应的端口.

 

使用本机测试
可以使用testparm测试samba配置是否正确
[root@base samba]# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[FileShare]"
Processing section "[WebDev]"
Loaded services file OK.
Server role: ROLE_STANDALONE

Press enter to see a dump of your service definitions

# Global parameters
[global]
    netbios name = TEDSAMBA
    server string = Ted Samba Server %v
    map to guest = Bad User
    security = USER
    idmap config * : backend = tdb


[FileShare]
    comment = share some files
    path = /smb/fileshare
    guest ok = Yes
    read only = No


[WebDev]
    comment = project development directory
    path = /smb/webdev
    create mask = 0644


    valid users = ted
    write list = ted

root用户的话,不用密码可直接查看samba服务器情况
[root@base samba]# smbclient -L localhost
Enter root's password:
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]

    Sharename       Type      Comment
    ---------       ----      -------
    FileShare       Disk      share some files
    WebDev          Disk      project development directory
    IPC$            IPC       IPC Service (Ted Samba Server 4.4.4)
Domain=[WORKGROUP] OS=[Windows 6.1] Server=[Samba 4.4.4]

    Server               Comment
    ---------            -------

    Workgroup            Master
    ---------            -------
 

Windows客户端访问\\123.206.207.197

CentOS 7 samba共享_第1张图片

Linux 访问windows共享文件
#smbclient //192.168.1.1/smb_share/ smb_user_passwd -U smb_user  #不提示输入密码
smbclient //115.159.24.172/DB_backup/ pwd@123 -U sqladmin
quit

 

 

 

 

你可能感兴趣的:(共享)