Linux Samba服务器配置

来源:互联网 发布:金蝶软件标准版破解 编辑:程序博客网 时间:2024/05/18 14:23

http://mirrors.163.com/    文件下载地址     centos/os/package/samba

http://lym6520.iteye.com/blog/1850737   挂载共享文件夹



http://www.cnblogs.com/whiteyun/archive/2011/05/27/2059670.html

为了实现Windows主机与Linux服务器之间的资源共享,Linux操作系统提供了Samba服务,Samba服务为两种不同的操作系统架起了一座桥梁,使Linux系统和Windows系统之间能够实现互相通信,为广泛的Linux爱好者提供了极大方便。本文简要介绍如何在Linux操作系统上搭建Samba服务器和简单配置。

 

1、服务查询

默认情况下,Linux系统在默认安装中已经安装了Samba服务包的一部分 ,为了对整个过程有一个完整的了解,在此先将这部分卸载掉。使用命令

rpm -qa | grep samba ,默认情况下可以查询到两个已经存在的包:

samba-client-3.0.33-3.7.el5

samba-common-3.0.33-3.7.el5

 

2、卸载Samba

用rpm -e 将两个包卸载掉。对于samba-common-3.0.33-3.7.el5,因为与其它rpm包之间存在依赖关系,所以必须加参数-f和--nodeps,-f是指强制,--nodeps是指不检查依赖关系,具体完整命令为:

  rpm -e samba-common-3.0.33-3.7.el5 -f --nodeps

rpm -e samba-client-3.0.33-3.7.el5 -f --nodeps

 

3、安装Samba 

用以下命令安装:

rpm -ivh samba-3.0.33-3.29.el5_6.2.i386.rpm -f --nodeps

rpm -ivh samba-client-3.0.33-3.29.el5_6.2.i386.rpm  -f --nodeps
rpm -ivh samba-common-3.0.33-3.29.el5_6.2.i386.rpm -f --nodeps

安装完成后,使用命令rpm -qa | grep samba进行查询,发现搭建samba服务器所依赖的所有服务器都已经安装好了即可。

 

4、配置smb.conf文件

Samba的配置文件一般就放在/etc/samba目录中,主配置文件名为smb.conf,文件中记录着大量的规则和共享信息,所以是samba服务非常重要的核心配置文件,完成samba服务器搭建的大部分主要配置都在该文件中进行。

Samba服务器的工作原理是:客户端向Samba服务器发起请求,请求访问共享目录,Samba服务器接收请求,查询smb.conf文件,查看共享目录是否存在,以及来访者的访问权限,如果来访者具有相应的权限,则允许客户端访问,最后将访问过程中系统的信息以及采集的用户访问行为信息存放在日志文件中。 

第一步:修改配置文件

     首先备份一下samba的配置文件

cd /etc/samba

mv smb.conf smb.confbak

然后重新创建一个smb.conf文件

touch smb.conf

然后我们把这段写入smb.conf中 

[global]

     workgroup = LinuxSir

    netbios name = LinuxSir05
    server string = Linux Samba Server TestServer
    security = share

 [linuxsir]
            path = /opt/linuxsir
             writeable = yes
                browseable = yes 

   guest ok = yes

 

注解:

[global]这段是全局配置,是必段写的。其中有如下的几行;

workgroup 就是Windows中显示的工作组;在这里我设置的是LINUXSIR (用大写);
netbios name 就是在Windows中显示出来的计算机名;
server string 就是Samba服务器说明,可以自己来定义;这个不是什么重要的;
security 这是验证和登录方式,这里我们用了share ;验证方式有好多种,这是其中一种;另外一种常用的是user的验证方式;如果用share呢,就是不用设置用户和密码了;

[linuxsir] 这个在Windows中显示出来是共享的目录;
path = 可以设置要共享的目录放在哪里;
writeable 是否可写,这里我设置为可写;
browseable 是否可以浏览,可以;可以浏览意味着,我们在工作组下能看到共享文件夹。如果您不想显示出来,那就设置为 browseable=no

guest ok 匿名用户以guest身份是登录;

第二步:建立相应目录并授权; 

[root@localhost ~]# mkdir -p /opt/linuxsir

[root@localhost ~]# id nobody
uid=99(nobody) gid=99(nobody) groups=99(nobody)
[root@localhost ~]# chown -R nobody:nobody /opt/linuxsir 

    注释:

关于授权nobody,我们先用id命令查看了nobody用户的信息,发现他的用户组也是nobody,我们要以这个为准。有些系统nobody用户组并非是nobody ; 

 

