搭建基于SAMBA的文件服务器

在CentOS下面,搭建一个简单的SAMBA服务,可以让局域网内的Win机器直接使用文件服务器。

----------------------------------------------------------------------------------------

无密码访问方式

新建一个目录作为文件服务器的目录。因为是内部局域网使用,所以直接把目录权限设置为777了。

# mkdir /home/samba

# chmod 777 /home/samba

通过yum和rpm安装samba,相当容易,wait4friend这里就不作介绍了,直接从samba配置文件开始。 就一个配置文件 /etc/samba/smb.conf

首先是字符集的配置

# ----------------------- Charset Options --------------------------------
        dos charset = cp936
        unix charset = cp936

无密码访问

        security = share

文件服务目录配置

# A publicly accessible directory, but read only, except for people in
# the "staff" group
        [public]
        comment = Public Stuff
        path = /home/samba
        public = yes
        writable = yes
        printable = no
        create mode = 0664
        directory mode = 0775

语法检查:配置文件修改之后,使用testparm命令进行检查,看有没有语法错误。

# testparm
Load smb config files from /etc/samba/smb.conf
rlimit_max: increasing rlimit_max (1024) to minimum Windows limit (16384)
Processing section "[public]"
Loaded services file OK.
Server role: ROLE_STANDALONE
Press enter to see a dump of your service definitions

[global]
    dos charset = cp936
    unix charset = cp936
    workgroup = MYGROUP
    server string = Samba Server Version %v
    security = SHARE
    log file = /var/log/samba/log.%m
    max log size = 50
    cups options = raw

[public]
    comment = Public Stuff
    path = /home/samba
    read only = No
    create mask = 0664
    directory mask = 0775
    guest ok = Yes

启动服务:确认配置正确之后,启动服务,并且设置在3,5级别下的自动启动。samba有两个服务需要启动,分别是smb和nmb 。

# /etc/init.d/smb start
Starting SMB services:                                     [  OK  ]
# /etc/init.d/nmb start
Starting NMB services:                                     [  OK  ]
#
# chkconfig --level 35 smb on
# chkconfig --level 35 nmb on

确认监听端口

# netstat -tulnp |grep '[sn]mb'
tcp        0      0 :::139                      :::*                        LISTEN      2220/smbd          
tcp        0      0 :::445                      :::*                        LISTEN      2220/smbd          
udp        0      0 192.168.229.255:137         0.0.0.0:*                               2228/nmbd          
udp        0      0 192.168.229.201:137         0.0.0.0:*                               2228/nmbd          
udp        0      0 0.0.0.0:137                 0.0.0.0:*                               2228/nmbd          
udp        0      0 192.168.229.255:138         0.0.0.0:*                               2228/nmbd          
udp        0      0 192.168.229.201:138         0.0.0.0:*                               2228/nmbd          
udp        0      0 0.0.0.0:138                 0.0.0.0:*                               2228/nmbd          

到这里整个samba已经配置完成,Win下可以使用无密码登录进行访问了。

遗留问题

虽然在smb.conf里面指定了dos charset和unix charset 为中文CP936,但是在Win下建立的中文目录和文件名称,在Win环境显示正常,但是在Linux下还是显示为乱码。

原文地址:https://www.cnblogs.com/wait4friend/p/2494824.html