Openwrt下折腾 Samba4 配置

一、需求的由来

最近看过很多播主的视频后被成功洗脑购入了一台R4S 4G 版本的软路由。由于性能过剩不甘心只做路由器来使用,所以本着折腾的原则产生了一个想法。。。一物两用( 路由器 + NAS)。于是经过多天的努力我从开始刷别人编译固件到自己编译定制固件,在到功能配置整整折腾了差不多一周左右的时间。期间真是踩坑无数。。。点滴过程记录在这里希望可以帮到其他爱折腾的朋友少踩一些坑。

注:本文假设你已经完成 Openwrt系统的刷写固件过程并且固件中包含了 Samba4 版本支持 (请注意本文不适用于 samba3 版本)  

 

二、相关环境与版本

 

  • 基于Lean 源码编译固件, 固件版本: OpenWrt R21.2.1 / LuCI Master

  • 内核版本: 5.4.95

  • Samba4 版本: 4.11.6

  • 共享硬盘的文件系统: Ext4  (这个很关键后面说明) 

  • 客户端系统: macOS Big Sur

 

三、功能配置

[global]
    ## 网络共享名称
	netbios name = OpenWrt
    ## 绑定到的网络接口
	interfaces = br-lan 
    ## 服务描述信息
	server string = Samba on OpenWrt
	unix charset = UTF-8
    ## 工作域
	workgroup = WORKGROUP

    ## 加载相关功能模块(用来支持APF、弥补APF协议的一些缺陷以及一些功能扩展支持)
    vfs objects = catia fruit streams_xattr
    ## 这个选项如在某些环境下如果不指定目录权限不会被继承
    fruit:nfs_aces = no
    inherit permissions = yes

	## This global parameter allows the Samba admin to limit what interfaces on a machine will serve SMB requests.
	bind interfaces only = yes

	## time for inactive connections to-be closed in minutes
	deadtime = 15

    ## Log File
    log level = 4
    log file = /var/log/samba/samba.log

   
	## disable core dumps
	enable core files = no

	## set security (auto, user, domain, ads)
	security = user

	## map unknow users to guest
	map to guest = Bad User

	## The old plaintext passdb backend. Some Samba features will not work if this passdb backend is used. (NOTE: enabled for size reasons)
	## (tdbsam,smbpasswd,ldapsam)
	passdb backend = smbpasswd

	## LAN/WAN options (IPTOS_LOWDELAY TCP_NODELAY) WAN (IPTOS_THROUGHPUT)
	socket options = IPTOS_LOWDELAY TCP_NODELAY


	## disable loading of all printcap printers by default (iprint, cups, lpstat)
	load printers = No
	printcap name = /dev/null

	## Enabling this parameter will disable Samba's support for the SPOOLSS set of MS-RPC's.
	disable spoolss = yes

	## This parameters controls how printer status information is interpreted on your system.
	## (BSD, AIX, LPRNG, PLP, SYSV, HPUX, QNX, SOFTQ)
	printing = bsd

	## Allows the server name that is advertised through MDNS to be set to the hostname rather than the Samba NETBIOS name.
	## This allows an administrator to make Samba registered MDNS records match the case of the hostname rather than being in all capitals.
	## (netbios, mdns)
	mdns name = mdns



	## This is a list of files and directories that are neither visible nor accessible.
	## Each entry in the list must be separated by a '/', which allows spaces to be included in the entry. '*' and '?' can be used to specify multiple files or directories as in DOS wildcards.
	veto files = /Thumbs.db/.DS_Store/._.DS_Store/.apdisk/

	## If a directory that is to be deleted contains nothing but veto files this deletion will fail unless you also set the delete veto files parameter to yes.
	delete veto files = yes

################################################################

