1. 程式人生 > >原創:實現Solaris 與Windows 間的文件共享

原創:實現Solaris 與Windows 間的文件共享

when reading work existing pan after 重啟 所有者 相同

背景:

現行作業方式無法實現賬號權限的管控,並且每次訪問都需要創建新的連接。

Solaris訪問windows共享目錄通過以下命令

/usr/sfw/bin/smbclient //XXXXXXX(服務器名/地址)/TK_XXXXXXX_test(目錄名稱) -U tk_test(用戶)

Password: (此處輸入用戶密碼即可)

Windows訪問solaris共享目錄現在沒有設定權限。

只要輸入IP即可訪問solaris共享目錄。

部署完後實現Solaris 與Windows 間的文件共享映射。

Program Server :solaris和windows之間的文件共享已經進行調整

Solaris訪問windows共享目錄

已經將windows系統XXXXXXX/TK_XXXXXXX_test(此目錄可修改配置)目錄掛載到solaris系統mnt目錄(此目錄可修改配置)

Windows訪問solaris共享目錄

使用帳號user1

密碼12345678

一、 安裝軟體

a) samba-3.6.4-sol10-sparc-local.gz

b) sharity.3.9.solaris-sun4.tar.gz

二、 Samba概述

Samba提供了Unix系統和Windows之間的文件和打印機共享服務。一臺Solaris的機器,如果配置了Samba Server,就能充當共享服務器;同時也能作為客戶機訪問網絡中其它Windows系統上的共享文件,或其它安裝了Samba Server的Solaris/Linux系統上的共享文件。

三、 安裝Samba

a) 下載 samba for Solaris 的安裝軟件包:samba-3.6.4-sol10-sparc-local.gz

註:Solaris系統分為Sparc和x86兩個版本。Samba版本需要和Solaris版本一致

b) 解壓並安裝samba軟件包:

#gunzip samba-3.6.4-sol10-sparc-local.gz

註:檢查是否已經安裝samba使用pkginfo命令

#pkgadd –d samba-3.6.4-sol10-sparc-local

註:pkgadd –d如果不加-d則需要將安裝包放置於/var/spool/pkg目錄

安裝完畢後,到默認安裝目錄/usr/local下可以看到安裝的軟件包samba目錄。

c) 啟動Solaris 10系統的Samba 服務

在安裝完軟件包後,我們把/usr/local/samba/sbin 下面的3個應用程序,nmbd,smbd,winbindd復制到/usr/local/samba/bin下面去。

samba server服務是 由3個守護進程組成,

nmbd—Netbios名稱服務器,該進程使用UDP協議提供Netbios名稱服務和瀏覽支持,處理命名註冊和決策請求。該進程應當是被首先啟動。

smbd —SMB服務器,使用TCP協議給SMB客戶提供文件和打印服務;應當在nmbd進程後立即啟動。

Winbindd—當Samba服務器是windows NT 或 ADS域中的成員時,此時當啟動該守護進程。

通常在修改了配置文件smb.conf後,我們需要從新啟動這3個進程,以便參數的設置起效.

d) 開啟samba服務

#svcadm enable samba

(關閉samba服務 #svcadm disable samba; 重啟samba服務 #svcadm restart samba)

e) 查看samba服務

# svcs -v | grep samba

f) 查看MDB進程

#ps -ef | grep mbd

四、 配置Samba

Samba的共享方式包括share、user、server、domain 和ads。(廠內目前使用user的共享方式)

a) 配置share共享方式

采用share方式,用戶不需要輸入帳號和密碼就可以登陸samba服務器。其配置步驟為:

i. 創建一個Samba共享目錄

# mkdir -p /export/home/user1

ii. 創建Samba配置文件

# cp /etc/sfw/smb.conf-example /etc/sfw/smb.conf

# vi /etc/sfw/smb.conf

===== ===== /usr/sfw/smb.conf ==========

security = share

[homes]

comment = Home Directories

browseable = yes

writable = yes

path = /export/home/user1

guest ok = yes

guest account = user1

這裏用戶是通過默認的user1來登陸的。用戶登陸之後,可以看到user1 所共享的文件和所有系統共享文件,其他用戶共享的文件能夠看得到,但是不一定能夠使用或者進的去。如果不設置guest account的話,則用戶就以默認的nobody進行登陸,只能夠使用系統設置的共享文件。其他用戶設置的文件不一定能夠使用。

iii. 啟動Samba服務

# svcadm enable samba

# svcs | grep samba

online1:19:02svc:/network/samba:default

# ps -eaf | grep mbd

root 24453 1 0 01:19:02 ? 0:00 /usr/sfw/bin/smbd -D

root 24450 1 0 01:19:02 ? 0:00 /usr/sfw/bin/nmbd -D

root 24454 24453 0 01:19:02 ? 0:00 /usr/sfw/bin/smbd -D

