Linux 文件服务器

NAS  #linux+samba | FTP 的结合体,实现内部共享

SAN  #linux+samba | FTP 通过光纤,公网IP,实现公网共享


 

yum install samba -y

 

1.1. 服务与端口号

 

service nmb restart   老系统

service smb restart  

 

UPD:

TCP:

 

 

 

1.2. 防火墙配置

 

iptables -I INUPT 1 -P --dport 137:138 -jACCEPT

iptables -i INUPT 1 -P --dport 139 -jACCEPT

iptables -i INUPT 1 -P --dport 445 -jACCEPT

 

 

 

 

1.3. 主配置文件

 

[root@localhost ~] # Testparm smb.comf     # 配置文件检查配置文件是否正确

 

 

 

[root@localhost ~] # cd /etc/samba/

[root@localhost samba]# ll

总用量

-rw-r--r--. 1 root root   20 1月

-rw-r--r--. 1 root root 9778 1月

-rw-r--r--. 1 root root   97 1月

[root@localhost samba]#

 

 

 

 

配置文件

 

vi /etc/samba/smb.conf

 

#======================= Global Settings全局设置===============================

 

# ----------------------- Network RelatedOptions -------------------------

网络相关选项

 

工作组 要与windows一致

描述信息

  config file = /etc/samba/smb.conf.%U    # 指定用户权限

