W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
上一章講解的FTP文件傳輸服務(wù)確實(shí)可以讓主機(jī)之間的文件傳輸變得簡單方便,但是FTP協(xié)議的本質(zhì)是傳輸文件,而非共享文件,因此要想通過客戶端直接在服務(wù)器上修改文件內(nèi)容還是一件比較麻煩的事情。
1987年,微軟公司和英特爾公司共同制定了SMB(Server Messages Block,服務(wù)器消息塊)協(xié)議,旨在解決局域網(wǎng)內(nèi)的文件或打印機(jī)等資源的共享問題,這也使得在多個(gè)主機(jī)之間共享文件變得越來越簡單。到了1991年,當(dāng)時(shí)還在讀大學(xué)的Tridgwell為了解決Linux系統(tǒng)與Windows系統(tǒng)之間的文件共享問題,基于SMB協(xié)議開發(fā)出了SMBServer服務(wù)程序。這是一款開源的文件共享軟件,經(jīng)過簡單配置就能夠?qū)崿F(xiàn)Linux系統(tǒng)與Windows系統(tǒng)之間的文件共享工作。當(dāng)時(shí),Tridgwell想把這款軟件的名字SMBServer注冊成為商標(biāo),但卻被商標(biāo)局以SMB是沒有意義的字符而拒絕了申請。后來Tridgwell不斷翻看詞典,突然看到一個(gè)拉丁舞蹈的名字—Samba,而且這個(gè)熱情洋溢的舞蹈名字中又恰好包含了“SMB”,于是Samba服務(wù)程序的名字由此誕生(見圖12-1)。Samba服務(wù)程序現(xiàn)在已經(jīng)成為在Linux系統(tǒng)與Windows系統(tǒng)之間共享文件的最佳選擇。
圖12-1 Samba服務(wù)程序的logo
Samba服務(wù)程序的配置方法與之前講解的很多服務(wù)的配置方法類似,首先需要先通過Yum軟件倉庫來安裝Samba服務(wù)程序(Samba服務(wù)程序的名字也恰巧是軟件包的名字):
[root@linuxprobe ~ ]# yum install samba
Loaded plugins: langpacks, product-id, subscription-manager
………………省略部分輸出信息………………
Installing:
samba x86_64 4.1.1-31.el7 rhel 527 k
Transaction Summary
================================================================================
Install 1 Package
Total download size: 527 k
Installed size: 1.5 M
Is this ok [y/d/N]: y
Downloading packages:
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Installing : samba-4.1.1-31.el7.x86_64 1/1
Verifying : samba-4.1.1-31.el7.x86_64 1/1
Installed:
samba.x86_64 0:4.1.1-31.el7
Complete!
安裝完畢后打開Samba服務(wù)程序的主配置文件,發(fā)現(xiàn)竟然有320行之多!有沒有被嚇到?但仔細(xì)一看就會(huì)發(fā)現(xiàn),其實(shí)大多數(shù)都是以井號(#)開頭的注釋信息行。有劉遄老師在,肯定是不會(huì)讓大家去“死啃”這些內(nèi)容的。
[root@linuxprobe ~]# cat /etc/samba/smb.conf
# This is the main Samba configuration file. For detailed information about the
# options listed here, refer to the smb.conf(5) manual page. Samba has a huge
# number of configurable options, most of which are not shown in this example.
#
# The Official Samba 3.2.x HOWTO and Reference Guide contains step-by-step
# guides for installing, configuring, and using Samba:
# http://www.samba.org/samba/docs/Samba-HOWTO-Collection.pdf
#
# The Samba-3 by Example guide has working examples for smb.conf. This guide is
# generated daily: http://www.samba.org/samba/docs/Samba-Guide.pdf
#
# In this file, lines starting with a semicolon (;) or a hash (#) are
# comments and are ignored. This file uses hashes to denote commentary and
# semicolons for parts of the file you may wish to configure.
#
# Note: Run the "testparm" command after modifying this file to check for basic
# syntax errors.
#
………………省略部分輸出信息………………
由于在Samba服務(wù)程序的主配置文件中,注釋信息行實(shí)在太多,不便于分析里面的重要參數(shù),因此先把主配置文件改個(gè)名字,然后使用cat命令讀入主配置文件,再在grep命令后面添加-v參數(shù)(反向選擇),分別去掉所有以井號(#)和分號(;)開頭的注釋信息行,對于剩余的空白行可以使用^$參數(shù)來表示并進(jìn)行反選過濾,最后把過濾后的可用參數(shù)信息通過重定向符覆蓋寫入到原始文件名稱中。執(zhí)行過濾后剩下的Samba服務(wù)程序的參數(shù)并不復(fù)雜,為了更方便讀者查閱參數(shù)的功能,表12-1羅列了這些參數(shù)以及相應(yīng)的注釋說明。
表12-1 Samba服務(wù)程序中的參數(shù)以及作用
行數(shù) | 參數(shù) | 作用 |
---|---|---|
1 | # See smb.conf.example for a more detailed config file or | 注釋信息 |
2 | # read the smb.conf manpage. | |
3 | # Run 'testparm' to verify the config is correct after | |
4 | # you modified it. | |
5 | [global] | 全局參數(shù) |
6 | workgroup = SAMBA | 工作組名稱 |
7 | ||
8 | security = user | 安全驗(yàn)證的方式,總共有4種 |
9 | ||
10 | passdb backend = tdbsam | 定義用戶后臺的類型,總共有3種 |
11 | ||
12 | printing = cups | 打印服務(wù)協(xié)議 |
13 | printcap name = cups | 打印服務(wù)名稱 |
14 | load printers = yes | 是否加載打印機(jī) |
15 | cups options = raw | 打印機(jī)的選項(xiàng) |
16 | ||
17 | [homes] | 共享名稱 |
18 | comment = Home Directories | 描述信息 |
19 | valid users = %S, %D%w%S | 可用賬戶 |
20 | browseable = No | 指定共享信息是否在“網(wǎng)上鄰居”中可見 |
21 | read only = No | 是否只讀 |
22 | inherit acls = Yes | 是否繼承訪問控制列表 |
23 | ||
24 | [printers] | 共享名稱 |
25 | comment = All Printers | 描述信息 |
26 | path = /var/tmp | 共享路徑 |
27 | printable = Yes | 是否可打印 |
28 | create mask = 0600 | 文件權(quán)限 |
29 | browseable = No | 指定共享信息是否在“網(wǎng)上鄰居”中可見 |
30 | ||
31 | [print$] | 共享名稱 |
32 | comment = Printer Drivers | 描述信息 |
33 | path = /var/lib/samba/drivers | 共享路徑 |
34 | write list = @printadmin root | 可寫入文件的用戶列表 |
35 | force group = @printadmin | 用戶組列表 |
36 | create mask = 0664 | 文件權(quán)限 |
37 | directory mask = 0775 | 目錄權(quán)限 |
[root@linuxprobe ~]# mv /etc/samba/smb.conf /etc/samba/smb.conf.bak
[root@linuxprobe ~]# cat /etc/samba/smb.conf.bak | grep -v "#" | grep -v ";" | grep -v "^$" > /etc/samba/smb.conf
[root@linuxprobe ~]# cat /etc/samba/smb.conf
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: