Linux局域网文件分享系统Samba

  原作者:http://blog.csdn.net/jhq0113/article/details/44159251

上学的时候在学校机房见过FTP做的文件分享系统,服务器是Windows的,当时感觉功能真的很强大,不管是哪台机器都可以共享一个文件夹,后来自己在家里通过查阅各种资料,用自己的win7做FTP服务器,做了一个文件服务器,但是真的很鸡肋,操作体验真的不尽人意。


      下面介绍的是Linux服务器平台安装的文件分享系统软件Samba,通过Samba部署的文件分享系统可以兼容Mac、Linux和Windows三大主流操作系统,而且操作体验也非常好,自己在家里做了一个小型分享系统,家用服务器的配置:CPU:凌动 D2500,2G内存,32G SSD的一个小型服务器,4m带宽,速度秒杀FTP,文件上传和下载都在11M/s左右。


         下面简单介绍一下CentOS下yum安装过程,如果是在公司内部用,一般会编译安装samba,然后会做一些细节的权限验证,我做家用,能用就可以了,如果你想做更细节的权限分配,去度娘,参考资料好几mol。


         安装:

         [root@jhq0229 ~]# yum install samba samba-client samba-swat


          设置smb和nmb在3、5启动级别随系统启动:

          [root@jhq0229 ~]# chkconfig --level 35 smb on

          [root@jhq0229 ~]# chkconfig --level 35 nmb on


          配置Samba:

          [root@jhq0229 ~]# vim /etc/samba/smb.conf

        

          进行如下修改:

          

  1. #======================= Global Settings =====================================  
  2.   
  3. [global]  
  4.   
  5. config file = /usr/local/samba/lib/smb.conf.%m  
  6.   
  7. # ----------------------- Network Related Options -------------------------  
  8. #  
  9. # workgroup = NT-Domain-Name or Workgroup-Name, eg: MIDEARTH  
  10. #  
  11. # server string is the equivalent of the NT Description field  
  12. #  
  13. # netbios name can be used to specify a server name not tied to the hostname  
  14. #  
  15. # Interfaces lets you configure Samba to use multiple interfaces  
  16. # If you have multiple network interfaces then you can list the ones  
  17. # you want to listen on (never omit localhost)  
  18. #  
  19. # Hosts Allow/Hosts Deny lets you restrict who can connect, and you can  
  20. # specifiy it as a per share option as well  
  21. #  
  22.         workgroup = MYGROUP  
  23.         server string = Samba Server Version %v  
  24.   
  25. ;       netbios name = MYSERVER  
  26.   
  27.         interfaces = lo eth0 192.168.1.11/24 192.168.1.1/255  
  28.   
  29.         hosts allow = 127. 192.168.1. 192.168.0.  
  30.   
  31. # --------------------------- Logging Options -----------------------------  
  32. #  
  33. # Log File let you specify where to put logs and how to split them up.  
  34. #  
  35. # Max Log Size let you specify the max size log files should reach  
  36.   
  37.         # logs split per machine  
  38.         log file = /var/log/samba/log.%m  
  39.         # max 50KB per log file, then rotate  
  40.         max log size = 50  
  41.   
  42. # ----------------------- Standalone Server Options ------------------------  
  43. #  
  44. # Scurity can be set to user, share(deprecated) or server(deprecated)  
  45. #  
  46. # Backend to store user information in. New installations should   
  47. # use either tdbsam or ldapsam. smbpasswd is available for backwards   
  48. # compatibility. tdbsam requires no further configuration.  
  49.   
  50.         security=share  
  51.         #security = user  
  52.         #passdb backend = tdbsam  
  53.   
  54.   
  55. # ----------------------- Domain Members Options ------------------------  
  56. #  
  57. # Security must be set to domain or ads  
  58. #  
  59. # Use the realm option only with security = ads  
  60. # Specifies the Active Directory realm the host is part of  
  61. #  
  62. # Backend to store user information in. New installations should   
  63. # use either tdbsam or ldapsam. smbpasswd is available for backwards   
  64. # compatibility. tdbsam requires no further configuration.  
  65. #  
  66. # Use password server option only with security = server or if you can't  
  67. # use the DNS to locate Domain Controllers  
  68. # The argument list may include:  
  69. #   password server = My_PDC_Name [My_BDC_Name] [My_Next_BDC_Name]  
  70. # or to auto-locate the domain controller/s  
  71. #   password server = *  
  72.   
  73.   
  74. ;       security = domain  
  75. ;       passdb backend = tdbsam  
  76. ;       realm = MY_REALM  
  77.   
  78. ;       password server = <NT-Server-Name>  
  79.   
  80. # ----------------------- Domain Controller Options ------------------------  
  81. #  
  82. # Security must be set to user for domain controllers  
  83. # use either tdbsam or ldapsam. smbpasswd is available for backwards   
  84. # compatibility. tdbsam requires no further configuration.  
  85. #  
  86. # Domain Master specifies Samba to be the Domain Master Browser. This  
  87. # allows Samba to collate browse lists between subnets. Don't use this  
  88. # if you already have a Windows NT domain controller doing this job  
  89. #  
  90. # Domain Logons let Samba be a domain logon server for Windows workstations.   
  91. #  
  92. # Logon Scrpit let yuou specify a script to be run at login time on the client  
  93. # You need to provide it in a share called NETLOGON  
  94. #  
  95. # Logon Path let you specify where user profiles are stored (UNC path)  
  96. #  
  97. # Various scripts can be used on a domain controller or stand-alone  
  98. # machine to add or delete corresponding unix accounts  
  99. #  
  100. ;       security = user  
  101. ;       passdb backend = tdbsam  
  102.   
  103. ;       domain master = yes   
  104. ;       domain logons = yes  
  105.   
  106.         # the login script name depends on the machine name  
  107. ;       logon script = %m.bat  
  108.         # the login script name depends on the unix user used  
  109. ;       logon script = %u.bat  
  110. ;       logon path = \\%L\Profiles\%u  
  111.         # disables profiles support by specifing an empty path  
  112. ;       logon path =            
  113.   
  114. ;       add user script = /usr/sbin/useradd "%u" -n -g users  
  115. ;       add group script = /usr/sbin/groupadd "%g"  
  116. ;       delete user script = /usr/sbin/userdel "%u"  
  117. ;       delete user from group script = /usr/sbin/userdel "%u" "%g"  
  118. ;       delete group script = /usr/sbin/groupdel "%g"  
  119.   
  120.   
  121. # ----------------------- Browser Control Options ----------------------------  
  122. #  
  123. # set local master to no if you don't want Samba to become a master  
  124. # browser on your network. Otherwise the normal election rules apply  
  125. #  
  126. # OS Level determines the precedence of this server in master browser  
  127. # elections. The default value should be reasonable  
  128. #  
  129. # Preferred Master causes Samba to force a local browser election on startup  
  130. # and gives it a slightly higher chance of winning the election  
  131. ;       local master = no  
  132. ;       os level = 33  
  133. ;       preferred master = yes  
  134.   
  135. #----------------------------- Name Resolution -------------------------------  
  136. # Windows Internet Name Serving Support Section:  
  137. # Note: Samba can be either a WINS Server, or a WINS Client, but NOT both  
  138. #  
  139. # - WINS Support: Tells the NMBD component of Samba to enable it's WINS Server  
  140. #  
  141. # - WINS Server: Tells the NMBD components of Samba to be a WINS Client  
  142. #  
  143. # - WINS Proxy: Tells Samba to answer name resolution queries on  
  144. #   behalf of a non WINS capable client, for this to work there must be  
  145. #   at least one        WINS Server on the network. The default is NO.  
  146. #  
  147. # DNS Proxy - tells Samba whether or not to try to resolve NetBIOS names  
  148. # via DNS nslookups.  
  149.   
  150. ;       wins support = yes  
  151. ;       wins server = w.x.y.z  
  152. ;       wins proxy = yes  
  153.   
  154. ;       dns proxy = yes  
  155.   
  156. # --------------------------- Printing Options -----------------------------  
  157. #  
  158. # Load Printers let you load automatically the list of printers rather  
  159. # than setting them up individually  
  160. #  
  161. # Cups Options let you pass the cups libs custom options, setting it to raw  
  162. # for example will let you use drivers on your Windows clients  
  163. #  
  164. # Printcap Name let you specify an alternative printcap file  
  165. #  
  166. # You can choose a non default printing system using the Printing option  
  167.   
  168.         load printers = yes  
  169.         cups options = raw  
  170.   
  171. ;       printcap name = /etc/printcap  
  172.         #obtain list of printers automatically on SystemV  
  173. ;       printcap name = lpstat  
  174. ;       printing = cups  
  175.   
  176. # --------------------------- Filesystem Options ---------------------------  
  177. #  
  178. # The following options can be uncommented if the filesystem supports  
  179. # Extended Attributes and they are enabled (usually by the mount option  
  180. # user_xattr). Thess options will let the admin store the DOS attributes  
  181. # in an EA and make samba not mess with the permission bits.  
  182. #  
  183. # Note: these options can also be set just per share, setting them in global  
  184. # makes them the default for all shares  
  185.   
  186. ;       map archive = no  
  187. ;       map hidden = no  
  188. ;       map read only = no  
  189. ;       map system = no  
  190. ;       store dos attributes = yes  
  191.   
  192.   
  193. #============================ Share Definitions ==============================  
  194.   
  195. [homes]  
  196.         comment = Home Directories  
  197.         browseable = no  
  198.         writable = yes  
  199. ;       valid users = %S  
  200. ;       valid users = MYDOMAIN\%S  
  201.   
  202. [printers]  
  203.         comment = All Printers  
  204.         path = /var/spool/samba  
  205.         browseable = no  
  206.         guest ok = no  
  207.         writable = no  
  208.         printable = yes  
  209.   
  210. # Un-comment the following and create the netlogon directory for Domain Logons  
  211. ;       [netlogon]  
  212. ;       comment = Network Logon Service  
  213. ;       path = /var/lib/samba/netlogon  
  214. ;       guest ok = yes  
  215. ;       writable = no  
  216. ;       share modes = no  
  217.   
  218.   
  219. # Un-comment the following to provide a specific roving profile share  
  220. # the default is to use the user's home directory  
  221. ;       [Profiles]  
  222. ;       path = /var/lib/samba/profiles  
  223. ;       browseable = no  
  224. ;       guest ok = yes  
  225.   
  226.   
  227. # A publicly accessible directory, but read only, except for people in  
  228. # the "staff" group  
  229.         [public]  
  230.         comment = Public Stuff  
  231.         path = /share  
  232.         public = yes  
  233.         writable = yes  
  234.         printable = no  
  235.         write list = +staff  

             建立共享文件夹并分配nobody权限:

             [root@jhq0229 ~]# mkdir /share


             [root@jhq0229 ~]# chown -R nobody:nobody /share

            

             关闭防火墙:

              [root@jhq0229 ~]# chkconfig iptables off


             关闭selinux:

              [root@jhq0229 ~]# vim /etc/sysconfig/selinux

               修改为:      

  1. #SELINUX=enforcing  
  2. SELINUX=disabled  

              重启:

              [root@jhq0229 ~]# init 6

             

              重启完成后,就可以通过局域网内的电脑连接共享目录了,如Windows:

              连接分享目录:Win键+R,然后键入\\IP地址\,如:\\192.168.1.18\,结果如下图:


          这样你就可以操作共享目录了。如果你想不用每次都这样操作可以将其映射为网络地址,就可以很方便的操作了,和本地磁盘一样方便,如下图:


         

           好了,Samba的配置就到这里了,希望可以帮助到你。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值