samba install

samba 安装

  1. 关闭selinux

    1
    2
    [root@10 ~]# setenforce 0
    [root@10 ~]# sed -i s/'SELINUX=enforcing'/'SELINUX=disabled'/g /etc/selinux/config
  2. 关闭防火墙

    1
    2
    [root@10 ~]# systemctl stop firewalld.service
    [root@10 ~]# systemctl disable firewalld.service
  3. samba 安装

    1
    [root@localhost ~]# yum -y install samba samba-client
  4. 创建共享目录

    1
    2
    [root@10 ~]# mkdir -p /mnt/data/samba/elasticsearch
    [root@10 ~]# chmod 777 /mnt/data/samba/elasticsearch
  5. samba 配置

    1
    2
    3
    4
    5
    6
    7
    8
    9
    [root@10 ~]# cp /etc/samba/{smb.conf,smb.conf.bak}
    [root@10 ~]# vim /etc/samba/smb.conf ==>追加
    [elasticsearch]
    comment = elasticsearch share
    path = /mnt/data/samba/elasticsearch
    hosts allow = 10.0.1. 10.0.2. 10.0.3. 10.0.4.
    browseable = no
    guest ok = no
    writable = yes
  6. 创建访问账号

    1
    2
    3
    4
    5
    [root@10 ~]# useradd -s /sbin/nologin smbuser
    [root@10 ~]# smbpasswd -a smbuser
    New SMB password: //123qwe`
    Retype new SMB password:
    Added user smbuser.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    //添加账号并设置密码
    smbpasswd -a smbuser

    //删除smb账号
    smbpasswd -x smbuser

    //禁用smb账号
    smbpasswd -d smbuser

    //启用smb账号
    smbpasswd -e smbuser
  7. 启动smb服务

    1
    [root@10 ~]# systemctl start smb
    1
    2
    3
    4
    5
    [root@10 ~]# netstat -lntp|grep smbd
    tcp 0 0 0.0.0.0:445 0.0.0.0:* LISTEN 5949/smbd
    tcp 0 0 0.0.0.0:139 0.0.0.0:* LISTEN 5949/smbd
    tcp6 0 0 :::445 :::* LISTEN 5949/smbd
    tcp6 0 0 :::139 :::* LISTEN 5949/smbd
  8. 客户端安装samba-client

    1
    [root@10 ~]# yum -y install samba-client
  9. 客户端查看共享资源

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    [root@10 ~]# smbclient -L //10.0.2.115
    Enter root's password: //查看共享信息,不需要密码,直接按回车键
    Anonymous login successful
    Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]

    Sharename Type Comment
    --------- ---- -------
    print$ Disk Printer Drivers
    IPC$ IPC IPC Service (Samba 4.4.4)
    Anonymous login successful
    Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]

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

    Workgroup Master
    --------- -------
  10. 客户端查看认证用户共享目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    [root@10 ~]# smbclient -U smbuser //10.0.2.115/elasticsearch
    Enter smbuser's password:
    Domain=[SAMBA] OS=[Windows 6.1] Server=[Samba 4.4.4]
    smb: \> ls
    . D 0 Sat Mar 11 15:27:59 2017
    .. D 0 Sat Mar 11 15:27:59 2017

    1048064000 blocks of size 1024. 1048031024 blocks available
    smb: \> help
    ? allinfo altname archive backup
    blocksize cancel case_sensitive cd chmod
    chown close del dir du
    echo exit get getfacl geteas
    hardlink help history iosize lcd
    link lock lowercase ls l
    mask md mget mkdir more
    mput newer notify open posix
    posix_encrypt posix_open posix_mkdir posix_rmdir posix_unlink
    print prompt put pwd q
    queue quit readlink rd recurse
    reget rename reput rm rmdir
    showacls setea setmode scopy stat
    symlink tar tarmode timeout translate
    unlock volume vuid wdel logon
    listconnect showconnect tcon tdis tid
    logoff .. !
    smb: \> quit
  11. 客户端挂载和卸载共享目录

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    [root@10 ~]# mkdir -p /mnt/ops/elasticsearch
    [root@10 ~]# chmod 777 /mnt/ops/elasticsearch
    [root@10 ~]# mount -t cifs //10.0.2.115/elasticsearch /mnt/ops/elasticsearch -o username=smbuser,password=123qwe\`

    或者:

    [root@10 ~]# mkdir -p /mnt/ops/elasticsearch
    [root@10 ~]# chmod 777 /mnt/ops/elasticsearch
    [root@10 ~]# vim /etc/fstab
    //10.0.2.115/elasticsearch /mnt/ops/elasticsearch cifs defaults,username=smbuser,password=123qwe` 0 0
    [root@10 ~]# mount -a

    [root@10 ~]# df -h |grep elasticsearch
    //10.0.2.115/elasticsearch 1000G 33M 1000G 1% /mnt/ops/elasticsearch

    [root@10 ~]# umount /mnt/ops/elasticsearch
  12. 拓展:不同用户访问不同目录(授权)

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    //创建两个组
    groupadd G1
    groupadd G2

    //创建三个用户
    useradd -s /sbin/nologin -g G1 U1
    useradd -s /sbin/nologin -g G1 U2
    useradd -s /sbin/nologin -g G2 U3

    //设置smb 密码
    smbpasswd -a U1
    smbpasswd -a U2
    smbpasswd -a U3

    //配置文件设置
    [test1]
    comment = Only U1 and U2 access
    path = /tmp/test1
    hosts allow = 10.0.1. 10.0.2. 10.0.3. 10.0.4.
    browseable = yes
    guest ok = no
    writable = yes
    write list = @G1

    [test2]
    comment = Only u3 access
    path = /tmp/test1
    hosts allow = 10.0.1. 10.0.2. 10.0.3. 10.0.4.
    browseable = no
    guest ok = no
    writable = yes
    write list = @G2