CentOS 6.8安裝Samba 4做Windows共用伺服器

來源:互聯網
上載者:User

標籤:samba iis

在某些情況下為了實現Windows多台伺服器負載平衡,需要使用共用來做圖片及附件的上傳空間。

這個時候就需要使用到Samba、IIS虛擬目錄等相關技術

Web伺服器使用upload作為上傳的目錄,現在需要使用2台伺服器做負載平衡,後台使用一台Samba伺服器作為檔案分享權限設定儲存

1.建立Samba檔案伺服器

卸載舊的samba組件,CentOS 6預設安裝的是3.6的版本

for a in `rpm -qa|grep samba`; do rpm -e --nodeps $a;done

2.安裝Samba 4

yum -y install samba4 samba-common samba4-client

3.建立共用使用者

說明:由於Windows在IIS中網站下是不能直接通過磁碟映射的方式作為網站路徑,必須使用原始的\\192.168.10.2\sns\upload這樣的目錄,而此時訪問共用的使用者就是應用程式集區的使用者。

這個時候就可以2種選擇:

a.samba使用匿名訪問可讀寫

b.修改網站應用程式集區使用者為訪問samba使用者

為了簡單我們這裡使用samba匿名訪問可讀寫的方式來進行配置

為共用建立系統使用者及組

groupadd -g 8800 smbgroup

useradd -g smbgroup -s /sbin/nologin -d /dev/null smbuser

建立共用目錄

mkdir /data/share

chown -R smbuser.smbgroup /data/share

chmod -R 755 smbuser.smbgroup /data/share


4.配置Samba

/etc/samba/smb.conf

[global]        workgroup = WORKGROUP        server string = FileServer        #hosts allow = 127. 192.168.10        log file = /var/log/samba/log.%m        max log size = 50                security = user        passdb backend = tdbsam        map to guest = bad user        guest account = smbuser                create mask = 0775        force create mode = 0775        directory mask = 0775        force directory mode = 0775                unix charset = cp936        dos  charset = cp936                use sendfile=yes        write raw = yes        read raw = yes        max xmit=65535        aio read size = 16384        aio write size = 16384[upload]        comment = sns        path = /var/www/html/upload        browseable = no        guest ok = yes        writable = yes        #valid users = @smbgroup

說明:在samba 4版本裡面security這個值已經廢棄了share,server。因此配置匿名訪問就需要

        security = user        map to guest = bad user


5.測試samba

[[email protected] samba]# testparmLoad smb config files from /etc/samba/smb.confProcessing section "[upload]"Loaded services file OK.Server role: ROLE_STANDALONEPress enter to see a dump of your service definitions# Global parameters[global]        dos charset = cp936        unix charset = cp936        server string = FileServer        security = USER        map to guest = Bad User        guest account = smbuser        log file = /var/log/samba/log.%m        max log size = 50        max xmit = 65535        idmap config * : backend = tdb        create mask = 0775        force create mode = 0775        directory mask = 0775        force directory mode = 0775        aio read size = 16384        aio write size = 16384        use sendfile = Yes[upload]        comment = sns        path = /var/www/html/upload        read only = No        guest ok = Yes        browseable = No


6.設定啟動服務及開機啟動

/etc/init.d/nmb start/etc/init.d/smb startchkconfig nmb onchkconfig smb on


第二部分:Windows IIS使用共用作為路徑

舉例:

我需要在網站的SignPDF路徑下建立PDF虛擬路徑

1.點擊“網站”--》對應的SignPDF目錄,右擊“SignPDF”,選擇“建立虛擬目錄”



650) this.width=650;" src="http://s1.51cto.com/wyfs02/M00/86/7A/wKioL1fAAubi488tAABKWHQp_Ww911.png" title="QQ20160826164735.png" alt="wKioL1fAAubi488tAABKWHQp_Ww911.png" />

2.輸入別名,我們這裡輸入“PDF”,然後選擇對應的實體路徑。

650) this.width=650;" src="http://s4.51cto.com/wyfs02/M02/86/7B/wKiom1fAA2qy5LSdAAAV2EfHiEI649.png" title="2.png" alt="wKiom1fAA2qy5LSdAAAV2EfHiEI649.png" />

注意:

  1. 這裡的實體路徑,如果使用共用的話,不能使用磁碟映射的路徑,比如我將共用映射為Z盤,這裡選擇Z盤是無效的,必須使用共用的全路徑

  2. 如果Samba不是使用匿名訪問的話,這裡就需要選擇“串連為”,設定對應的使用者及密碼,這裡的使用者需要自行到Windows系統中進行添加,並且使用者名稱密碼可訪問共用。


問題:

1.在配置Samba後發現在A節點建立的目錄,B節點無法寫入,這是因為2個使用者是一致的但是使用者的組不一致。比如A伺服器主機名稱為ServerA,B伺服器的主機名稱為ServerB,因此在Samba中的A節點對應的許可權就是ServerA\smbuser,B伺服器對應的許可權就是ServerB\smbuser,這就是造成2台伺服器許可權不一致的問題。

在smb.conf中添加

        create mask = 0775        force create mode = 0775        directory mask = 0775        force directory mode = 0775

再重啟服務即可

本文出自 “楓林晚” 部落格,請務必保留此出處http://fengwan.blog.51cto.com/508652/1843034

CentOS 6.8安裝Samba 4做Windows共用伺服器

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.