;      netbios name = MYSERVER

 

      vetofiles  = /*.exe/*.rar/*.zip/      # 禁止上传文件类型

       hide files  =  /*.exe/*.dll/*.com/      # 文件隐藏

 

;      interfaces = lo eth0 192.168.12.2/24 192.168.13.2/24 

流量监听从哪个接口访问 默认所有接口

;      hosts allow = 127. 192.168.12. 192.168.13.

限制主机访问范围

 

# ----------------------- Standalone ServerOptions ------------------------

独立服务器选项

验证方式

 

为无密码访问 user 为用户和密码访问

此项为后加,同时支持匿名访问

       passdb backend = tdbsam

 

#

#

 

# ----------------------- Domain MembersOptions ------------------------

域成员选项  加入域的设置

 

 

 

 

 

# ----------------------- Domain ControllerOptions ------------------------

模拟域控制器PDC   将此服务器变成域控

 

;      security = user

;      passdb backend = tdbsam

 

;      domain master = yes

;      domain logons = yes

 

       # the login script name depends on the machine name

;      logon script = %m.bat

       # the login script name depends on the unix user used

;      logon script = %u.bat

;      logon path = \\%L\Profiles\%u

       # disables profiles support by specifing an empty path

;      logon path =

 

;      add user script = /usr/sbin/useradd "%u" -n -g users

;      add group script = /usr/sbin/groupadd "%g"

;      add machine script = /usr/sbin/useradd -n -c "Workstation(%u)" -M -d /nohome -s /bin/false "%u"

;      delete user script = /usr/sbin/userdel "%u"

;      delete user from group script = /usr/sbin/userdel "%u""%g"

;      delete group script = /usr/sbin/groupdel "%g"

 

# ----------------------- Browser ControlOptions ----------------------------

浏览器控制选项

;      local master = no

;      os level = 33

;      preferred master = yes

 

#----------------------------- NameResolution -------------------------------

名称解析wins

 

;      wins support = yes

;      wins server = w.x.y.z

;      wins proxy = yes

 

;      dns proxy = yes

 

 

# --------------------------- PrintingOptions -----------------------------

共享打印

 

 

       load printers = yes

       cups options = raw

 

;      printcap name = /etc/printcap

       #obtain list of printers automatically on SystemV

;      printcap name = lpstat

;      printing = cups

 

# --------------------------- FilesystemOptions ---------------------------

文件系统选项

 

;      map archive = no

;      map hidden = no

;      map read only = no

;      map system = no

;      store dos attributes = yes


    

 

 

#============================ ShareDefinitions ==============================

定义共享设置

# 可以设置多个[public]

;      [public]           # 共享名

;      comment = Public Stuff

;      path = /home/samba           # 共享路径

;      public = yes                 # 允说匿名访问

;      writable = yes               # 写权限

;      write list =user1  +root         # 设置写规则,指定用户user1能写 需关闭writable=no

代表指定root组都可以写

;      browseable=no           # 默认是Yes  隐藏共享,等于于windows下的c$

是否为打印机共享   启用后共享图标会变成打印机

 

 

 

 

 

 

1.4. 指定用户隐藏共享c$

# 当配置此功能时,代表所指用户能够查看到所有共享,而未设置的用户,则看不到共享文件

 

config file =/etc/samba/smb.conf.%U    # 指定用户权限

 

 

在/etc/samba目录下,创建一个以下文件

 

cp smb.conf smb.conf.user1

 

vi smb.conf.user1

 

在smb.conf中的设置

#============================ ShareDefinitions ==============================

共享设置

 

共享名

      comment = Public Stuff

共享路径

允说匿名访问

写权限

设置写规则,指定用户user1能写 需关闭

代表root组都可以写

浏览权限  隐藏共享  等同于c$

 

 

在smb.conf.user1中的设置

 

#============================ ShareDefinitions ==============================

共享设置

 

;      [public]           # 共享名

;      comment = Public Stuff

;      path = /home/samba           # 共享路径

;      public = no                 # 允说匿名访问

;      writable = no               # 写权限

;      write list = user1          # 设置写规则,指定用户user1能写 需关闭writable=no

代表root组都可以写

;      browseable=yes 

 

 

1.5. 客户端查询验证共享

 

smbclient -L //192.168.1.100   # 查看服务器的共享  可指定用户

 

smbclient -L //192.168.1.100 -U user1

 

smbtree -n     # 查看本机共享

 

客户端访问:

 

smbclient //192.168.1.100/aa -Uuser1%passwd

 

 

 

配置检查:

 

Testparm smb.conf

 

 

检查连接:

 

smbstatus

 

 

 

 

1.6. samba用户管理

新建用户:

useradd user1        # 建立smaba用户名

 

将系统用户加入samba服务中

pdbedit -au user1  # 将user1用户加入到samba服务中

 

管理samba用户:

smbpasswd -a user1   # 修改samba用户密码   可以与系统的密码不一样

smbpasswd -d user1   # 禁用

smbpasswd -e user1   # 恢复

smbpasswd -x user1   # 删除

 

 

\\server\bob\profile

 

 

# 查看smaba用户列表

[root@localhost /]# pdbedit -L

 

 

pdbedit -Lv user1  # 查看samba中user1详细信息

 

 

 

 

 

 

 

 

 

1.7. 关于selinux的设置

 

ls -ldz /aa    # 查看共享目录aa的属性

 

chcon -t samba_share_t /aa     # 修改属性

 

 

1.8. PDC服务器的管理

# linux底下的虚拟活动目录DC

 

vi /etc/smaba/smb.conf

 

# ----------------------- Domain MembersOptions ------------------------

 

 

;      security = domain      # 开启

;      passdb backend = tdbsam

;      realm = MY_REALM

 

;      password server = <NT-Server-Name>

 

 

# ----------------------- Domain ControllerOptions ------------------------

 

开启 只能user

 

开启

开启

 

       # the login script name depends on the machine name

      

开启登录时运行脚本 默认路径在/etc/samba/netlogon/ 要手动创建

 

*****test.bat********************************************************************

 

net user k: /home

 

*******************************************************************************

对test.bat做如下操作,让linux识别bat文件

l 安装yum install unix2dos软件

l unix2dos/etc/samba/netlogon/test.bat  # 转换成windows能识别的格式

 

     # the login script name depends on the unix user used

 

开启  登录时初始个性配置 就是个人配置文件存放

开启  %N 是服务器IP  %U用户  登入家目录

     

 

# ----------------------- Browser ControlOptions ----------------------------

      

开启

开启   客户端服务器类型

开启

 

 

#----------------------------- NameResolution -------------------------------

 

开启 开启主机名与IP解析的NETBIOS  因为没有DNS

 

 

 

 

 

 

 

 

 

 

 

创建PDC用户

 

l 创建/home/samba/user1目录

l useradd -d /home/samba/user1user1     # 创建用户和家目录

l pdbedit -a -u user1    # 加入PDC用户

 

 

 

客户端加入域

 

useradd -M -D /dev/null -s/sbin/nologin  winxp$   # 加入计算机用户winxp$为计算机名

 

smbpasswd -a -m winxp$   # 加入域用户

 

 

 

1.9. samba实例

1.   rootpreexce= find /data -size +10000000c -exec  rm -fr {} \;

2.  rootpostexec = find /data -size +10000000c -exec rm -fr {} \;

 

1.10.不同用户只能修改指定的目录

 

       [zhb]

       comment = Public Stuff

       path = /home/zhb

       public = no

       writable = no

       write list = user1

       browseable=yes

 

       [zlb]

       comment = Public Stuff

       path = /home/zlb

       public = yes

       writable = no

       write list = user2

        browseable=yes

 

       [scb]

       comment = Public Stuff

       path = /home/scb

       public = scb

       writable = no

       write list = user3

        browseable=yes

 

1.11. 步骤精华  ★★★

 

1.12. 故障排错

 

1.如果写文件提示拒绝访问?

 

a.检查配置文件是否开启写权限

b.检查目录的自身权限是否有写权限

c.检查selinux是否开启

 

 

2.无法访问,您可能没有权限使用网络资源

 

不允许一个用户使用一个以上用户名与一个服务器或共享资源的多重连接

 

net user * /del

 

# 清除缓存记录

 

 

3.无法查询远程主机共享

 

[root@server2 ~]# smbclient -L//192.168.242.128

Enter root's password:

Domain=[MYGROUP] OS=[Unix] Server=[Samba3.6.23-24.el6_7]

Server requested LANMAN password(share-level security) but 'client lanman auth = no' or 'client ntlmv2 auth =yes'

tree connect failed:NT_STATUS_ACCESS_DENIED

 

[root@redhat yum.repos.d]# smbclient -L\\10.204.2.200

Enter root's password:

session setup failed:NT_STATUS_LOGON_FAILURE

 

# 因为root不是samba的用户,所以无法查看,-u user1   指定用户查看,user1一定要加入samba服务