Sambaを使うSamba は、Windows NT Server 互換のファイルおよびプリンタ共有サービスを提供するサーバーソフトである。それだけにとどまらず、安定したWINSやドメインコントローラー機能をも提供する。実際の検証結果によれば、およそ3000ユーザーを有する大規模ネットワークの運用でも性能の劣化は見られないほどである。このページでは、Sambaのインストール、基本的な共有フォルダの作成からドメインコントローラーの構築までを記録しておく。 Samba のインストール Samba のインストールもちろんaptでインストールする。 # apt-get install samba Reading Package Lists... Done Building Dependency Tree... Done The following extra packages will be installed: libcupsys2 samba-common The following NEW packages will be installed: libcupsys2 samba samba-common 0 packages upgraded, 3 newly installed, 0 to remove and 0 not upgraded. Need to get 3521kB of archives. After unpacking 10.9MB will be used. Do you want to continue? [Y/n] Enterを押すとインストールが始まり、しばらくすると初期設定画面が表示される。Y を選択し、設定を進める。もちろんNoを選択して、あとで手動設定しても構わない。逆に、慣れていれば一から設定ファイルを書いたほうが早いだろう。以下は Y を選択したときの画面。 Debian Configuration ----------------------------- Samba Server ----------------------------- | | | The rest of the configuration of Samba deals with questions that | | affect parameters in /etc/samba/smb.conf, which is the file used to | | configure the Samba programs (nmbd and smbd.) If you want to be | | asked just a few questions then select "Yes" and continue with the | | configuration. If you want to have full control, select "No" and | | configure your smb.conf manually or through SWAT. | | | | Configure smb.conf through debconf? | | | | <Yes> <No> | | | ------------------------------------------------------------------------ ワークグループもしくはドメイン名を入力。既存のWindowsネットワークの設定に合わせる。決まっていなかったら、workgroupとでも入れておく。 Debian Configuration ----------------------------- Samba Server ---------------------------- | This controls what workgroup your server will appear to be in when | | queried by clients. Note that this parameter also controls the | | Domain name used with the security=domain setting. | | | | Workgroup/Domain Name? | | | | workgroup__________________________________________________________ | | | | <Ok> | | | ----------------------------------------------------------------------- 次の画面では、暗号化パスワードを使うかどうか聞いてくる。普通使うので、Yesを押す。 Debian Configuration ----------------------------- Samba Server ----------------------------- | | | Recent Windows clients communicate with SMB servers using encrypted | | passwords. If you want to use clear text passwords you will need to | | change a parameter in your Windows registry. It is recommended that | | you use encrypted passwords. If you do, make sure you have a valid | | /etc/samba/smbpasswd file and that you set passwords in there for | | each user using the smbpasswd command. | | | | Use password encryption? | | | | <Yes> <No> | | | ------------------------------------------------------------------------ ログファイルの位置は /var/log/samba である。 Debian Configuration ----------------------------- Samba Server ---------------------------- | | | Samba's log files have moved. | | | | Starting with the first packages of Samba 2.2 for Debian the log | | files for both Samba daemons (nmbd and smbd) are now stored in | | /var/log/samba/. The names of the files are log.nmbd and log.smbd, | | for nmbd and smbd respectively. | | | | The old log files that were in /var/log/ will be moved to the new | | location for you. | | | | <Ok> | | | ----------------------------------------------------------------------- デーモンで稼動させるのが普通である。 Debian Configuration ----------------------------- Samba Server ------------------------------ | The Samba services (nmbd and smbd) can run as normal daemons or from | | inetd. Running as daemons is the recommended approach. | | | | How do you want to run Samba? | | | | daemons | | inetd | | | | | | <Ok> | | | ------------------------------------------------------------------------ パスワードファイルももちろん作成する。場所は /etc/samba/smbpasswd である。 Debian Configuration ----------------------------- Samba Server ------------------------------ | | | To be compatible with the defaults in most versions of Windows, | | Samba must be configured to use encrypted passwords. This requires | | user passwords to be stored in a file separate from /etc/passwd. | | This file can be created automatically, but the passwords must be | | added manually (by you or the user) by running smbpasswd, and you | | must arrange to keep it up-to-date in the future. If you do not | | create it, you will have to reconfigure samba (and probably your | | client machines) to use plaintext passwords. See | | /usr/share/doc/samba-doc/htmldocs/ENCRYPTION.html from the samba-doc | | package for more details. | | | | Create samba password file, /etc/samba/smbpasswd? | | | | <Yes> <No> | | | ------------------------------------------------------------------------ このあとsmbdとnmbd の各デーモンが自動的に立ち上がり、稼動し始める。 Selecting previously deselected package libcupsys2. (Reading database ... 27822 files and directories currently installed.) Unpacking libcupsys2 (from .../libcupsys2_1.1.14-4.4_i386.deb) ... Selecting previously deselected package samba-common. Unpacking samba-common (from .../samba-common_2.2.3a-12.3_i386.deb) ... Selecting previously deselected package samba. Unpacking samba (from .../samba_2.2.3a-12.3_i386.deb) ... Setting up libcupsys2 (1.1.14-4.4) ... Setting up samba-common (2.2.3a-12.3) ... Setting up samba (2.2.3a-12.3) ... Generating /etc/default/samba... Starting Samba daemons: nmbd smbd. Samba 日本語版のインストールもしSamba日本語版を使いたい場合は、/etc/apt/sources.list に次の行を書き足す。 deb http://people.hypercore.co.jp/~nsaito/ ./ ※ 最近では上記のaptラインだとエラーが出る。下記の一行を記述すると良い(2004/1) deb http://www.yaromai.net/~nsaito/ ./ それから、aptでインストール。パッケージ名はsamba-ja と指定する。 # apt-get install samba-ja ・ (中略) ・ 0 packages upgraded, 2 newly installed, 1 to remove and 3 not upgraded. Need to get 4263kB of archives. After unpacking 8012kB will be used. Do you want to continue? [Y/n] 上記でYと答えると、インストールが始まる。あとはオリジナル版と同じだ。 基本設定と共有フォルダの作成いよいよ設定にとりかかる。ユーザーを作成し、設定ファイル smb.conf に、最低限必要な設定を記述する。 最初に実ユーザーとゲストユーザーのSambaアカウントを作成する。ここでは user01 というユーザーを例にする。実際にはMicrosoftネットワークに実際ログオンしているユーザー名と同じユーザーを作ることになる。まずは guest というゲストユーザーを作ってみよう。 忘れてはならないのは、Sambaのユーザーを作成する前に、システムユーザーを作成する必要があることだ。次のような手順となる。 # adduser guest (中略) # smbpasswd -a guest New SMB password: Retype new SMB password: Added user guest. # smbpasswd -n guest User guest password set to none. -a オプションは新規ユーザーの作成時に使う。パスワードが求められてもEnterで抜ける。そのあと、-n オプションを使って、guestユーザーがパスワードなしでアクセスできるようにする。 次に同じようにuser01のアカウントを作成する。パスワードは、実際にMicrosoftネットワークにログオンするときのものを入力する。 # adduser user01 (中略) # smbpasswd -a user01 New SMB password: Retype new SMB password: Added user user01. 次に設定ファイル /etc/samba/smb.conf に必要な設定を記述する。
[global]
coding system = euc
client code page = 932
netbios name = server name
encrypt passwords = Yes
guest account = guest
map to guest = Bad User
null passwords = Yes
log file = /var/log/samba/log.%m
[tmp]
path = /tmp
guest ok = Yes
writeable = Yes
以上の設定が終わったら Samba を再起動し、設定を反映させる。 # /etc/init.d/samba restart ネットワークコンピュータを開いて、設定したサーバー名のアイコンが見えてくればOKだ。 もし「そんなコンピュータはありません」というようなメッセージが出て、すぐに見えてこないようであれば、数分後リトライしてみる。反映されるのに時間がかかっているのかもしれない。あと、ネットワークコンピュータのアイコンを右クリック - コンピュータの検索で、マシン名を指定して、検索してみてもよい。 Sambaサーバーが見えてきたら、ダブルクリックして開いてみる。そこに「tmp」フォルダがあれば、ブラウジングも共有も正常に動作していることになる。 以上がうまくいったら、先ほどの smb.conf ファイルに下記の記述を加えてみよう。 [homes] comment = %U's home directory path = /home/%U writeable = yes browsable = no 設定を保存してSambaを再起動したら、ネットワークコンピュータのSambaサーバーを開いてみる。今度はウィンドウズのログオンユーザーと同名のフォルダが見えてくる。これはhomes共有といって、そのユーザー専用のホームディレクトリを公開するための記述である。 次はとうとうドメインコントローラーの設定だ。 ドメインコントローラーの設定注意: 申し訳ないが、以下は数年前のテスト中の設定ファイルを掘り起こして記述したので、間違いがいくつかあるかもしれない。気づいたところがあったらお知らせ願いたい。 まずは下記のように、ドメインコントローラー用のグローバル設定をする。
[global]
coding system = euc
client code page = 932
workgroup = domain
netbios name = server01
server string =
security = user
encrypt passwords = yes
logon script = logon.bat
logon drive = U:
log file = /var/log/samba/log.%m
max log size = 50
domain logons = yes
domain master = yes
local master = yes
os level = 65
preferred master = yes
dns proxy = no
socket options = TCP_NODELAY
次に、samba で共有するディレクトリを作成する。今回は企業内で使用することを想定し、下記のような共有を作る。まずは /home/samba 以下に、mkdir コマンドでディレクトリを作成する。
上記の共有を設定するsmb.confは次のようになる。HOMES共有は、各ユーザーのHOMEディレクトリを使うわけだが、ドットファイルが見えてしまったりして、混乱やトラブルの元になるので、/home/%S/work などとするとよい。
[homes]
comment = Home Directories
path = /home/%S/work
read only = no
browseable = no
[netlogon]
path = /home/samba/netlogon
public = yes
writeable = no
browseable = yes
[共用]
comment = Public Space
path = /home/samba/public
public = yes
read only = no
writeable = yes
guest ok = yes
force user = guest
[専用]
comment = Only Group Members
path = /home/samba/dat
writeable = yes
[アプリ]
comment = Standard Apllication
path = /home/samba/apl
public = yes
writeable = yes
guest ok = yes
[公開情報]
comment = Open Information
path = /home/samba/open
public = yes
guest ok = yes
writeable = no
ここまできたら、smb.conf が正しく記述されているか testparm コマンドで確認する。エラーが出たら、出なくなるまで正しく編集する。 次に進もう。netlogon 共有を作ったので、そこにログオンスクリプトを置く。下記はドライブ割り当ての例である。これを「logon.bat」としてnetlogon共有に置く。注意すべきは、このバッチファイルはShift-JISで記述されなければいけない。Linux側のエディタで うっかりEUC で記述してしまうと、正しく動作しないことになる。 rem ドライブ割り当てのログオンスクリプト if "%OS%"=="Windows_NT" goto WindowsNT rem windows 9x系の場合 :Windows rem ============= 9x系OS ネットワークドライブ割り当て ============ echo. echo \\red-fish\共用 を G:ドライブに割り当てます net use g: \\red-fish\共用 > null echo. echo \\red-fish\専用を H:ドライブに割り当てます net use h: \\red-fish\専用 > null echo. echo \\red-fish\公開情報を I:ドライブ に割り当てます net use i: \\red-fish\公開情報 > null echo. echo \\red-fish\アプリを J: ドライブに割り当てます net use j: \\red-fish\アプリ > null echo. echo 処理は終了しました echo. goto END :WindowsNT rem ============= NT系OS ネットワークドライブ割り当て ============ echo. echo \\red-fish\共用 を G:ドライブに割り当てます net use /persistent:no g: \\server01\共用 > null echo. echo \\red-fish\専用を H:ドライブに割り当てます net use /persistent:no h: \\server01\専用 > null echo. echo \\red-fish\公開情報を I:ドライブ に割り当てます net use /persistent:no i: \\server01\公開情報 > null echo. echo \\red-fish\アプリを J: ドライブに割り当てます net use /persistent:no j: \\server01\アプリ > null echo. echo 処理は終了しました echo. :END exit このほか、時刻合わせ、ウィルス対策ソフトのパターンファイル更新、クライアントPCのインベントリ情報の取得など、アイデアしだいでさまざまな処理ができる。 次に、ドメイン管理者をsambaユーザーに加える。下記では root がドメイン管理者となり、マシンアカウントを追加する際の権限を持つユーザとなる # smbpasswd -a root ドメインに参加するマシンアカウントの追加。まずはシステムユーザーにマシンアカウントを追加する。マシン名の末尾に「$」をつける。マシンアカウント専用のグループを作成してひとまとめにすれば、なおスマートであろう。
# useradd -s /bin/false computer_name$
~~~
続いてsambaユーザーにマシンアカウントを追加する。-w オプションをつけているので、マシン名の末尾に$はつけない。 # smbpasswd -w -a computer_name さて、これでクライアントPCを招待する準備は整った。ここまで準備ができたら、samba を再起動する。 # /etc/init.d/samba restart 最後はクライアントPC側の設定となる。9x系OSなら、ネットワークコンピュータのプロパティで設定する。2000/XP系のOSでは、 マイコンピュータのプロパティ - ネットワークID - プロパティボタン - でドメインを設定することにより、ドメインに移す。再起動してログオンする。ログオンスクリプトが走ったら、めでたく成功である。
|