b) 配置user共享方式(新建user1用戶。此處用戶名可自定義)

配置成user方式需要提供用戶名和密碼進行驗證。這裏Samba用戶必須是 Solaris系統用戶。而對同一個用戶來說,samba密碼和系統密碼不必一定相同。

i. 添加一個系統用戶(用已經存在的也可以)

# useradd -d /export/home/user1 -m -s /usr/bin/bash user1

ii. 用smbpasswd添加Samba用戶

# /usr/sfw/bin/smbpasswd -a user1

New SMB password: <password>

Retype new SMB password: <password>

Added user user1.

/usr/sfw/bin/smbpasswd -e user1

Enabled user user1

iii. 編輯配置文件smb.conf

===== ===== /usr/sfw/smb.conf ==========

security = user #使用user認證方式

[homes]

comment = Home Directories for %S

valid users = %S #只有所有者能訪問該共享

browseable = no #該共享對其它用戶不可見

writable = yes

create mask = 0640 #創建文件時的權限掩碼

directory mask = 0750 #創建目錄時的權限掩碼

這裏%S通配符可以擴展成實際的共享名。這樣user1共享的註釋將是 “Home Directories for user1”。

iv. 重新啟動Samba服務

# svcadm restart samba

c) Solaris訪問 Windows的共享資源

Samba包中已經包括了smbclient、smbmount等的實用程序。smbclient程序提供了一個類似FTP 的模式界面,允許用戶共享Windows、Linux的資源,還可以用戶列出服務器上的可用共享資源。smbmount類似mount命令,將 Windows的共享目錄安裝到Linux的本地目錄。

  1. 查詢網絡上的Samba服務器

# /usr/sfw/bin/findsmb

每個找到的服務器都會顯示其 IP 地址、NetBIOS 名稱、工作組名稱、操作系統、以及 SMB 服務器版本。

  1. 列出Samba服務器上的可用資源

# /usr/sfw/bin/smbclient -L <hostname>

如果是 user共享方式,就要加“-U <user>”選項如下。

# /usr/sfw/bin/smbclient -L <hostname> -U <user>

Password: <password>

如果是 share共享方式,可以不必理會用戶和密碼,要求輸入密碼時直接回車即可。

  1. 連接Samba共享

# /usr/sfw/bin/smbclient //<hostname/<share> [-U <username>]

例如要訪問上文中的share共享時,可用

# /usr/sfw/bin/smbclient //hostname/homes

Password: <ENTER>

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.21b]

smb:>

要訪問上文中的user共享時,可用

# /usr/sfw/bin/smbclient //hostname/user1 -U user1

Password: <user1_password>

Domain=[MYGROUP] OS=[Unix] Server=[Samba 3.0.21b]

smb:>

連接後,就能象FTP用戶一樣上傳和下載文件。用put表示上傳,用get表示下載。鍵入help獲得可用的命令列表。

  1. 掛載Samba共享

Solaris 尚不支持smbfs和smbmount命令。解決方法之一就是使用Sharity。其安裝和使用都很簡單。

此時Samba即安裝完成。也初步實現Solaris和Windows之間的文件共享功能。但此存在以下問題:

1、每次Solaris訪問Windows共享文件夾時,需使用以下命令進行文件共享連接

/usr/sfw/bin/smbclient //XXXXXXX(服務器名/地址)/TK_XXXXXXX_test(目錄名稱) -U tk_test(用戶)

Password: (此處輸入用戶密碼即可)

2、需使用FTP命令進行數據交換,這樣對用戶的要求比較高,難以掌握。

3、無法實現機臺自動獲取信息。機臺無法在每次獲取數據時自動輸入命令。

五、 安裝配置sharity

a) 解壓sharity文件

# gunzip -c sharity.3.9.solaris-sun4.tar.gz | tar xf -

b) 進入sharity解壓目錄

cd sharity.3.9.solaris-sun4(此處最好書寫解壓目錄全路徑)

c) 安裝sharity

# ./setup

d) 安裝流程:

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

Type 1 and press Enter for an installation in English language.

Tippen Sie 2 und dann Enter um in deutscher Sprache zu installieren.

-----------------------------------------------------------------------
Default answer: 1

-----------------------------------------------------------------------
WELCOME TO SHARITY 3 INSTALLATION

This is the install script for Sharity 3. The script will first ask a
couple of questions, then give a summary of your choices and give you a
chance to start over again.

The installation will not begin before the questionnaire is complete. You can
type ^C at any time during the questionnaire to abort the installation.

Please press Enter to start.
-----------------------------------------------------------------------

-----------------------------------------------------------------------
INSTALLATION DIRECTORY

Where do you want to install Sharity? We recommend locations like
/usr/local/sharity3 or /opt/sharity3.
-----------------------------------------------------------------------
Default answer: /usr/local/sharity3

