HOME 生活记录运维/编程
作者/来源:yixinu.com
栏目:运维/编程
日期:2012-04-21 09:12:33

安装:

    

[root@bogon ~]# yum install samba
……
 Installing     : samba-winbind-clients-3.5.5-68.fc14.1.i686                                          1/3 
  Installing     : samba-common-3.5.5-68.fc14.1.i686                                                   2/3 
  Installing     : samba-3.5.5-68.fc14.1.i686                                                          3/3 

Installed:
  samba.i686 0:3.5.5-68.fc14.1                                                                             

Dependency Installed:
  samba-common.i686 0:3.5.5-68.fc14.1             samba-winbind-clients.i686 0:3.5.5-68.fc14.1            

Complete!


smaba通过两个服务来控制 :

    nmbd:这个进程主要用来管理工作组,NETBIOS解析,主要用udp137,138端口来解析业务

    smbd:这个进程主要用来管理主机的文件共享 ,主要利用tcp协议来传输数据


example:

    1、配置服务

[global]
        workgroup = MYGROUP
        #工作组
        server string = Samba Server Version %v
        #服务器简要说明
        #hosts allow = 127. 192.168.12. 192.168.13.
        #指定可以访问的网段
        # log files split per-machine:

        log file = /var/log/samba/log.%m
        #日志文件存放位置
        # maximum size of 50KB per log file, then rotate:
        max log size = 50
        #日志文件达到50KB时,循环创建下一个日志文件

        security = user
        #验证模式,user表示需要输入验证用户名和密码,这里有三个选项,share表示不需要密码验证,domain 使用外部服务器的密码,亦即 SAMBA 是客户端之意,如果设定这个项目, 你还得要提供『password server = IP』的设定值才行;
        passdb backend = tdbsam

        # the following login script name is determined by the machine name
        # (%m):
        # the following login script name is determined by the UNIX user used:
        # use an empty path to disable profile support:
        # various scripts can be used on a domain controller or a stand-alone
        # machine to add or delete corresponding UNIX accounts:

        load printers = yes
        cups options = raw

        # obtain a list of printers automatically on UNIX System V systems:
[homes]
        comment = Home Directories
        browseable = no
        writable = yes
[printers]
        comment = All Printers
        path = /var/spool/samba
        browseable = no
        guest ok = no
        writable = no
        printable = yes
[httpd_www]     #在客户端显示的共享名 
        comment = Public Stuff   #目录说明
        path = /var/www   #共享的目录路径
        public = yes
        browseable = yes   #可以浏览目录内的文件
        writable = yes    #有写权限
        create mode = 766  #用户创建的文件的默认权限
        directory mode = 777    #用户创建的目录的默认权限

    2、开启服务并添加用户


[root@j071 ~]# /etc/init.d/smb start
Starting SMB services:                                     [  OK  ]
[root@j071 ~]# /etc/init.d/nmb start
Starting NMB services:                                     [  OK  ]
[root@j071 ~]#

添加用户

[root@j071 ~]# smbpasswd -a test1
New SMB password:
Retype new SMB password:
Added user test1.

查看添加是否有帐户信息
[root@j071 ~]# pdbedit -L
test1:503:
[root@j071 ~]#
     3、调试selinux



[root@j071 ~]# getsebool -a | grep -E "sam"
samba_create_home_dirs --> on
samba_domain_controller --> on
samba_enable_home_dirs --> on
samba_export_all_ro --> on
samba_export_all_rw --> on
samba_run_unconfined --> on
samba_share_fusefs --> on
samba_share_nfs --> on
use_samba_home_dirs --> on
virt_use_samba --> on
[root@j071 ~]# 

     4,OK ,用windows访问服务器IP地址,已经可以用test1用户访问到目录了



     linux 客户端连接

[root@bogon ~]# smbclient //192.168.73.173/httpd_www -U test1
Enter test1's password:
Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.5.5-68.fc14]
smb: > dir
  .                                   D        0  Mon Apr 23 18:15:40 2012
  ..                                  D        0  Wed Mar 28 23:02:10 2012
  cgi-bin                             D        0  Thu Jul  7 03:28:49 2011
  testfileb.txt                       A        0  Mon Apr 23 18:15:34 2012
  html                                D        0  Mon Apr 23 18:00:44 2012
  icons                               D        0  Wed Mar 28 21:54:57 2012
  testfile.txt                        A        0  Mon Apr 23 18:11:08 2012
  error                               D        0  Wed Mar 28 21:54:57 2012

                61025 blocks of size 524288. 27879 blocks available
smb: >


    mount 挂载


[root@bogon ~]# mount //192.168.73.173/httpd_www /mnt/j071www -o username=test1,password=test1

挂载成功

[root@bogon ~]# mount | grep httpd
//192.168.73.173/httpd_www on /mnt/j071www type cifs (rw,username=test1,password=test1)
[root@bogon ~]#


    写到 fstab 表


//192.168.73.173/httpd_www      /mnt/j071www            cifs    defaults,soft,intr,username=test1,password=test1        0 0

    使用cifs文件系统

    写上用户名和密码是为了不用每次开机都输入一次用户名和密码

    samba服务共享目录不能做扫描


其它工具

        smbpasswd -a user   添加用户

        smbpasswd -x user  删除用户

        testparm        检测samba语法 


smbclient  linux客户端工具

    smbclient -L 192.168.73.173 -U username  使用指定用户,查看主机共享的目录

    

分享到:

Copyright © 2013-2014 yixinu.com 湘ICP备14004402号

QQ:316686606  Email: 316686606@qq.com