[TMDisk]
    ## 需要共享的目录所在路径 (我这里是单独一块硬盘的文件夹)
	path = /mnt/sda1/TMBackup

    ## 设置谁可以访问这个目录,默认配置下这个用户名来自于 /etc/samba/smbpasswd 文件.
    ## 使用 @前缀表示哪个用户组可以访问, 多个用户或分组使用逗号(,)间隔.
	valid users = timemachine,@root

    ## 目录是否可以写入
    writable = yes
    ## 目录只读(与 writable 参数互斥)
    read only = no
    ## 文件权限掩码
    create mask = 0666
    ## 目录权限掩码 
	directory mask = 0755

    ## 这个目录在网络中是否可以被人看到;如果设置为 no 则别人不会看到,但是可以通过路径来直接访问
    #browseable = no
    ## 继承acl 权限控制(暂时还没搞清这个参数,设置后有问题,所以注释了)
    #inherit acls = yes
    ## 文件或目录的所有者继承;相当于你在根目录创建一个文件夹后其他人创建的目录和文件将都属于你
	inherit owner = yes

	## file/dir creating rules
    ## 这个参数相当于是给目录绑定默认分组
	#force group = timemachine
    ## 相当于绑定默认账户(当设置参数guest ok = yes 时这两个参数可能会发挥价值)
	#force user = timemachine

    #fruit:nfs_aces = no
	fruit:encoding = native
    ## 支持MAC用户对文件或目录写入元数据
	fruit:metadata = stream
    ## 是否否决 _ AppleDouble 文件的创建(设置为 yes 那么 苹果的 timemachine 功能可能无法使用)
	fruit:veto_appledouble = no
    ## 官方文档中说这个参数是用来设置图标的(实际好像没有效果 - -)
    fruit:model = MacSamba
    ## 设置这个目录作为 苹果的 TimeMachine 
	fruit:time machine = yes

######### Dynamic written config options #########

以上是我的 Samba4服务配置信息,来自 /etc/samba/smb.conf.template 文件内。

 

服务相关操作命令:

    启动服务: service samba4 start
    停止服务: service samba4 stop
    重启服务: service samba4 restart
    服务状态: service samba4 status

    配置文件检查: testparm -v

 

服务相关配置文件及路径:

    /etc/samba
    /etc/config/samba4 (暂时没明白这个配置是干什么用的,好像与 smb.conf 文件有些重叠)

    日志路径: /var/samba/samba.log (这个路径通过配置文件中的 ”log file“ 参数来指定,默认是不存在的)

     其他:建议不要直接修改 smb.conf 这个文件,因为每次重启服务这个文件都会被 smb.conf.template 的文件内容给覆盖掉

 

 

四、问题整理

 

  1. 挂载目录文件系统问题;共享目录最好使用 Ext4 文件系统, 因为我最开始的时候文件系统用的是 NTFS,结果按照上述配置后无法进行文件写入,在 macOS 系统下会提示 “遇到意外xxxxxxx 错误码100093”。主要原因猜测可能为 samba4 对 NTFS 文件系统使用 Windows 权限控制机制(openwrt 是基于linux 的,使用的文件系统一般为 ext4 )导致权限混乱无法正常写入文件。
     
  2. 挂载目录的访问权限问题;如果你是像我一样将硬盘直接挂载到openwrt 的某个目录上面并直接配置samba4进行共享,那么你很有可能会遇到服务能访问但无法上传或创建文件的问题。这个问题的产生原因有很多种可能。在这里说一下解决思路,不细说过程了。

    a) 首先需要排查挂载目录的权限; 假设你的硬盘挂载目录是 /mnt/sda1  则进入到该目录下 通过 ll 命令检查 这个目录的权限(所有者、所属组、读写权限) 是否达标。如果你很懒的话可以使用命令 chmod 777 -R /mnt/sda1 直接解放这个目录及这个挂载目录下的所有子项, 这样保证我们的挂载目录权限是ok的.

    b) 检查 Samba4 的配置是否正确,主要配置参数如下:

         writable = yes
         valid users = timemachine,@root
         read only = no
         create mask = 0666
         directory mask = 0755
         inherit owner = yes
         inherit permissions = Yes
         guest ok = yes
         guest only = yes
        

五、相关帮助链接

          解决问题的过程中参考了很多资料,相关的链接整理如下:

             Samba 服务配置文件说明 https://www.samba.org/samba/docs/current/man-html/smb.conf.5.html

             Samba 服务扩展功能配置 https://www.samba.org/samba/docs/current/man-html/vfs_fruit.8.html

             macOS 客户端访问基于 Samba4 搭建 TimeMachine 说明 https://developer.apple.com/forums/thread/666293

             NTFS 文件系统的 Samba4 访问问题

           

      

  • 1
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值