第三步:启动smbd和nmbd服务器;

     [root@localhost ~]# smbd

     [root@localhost ~]# nmbd






http://blog.chinaunix.net/uid-26642180-id-3135941.html

一、安装前准备
1、使用Samba服务器需要防火墙开放以下端口
    UDP 137 UDP 138 TCP 139 TCP 445
#配置防火墙端口
[root@roothomes ~] vi /etc/sysconfig/iptables   
-A INPUT -m state --state NEW -m tcp -p tcp --dport 139 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 445 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 137 -j ACCEPT
-A INPUT -m state --state NEW -m udp -p udp --dport 138 -j ACCEPT
#重启防火墙,使规则生效
[root@roothomes ~] /etc/rc.d/init.d/iptables restart     

2、关闭CentOS6系统的 SELinux
[root@roothomes ~] vi /etc/selinux/config
#SELINUX=enforcing     #注释掉
#SELINUXTYPE=targeted  #注释掉
SELINUX=disabled       #增加
#:wq  保存。
#重启系统
[root@roothomes ~] shutdown -r now  或者 init 6

二、安装Samba
1、检查Samba服务包是否已安装
[root@roothomes ~] rpm -qa | grep samba
    samba-3.5.4-68.el6.x86_64
    samba-common-3.5.4-68.el6.x86_64
    samba-client-3.5.4-68.el6.x86_64
    samba4-libs-4.0.0-23.alpha11.el6.x86_64
    samba-winbind-clients-3.5.4-68.el6.x86_64

   说明samba已经安装,如果没有安装,运行下面命令安装 [root@roothomes ~] yum install samba 
   
2、配置samba
[root@roothomes ~] chkconfig smb on  #设置 Samba开机自动启动
[root@roothomes ~] service smb start      #启动Samba服务 
[root@roothomes ~] /etc/init.d/smb restart  #重启
[root@roothomes ~] /etc/init.d/smb stop    #停止 
[root@roothomes ~] cp /etc/samba/smb.conf  /etc/samba/bak_smb.conf_bak  #备份
[root@roothomes ~] cp /etc/samba/bak_smb.conf_bak  /etc/samba/smb.conf  #恢复
[root@roothomes ~] vi /etc/samba/smb.conf
[global]                           #找到这一行(全局设置标签),在此行下面添加如下行:
    workgroup = WORKGROUP          #工作组名称改为 Windows 网络所定义的工作组名
    server string = Samba Server   #设置samba服务器的主机名称
    security = user                #设置samba服务器安全级别为user,即以账号和口令访问
    netbios name = SambaServer     #设置Samba服务器访问别名
#在配置文件的末尾添加以下自定义内容
[SambaServer]                      #在Windows网上邻居中看到的共享目录的名字
    comment = SambaServer          #在Windows网上邻居中看到的共享目录的备注信息
    path = /home/SambaServer       #共享目录在系统中的位置
    public = no                    #不公开目录
    writable = yes                 #共享目录可以读写
    valid users=SambaServer        #只允许SambaServer用户访问
#保存配置

3、添加访问linux共享目录的账号SambaServer
   用户家目录为/home/SambaServer, 用户登录终端设为/bin/false(即使之不能登录系统)
[root@roothomes ~] mkdir -p /home/SambaServer #建立SambaServer文件夹
[root@roothomes ~] cd /home/SambaServer
[root@roothomes ~] touch  samba.txt   #创建测试文件samba.txt
[root@roothomes ~] useradd SambaServer -d /home/SambaServer -s /bin/false
[root@roothomes ~] chown SambaServer:SambaServer /home/SambaServer -R

4、将用户SambaServer添加入到Samba用户数据库,并设置登录共享目录的密码为:123456
[root@roothomes ~] smbpasswd -a SambaServer
   New SMB password:  输入该用户用于登录Samba的密码
   Retype new SMB password:  再次确认输入该密码
   Added user SambaServer.
#备注:这里设置的密码是SambaServer用户登录该机的Samba共享的密码,非登陆OS的密码;
5、重启Samba服务器
[root@roothomes ~] /etc/init.d/smb restart
6、浏览共享信息
在Windows客户端输入 \\ip  或者 \\SambaServer  #服务器别名
   回车之后,会跳出来登录框,输入账号SambaServer ,密码123456 , 即可访问共享目录



问题:
如果无法访问共享目录的内容,请把防火墙停止;
[root@roothomes ~] service iptables stop



0 0
原创粉丝点击