-----------------------------------------------------------------------
SYMLINKS FOR BINARIES?

Sharity comes with binaries which should be in your search path. This can be
accomplished either by adding /usr/local/sharity3/bin
to your search path or by making symlinks from an existing bin directory
to Sharity‘s binaries.

If you want to create the symlinks, please specify your preferred binary
directory where the symlinks should be created (e.g. /usr/local/bin):
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
NETWORK BROWSING DIRECTORY

Sharity provides a network browser similar to the Windows Network
Neighborhood. Where do you want to mount this browser? If you don‘t want
the browser, answer none (without the quotes).
-----------------------------------------------------------------------
Default answer: /CIFS

-----------------------------------------------------------------------
WORKGROUP OR DOMAIN

Sharity works best if it knows your Windows workgroup or domain. If you know
your workgroup or domain name (fully qualified DNS domain name, if possible),
please enter it below. Otherwise leave it blank. You can always change this
setting later in the Sharity GUI or in the file
/usr/local/sharity3/var/user.cfg.
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
WINS SERVER

If your network uses a WINS server (Netbios name server), Sharity should know
about it. If you don‘t know what a WINS server is, please leave it blank. You
can always set it through the Sharity GUI or in the file
/usr/local/sharity3/var/user.cfg.

If you know your WINS server IP-address, please enter it here. Remember:
we need an IP address (or a DNS name), not a Netbios name of the computer.
-----------------------------------------------------------------------
Default answer: <none>

-----------------------------------------------------------------------
SUMMARY

Summary of your choices:
Installation root directory: "/usr/local/sharity3"
Upgrade or new install: install
Link binaries to directory: ""
Network browser directory: "/CIFS"
Workgroup or Domain: ""
WINS server: ""

Are these values OK? [Y/n]
-----------------------------------------------------------------------
Default answer: yes

Copying files...
Editing and creating customized files...
Fixing permissions and ownership...
Starting Sharity service...
Starting Sharity daemon:
odcfgparse/info: Reading file "/usr/local/sharity3/etc/config/cifs.cfg"
odcfgparse/info: Reading file "/usr/local/sharity3/etc/config/main.cfg"
odcfgparse/info: Reading file "var/local.cfg"
odcfgparse/info: Reading file "var/user.cfg"
Warning: The master pass phrase for your key chain has been chosen
randomly by the system. Please use "sharity keychain setpass" to
set your own master pass phrase. The master pass phrase is needed
after an upgrade or restore from backup!
done.

-----------------------------------------------------------------------
You must choose a master pass phrase to protect your keychain. The keychain
contains passwords and other secret data. You need this pass phrase after
an upgrade or a restore from backup. Please choose something which can not
be guessed easily (no dictionary words) and which you can remember, although
you don‘t need it regularly. If you can‘t decide now, type ^C and use

/usr/local/sharity3/bin/sharity keychain setpass

or the GUI application

/usr/local/sharity3/bin/sharitygui

later to set your pass phrase.
-----------------------------------------------------------------------
New master pass phrase:
Type again to verify:
Pass phrase successfully changed.

-----------------------------------------------------------------------
COMPLETED

The installation has finished. You should start the GUI application now.
It can be found at the path

/usr/local/sharity3/bin/sharitygui

The GUI application asks for passwords when required and can be used to
configure Sharity. You must run it under the same account which uses the
Sharity mounts in order to get login dialogs for the correct account.

If you don‘t have a license key yet, please visit
http://www.obdev.at/products/sharity/.
-----------------------------------------------------------------------

e) 啟動和停止Sharity

重啟機器後,Sharity會自動運行

# svcs | grep sharity

legacy_run 0:38:06 lrc:/etc/rc2_d/S80sharity3

legacy_run 0:38:14 lrc:/etc/rc3_d/S80sharity3

停止 Sharity

# /usr/local/sharity3/sbin/sharity.init stop

啟動 Sharity

# /usr/local/sharity3/sbin/sharity.init start

f) 配置sharity

  1. 進入sharity目錄

# cd /usr/local/sharity3/bin (默認路徑)

  1. 檢查sharity安裝

# ./sharity -h

  1. 掛載:登錄到windows

# ./sharity login smb://XXXXXXX/TK_XXXXXXX_test –U tk_test –P 12345678

註:此處服務器地址為windows文件共享服務器地址;目錄為共享文件目錄;用戶問windows文件共享服務器用戶;密碼為對應用戶密碼

  1. 掛載:至solaris mnt目錄

# ./sharity mount smb://XXXXXXX/TK_XXXXXXX_test /mnt

  1. 查看掛載情況

# df

  1. 卸載掛載

# ./sharity umount -a

  1. 查看掛載情況

# df

  1. 退出windows會話

# ./sharity logout –a

原創:實現Solaris 與Windows 間的文件共享