• CentOS下Samba文件服务器的安装与配置


    CentOS下Samba文件服务器的安装与配置 http://blog.csdn.net/limingzhong198/article/details/22064801

    一、安装配置

    1. 安装samba
    yum -y install samba samba-client

    2. 查看安装情况
    # rpm -qa | grep samba
    samba-client-3.0.33-3.40.el5_10
    samba-3.0.33-3.40.el5_10
    samba-common-3.0.33-3.40.el5_10

    3. 启动samba
    [root@localhost ~]# service smb start
    Starting SMB services: [ OK ]
    Starting NMB services: [ OK ]

    4. 关闭SElinux和Iptables
    直接使用service smb start 启动Samba服务。
    # getenforce 命令可以查看SElinux的状态 ,# setenforce 0可以暂时关闭SElinux,在/etc/selinux/config中把SELINUX= enforcing更改为SELINUX=disable可以永久关闭SELinux
    # service iptables status可以查看Iptables的状态,# service iptables stop可以暂时关闭,# chkconfig iptables off可以永久关闭防火墙。
    最后关闭后的状态应该是
    SElinux:Disabled
    Iptables:Firewall is not running
    这两个服务在没配置时一定要是关闭状态,不然会访问不到!


    5. 查看启动情况
    # service smb status

    6. 设置开机自启动
    # chkconfig --level 35 smb on //在3、5级别上自动运行samba服务

    7. 检查是否成功:
    [root@localhost share]# chkconfig --list | grep smb
    smb 0:off 1:off 2:off 3:on 4:off 5:on 6:off
    结果显示在3、5级别上自动运行samba服务,则表示设置成功

    8.配置:
    [root@localhost ~]# cd /etc/samba/
    [root@localhost samba]# cp smb.conf smb.conf.bak20160220
    [root@localhost samba]# vi /etc/samba/smb.conf
    在文件中添加或者修改下面大括号内的相关代码:
    {
    workgroup = WORKGROUP //定义工作组,也就是windows中的工作组概念
    server string = Lmz Samba Server Version %v //定义Samba服务器的简要说明
    netbios name = LmzSamba //定义windows中显示出来的计算机名称
    //定义Samba用户的日志文件,%m代表客户端主机名
    //Samba服务器会在指定的目录中为每个登陆主机建立不同的日志文件
    log file = /var/log/samba/log.%m
    security = share //共享级别,用户不需要账号和密码即可访问
    [public] //设置针对的是共享目录个别的设置,只对当前的共享资源起作用
    comment = Public Stuff //对共享目录的说明文件,自己可以定义说明信息
    path = /share //用来指定共享的目录,必选项
    public = yes //所有人可查看,等效于guest ok = yes
    }


    9.建立共享目录
    mkdir /share
    cd /share ; touch 1111.txt; touch 2222.txt ; mkdir dd;

    为/share目录给匿名用户授权为nobody权限
    chown -R nobody:nobody /share/

    10. 设立samba登录账户

      smbpasswd -a <usrname>
    11. 重启smb服务 /etc/init.d/smb restart

    12. 测试smb.conf配置是否正确
    [root@localhost share]# testparm

    13.访问Samba服务器的共享文件:
    CentOS系统下测试:


    [root@localhost share]# smbclient //127.0.0.1/public
    Password:
    Domain=[WORKGROUP] OS=[Unix] Server=[Samba 3.0.33-3.40.el5_10]
    Server not using user level security and no password supplied.
    smb: > ls
    . D 0 Fri Feb 19 17:51:56 2016
    .. D 0 Fri Feb 19 17:49:50 2016
    1111.txt 5 Fri Feb 19 17:51:10 2016
    dd D 0 Fri Feb 19 17:52:12 2016
    2222.txt 5 Fri Feb 19 17:51:16 2016

    61880 blocks of size 65536. 10157 blocks available


    Windows下测试:
    在浏览器地址栏输入\192.168.2.109public ,看到/share/目录下面的文件夹和文件。
    或Win+R输入\192.168.2.109public ,也能看到/share/目录下面的文件夹和文件。

    二、错误说明

    1. 不能访问: NT_STATUS_ACCESS_DENIED listing *    https://my.oschina.net/sfilyh/blog/42567

    解决方法:关闭SELIUNX
    
    [root@linux /]# getenforce   ;查看当前状态
    Enforcing
    [root@linux /]# setenforce 0 ;关闭
    
    -------------------- SELINUX几种状态表示: enforcing:强制模式,代表 SELinux 运行中,且已经正确的开始限制 domain
    /type 了; permissive:宽容模式:代表 SELinux 运行中,不过仅会有警告信息并不会实际限制 domain/type 的存取。这种模式可以运来作为 SELinux 的 debug 之用; disabled:关闭,SELinux 并没有实际运行。

    ============================================

    13. centos7配置samba 实例

    (1) install
    [root@localhost ~]# yum -y install samba samba-client samba-common

    (2)save config file
    [root@localhost ~]# cp /etc/samba/smb.conf /etc/samba/smb.conf.origin

    (3)modify config file
    [root@localhost ~]# vi /etc/samba/smb.conf
    [global]
            workgroup = WORKGROUP
            netbios name = CentOS7
            server string = Samba Server
            security = user
            encrypt passwords = yes
            max connections = 0
            security = user
            smb passwd file = /etc/samba/smbpasswd
            username map = /etc/samba/smbusers
    [share]
            path = /root
            writable = yes
            guest ok = yes
            write list = @root
            validusers = @root
            display charset = UTF-8
            unix charset = UTF-8
            dos charset = cp936
    (4) modify  user name map      
    [root@localhost ~]# vi /etc/samba/smbusers
        [root] = "Ocean"
    (5) modify remote user name and passwd   
    [root@localhost ~]# touch /etc/samba/smbpasswd
    [root@localhost ~]# smbpasswd -a root     

    (6) restart samba
    [root@localhost ~]# service smb restart
    (7) test samba on linux host
    [root@localhost ~]# smbclient //127.0.0.1/share

    (8) some other command may be used
    [root@localhost ~]# testparm ; 查看samba配置项
    [root@localhost ~]# testparm -v -s  | grep share;查看samba详细的配置项, grep过滤字段.
    [root@localhost ~]# systemctl stop firewalld.service ; 关闭防火墙
    [root@localhost ~]# vi /etc/security/limits.conf ;设置用户可以同时打开的最大文件数, 等等等
    [root@localhost ~]# ulimit -n 16384 ; 设置用户可以同时打开的最大文件数

    ============================================

    本文只是最基本的配置,不涉及安全的考虑。

    更多的,参考: 

    CentOS 6.4下安装和配置Samba  http://www.linuxidc.com/Linux/2013-10/90935.htm

     

  • 相关阅读:
    linux那点事儿(六)进程管理详解(推荐)
    linux那点事儿(下)
    视图的架构刷新和绑定
    HttpHandler开发的两个重点问题
    RichTextBox控件的几点有意思的东西
    重复输入某个字符(C++,C#)
    几个博客系统点评
    怎么理解符号整数的取值范围(C++)
    为SSIS编写自定义任务项(Task)之进阶篇
    LINQ TO XML之判断不存在行则插入
  • 原文地址:https://www.cnblogs.com/mylinux/p/5202792.html
Copyright © 2020-2023  润新知