本家様 https://wiki.samba.org/index.php/Main_Page
samba-4.0からWindowsServerのActiveDirectoryの機能が提供されている。
だが、別にそれを使わなくても従来からのファイル共有は行えて、ボリュームシャドーコピーといった便利な機能が使えます。
*samba4だからADの構築が必須ではないです。
windowsとLinux、MacOSXらのアカウント管理を費用を掛けずに一元管理したいならこのsamba-4.xのAD機能は有効かも。
でも人件費を考えれば、素直にMS様のwindows serverを用意された方が安く済むし「訊けます」
研究室なら安価なwindows serverがお勧め。もし予算が厳しいのでしたら、僭越ですがこのサイトをご活用頂ければ幸いです。
ここではCentOS 7 に samba-4.x.yをインストールして
- ActiveDirectoryドメインコントローラによるアカウント・マシン管理
- SMBによるwindowsファイル共有、ボリュームシャドーコピー
- 簡単なログオンスクリプト、グループポリシー付与
- MacOSXとのNFS接続
について記します。
方針 †
過去、いろいろな方針の元、構築してきましたが、今回は素直にsambaのDNS機能を使ってシングルドメインで構築します。
過去、samba-4.2(マルチドメイン bind使用[BIND9_DLZ])、samba-4.1(マルチドメイン bind使用[BIND9_FLATFILE])、samba-4.1((マルチドメイン 内蔵DNS使用)
ホスト名は c.sybyl.local(192.168.0.3)、ADドメイン名は sybyl.local、DNSフォワード先は192.168.0.1とする。

sambaサーバはCentOS 7で、sambaのソースコードからコンパイルしてインストールします。
*まだAD機能を有するパッケージ(samba-dc)がCentOS 7から提供されていないのです。リポジトリを追加すれば利用可能にもなりますけどね
通常の管理運営はwindowsPCにインストールしたリモートサーバ管理ツールで行う事を念頭にしますが、
Linuxでのコマンドラインでの方法も記載します。
下準備 †
CentOS 7 を最小構成で構築して、開発環境とドキュメントに書かれたパッケージ(samba42/install_packages)をインストール
/etc/hostsファイルは下記の様に調整します。
[root@c ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain
192.168.0.3 c.sybyl.local c
[root@c ~]#
/etc/resolv.conf はCentOS 7ではNetworkManagerが基本なので 直接編集せず、nmtui画面で調整します。
注意自分自身がDNSサーバになるので 192.168.0.3 も加える

その後OS再起動、もしくはNetworkManagerを再起動すれば反映される。
[root@c ~]# cat /etc/resolv.conf
# Generated by NetworkManager
search sybyl.local
nameserver 192.168.0.3
nameserver 192.168.0.1
[root@c ~]#
*nameserverは127.0.0.1でもいいみたい
Step 1: Download Samba †
ソースを取得します。
[root@c ~]# mkdir -p /opt/src && cd /opt/src
[root@c src]# wget https://download.samba.org/pub/samba/stable/samba-4.3.0.tar.gz
Step 2: Compile Samba †
[root@c src]# gzip -cd samba-4.3.0.tar.gz | tar xf - && cd samba-4.3.0
[root@c samba-4.3.0]# export PATH=/sbin:/bin:/usr/sbin:/usr/bin
[root@c samba-4.3.0]# ./configure --prefix=/opt/samba --enable-selftest --with-utmp --with-ads \
--with-systemd --enable-spotlight
[root@c samba-4.3.0]# time ( make -j3 ; make quicktest ) | tee -a make.log
(略)
ALL OK (2400 tests in 350 testsuites)
(略)
*CentOS7.2だと--enable-spotlightを外さないとコンパイルできなかった
Step 3: Install Samba †
[root@c samba-4.3.0]# make install
[root@c samba-4.3.0]# ( cd /lib64 ; ln -sv /opt/samba/lib/libnss_* .)
[root@c samba-4.3.0]# ( cd /lib64/security ; ln -sv /opt/samba/lib/security/* . )
あと、yum install/updateでsamba関係がインストールされないように /etc/yum.conf を調整する
パスの影響は無視して、ファイル名が被るものは
/lib64/security/pam_smbpass.so --> samba-common
/lib64/libnss_winbind.so.2 --> samba-winbind-clients
/lib64/libnss_wins.so.2 --> samba-winbind-clients
/lib64/security/pam_winbind.so --> samba-winbind-clients
なので、基本 samba-common と samba-winbind-clients をyum updateの際に適用されないようにする
[root@c ~]# vi /etc/yum.conf
[main]
:
exclude=samba-common samba-winbind-clients
[root@c ~]#
*ただし、他のパッケージのインストールの際、エラーになる可能性があります
Step 4: Provision Samba †
今回はBindとの連携は使用せず、sambaのDNSを使用します。なのでDNS backendにはSAMBA_INTERNALを使用します。
その場合、DNSのforwader先を問われます。/etc/resolv.confのnameserverの値が規定値として参照されます。
[root@c ~]# /opt/samba/bin/samba-tool domain provision --use-rfc2307 --interactive
Realm [SYBYL.LOCAL]:
Domain [SYBYL]:
Server Role (dc, member, standalone) [dc]:
DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]:
DNS forwarder IP address (write 'none' to disable forwarding) [192.168.0.3]: 192.168.0.1
Administrator password:
Retype password:
Looking up IPv4 addresses
(略
A Kerberos configuration suitable for Samba 4 has been generated at /opt/samba/private/krb5.conf
Setting up fake yp server settings
Once the above files are installed, your Samba4 server will be ready to use
Server Role: active directory domain controller
Hostname: c
NetBIOS Domain: SYBYL
DNS Domain: sybyl.local
DOMAIN SID: S-1-5-21-3856705137-1458541217-574567365
[root@c ~]#
*他の引数はsamba-tool domain provision --help を参照
再度provisionを行うなら、設定ファイルらを予め削除してから行う事
[root@c ~]# rm -rf /opt/samba/private/*
[root@c ~]# rm -rf /opt/samba/etc/smb.conf
*エラーメッセージで「ERROR(ldb): uncaught exception - operations error at ../source4/dsdb/samdb/ldb_modules/password_hash.c:3132」があるなら
「rm /etc/krb5.conf」とkrb5.confを削除します. あとでprovisionで作られたkrb5.confに差し替えます
Step 5: Starting Samba †
シングルモードでテスト実行を行う
[root@c ~]# /opt/samba/sbin/samba -i -M single
samba version 4.3.0 started.
Copyright Andrew Tridgell and the Samba Team 1992-2015
samba: using 'single' process model
Attempting to autogenerate TLS self-signed keys for https for hostname 'C.sybyl.local'
TLS self-signed keys generated OK
このまま動かしておいて、別のターミナルから
Step 6: Testing Samba †
別ターミナルを立ち上げて自分自身にアクセスしてみます。
[root@c ~]# /opt/samba/bin/smbclient --version
Version 4.3.0
[root@c ~]#
[root@c ~]# /opt/samba/bin/smbclient -L c.sybyl.local -U%
Domain=[SYBYL] OS=[Windows 6.1] Server=[Samba 4.3.0]
Sharename Type Comment
--------- ---- -------
netlogon Disk
sysvol Disk
IPC$ IPC IPC Service (Samba 4.3.0)
Domain=[SYBYL] OS=[Windows 6.1] Server=[Samba 4.3.0]
Server Comment
--------- -------
Workgroup Master
--------- -------
[root@c ~]#
さらにnetlogon共有ドライブへアクセスしてみます。
[root@c ~]# /opt/samba/bin/smbclient //c.sybyl.local/netlogon -Uadministrator
Enter administrator's password:
Domain=[SYBYL] OS=[Windows 6.1] Server=[Samba 4.3.0]
smb: \> ls
. D 0 Sat Sep 19 17:17:13 2015
.. D 0 Sat Sep 19 17:17:40 2015
26201600 blocks of size 1024. 11051908 blocks available
smb: \> quit
[root@c ~]#
Step 7: Testing internal DNS †
名前解決が正しく行われているかを確認する
[root@c ~]# host -t SRV _ldap._tcp.sybyl.local.
_ldap._tcp.sybyl.local has SRV record 0 100 389 c.sybyl.local.
[root@c ~]#
[root@c ~]# host -t SRV _kerberos._udp.sybyl.local.
_kerberos._udp.sybyl.local has SRV record 0 100 88 c.sybyl.local.
[root@c ~]#
[root@c ~]# host -t A c.sybyl.local.
c.sybyl.local has address 192.168.0.3
[root@c ~]#
[root@c ~]# host -t A www.sgi.com
www.sgi.com has address 192.48.178.134
[root@c ~]#
内部も、外部も名前解決はできている。
ただし、provisionの際にsamba4内蔵DNSで作られるゾーンは正引き(sybyl.local)のみで、その逆引きは登録されない。そのため
[root@c ~]# host 192.168.0.3
3.0.168.192.in-addr.arpa has no PTR record
[root@c ~]#
となる。逆引きを有効にするには samba-tool で逆引きゾーンの追加が必要になる。
注意samba4内部で解決できない名前解決要求を別のDNSへ回すforwarder設定は、step4のprovisionの際に定義している。
この定義値は、smb.confの[global]セクション内で記述されている。修正が必要ならこの値を変更する。
[root@c ~]# grep "dns forwarder" /opt/samba/etc/smb.conf
dns forwarder = 192.168.0.1
[root@c ~]#
Step 8: Configure Kerberos †
Step 5でテスト稼働させているsambaをCtrl-Cで停止してから
sambaのprovisionコマンドで作成された krb5.conf を /etc/krb5.conf と差し替えます。
[root@c ~]# mv /etc/krb5.conf /etc/krb5.conf.150919
[root@c ~]# cp -a /opt/samba/private/krb5.conf /etc/krb5.conf
[root@c ~]# cat /etc/krb5.conf
[libdefaults]
default_realm = SYBYL.LOCAL
dns_lookup_realm = false
dns_lookup_kdc = true
[root@c ~]#
その後、Step5のようにシングルモードでsambaを起動させ、
[root@c ~]# /opt/samba/sbin/samba -i -M single
samba version 4.3.0 started.
Copyright Andrew Tridgell and the Samba Team 1992-2015
samba: using 'single' process model
再度別ターミナルでkerberosチケット受領後のDNS動的更新を行ってみる
[root@c ~]# LANG=C kinit administrator@SYBYL.LOCAL
Password for administrator@SYBYL.LOCAL:
Warning: Your password will expire in 41 days on Sat Oct 31 20:34:02 2015
[root@c ~]#
[root@c ~]# klist -e
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@SYBYL.LOCAL
Valid starting Expires Service principal
2015-09-19T22:06:40 2015-09-20T08:06:40 krbtgt/SYBYL.LOCAL@SYBYL.LOCAL
renew until 2015-09-20T22:06:36, Etype (skey, tkt): aes256-cts-hmac-sha1-96, aes256-cts-hmac-sha1-96
[root@c ~]#
[root@c ~]# nsupdate -g
> update add c200.sybyl.local 100 in a 192.168.0.200
> send
; TSIG error with server: tsig verify failure
> quit
[root@c ~]#
[root@c ~]# host c200.sybyl.local
c200.sybyl.local has address 192.168.0.200
[root@c ~]#
[root@c ~]# nsupdate -g
> update delete c200.sybyl.local
> send
; TSIG error with server: tsig verify failure
update failed: NOTIMP
> quit
[root@c ~]# host c200.sybyl.local
c200.sybyl.local has address 192.168.0.200
[root@c ~]#
どうやら削除はできないみたい。samba-toolなら削除可能であった
[root@c ~]# /opt/samba/bin/samba-tool dns delete c sybyl.local c200.sybyl.local A 192.168.0.200
Record deleted successfully
[root@c ~]# host c200.sybyl.local
Host c200.sybyl.local not found: 3(NXDOMAIN)
[root@c ~]#
*読みずらいので英語環境(LANG=C)で実行してます。日本語環境(LANG=ja_JP.UTF-8)でも構いません
*「; TSIG error with server: tsig verify failure」はinternal DNSを使うと表示されるバグみたい。DNSを外部のBINDとかに任せると解消するそうな
Step 9: Configure NTP †
CentOS 7の時計合わせはchronyが基本みたい。
っが、正直使い方が分からない....なので、これを外してntpを使うことにした
[root@c ~]# systemctl stop chronyd
[root@c ~]# yum remove chrony
[root@c ~]# yum install ntp
[root@c ~]# systemctl enable ntpd ntpdate
として、設定は下記にのようにした
[root@c ~]# echo "ntp1.jst.mfeed.ad.jp" > /etc/ntp/step-tickers
[root@c ~]# cat << _EOF_ >/etc/ntp.conf
server ntp1.jst.mfeed.ad.jp
driftfile /var/lib/ntp/drift
logfile /var/log/ntpd.log
ntpsigndsocket /opt/samba/var/lib/ntp_signd/
restrict default mssntp
restrict 192.168.0.0 mask 255.255.255.0 nomodify notrap mssntp
restrict ntp1.jst.mfeed.ad.jp mask 255.255.255.255 nomodify notrap noquery
restrict 127.0.0.1
broadcastdelay 0.008
keys /etc/ntp/keys
_EOF_
[root@c ~]# systemctl start ntpdate
[root@c ~]# systemctl start ntpd
[root@c ~]# chown root:ntp /opt/samba/var/lib/ntp_signd/
[root@c ~]# chmod 750 /opt/samba/var/lib/ntp_signd/
Step 10: Configure smb.conf †
一応、Step 4: Provision Sambaの際にテンプレートが /opt/samba/etc/smb.conf に用意される。これてに修正を施す。
[root@c ~]# cat /opt/samba/etc/smb.conf
# Global parameters
[global]
workgroup = SYBYL
realm = SYBYL.LOCAL
netbios name = C
server role = active directory domain controller
dns forwarder = 192.168.0.1
idmap_ldb:use rfc2307 = yes
password server = c.sybyl.local # DCへのログインをwinbindd経由なら
printing = bsd
log level=1
log file = /var/log/samba.log
utmp = yes
ldap server require strong auth = no #TLS暗号通信をしたいのならyes
kerberos method = secrets and keytab #sssdでkeytabを使うなら
[netlogon]
path = /opt/samba/var/locks/sysvol/sybyl.local/scripts
read only = No
write ok = Yes
[sysvol]
path = /opt/samba/var/locks/sysvol
read only = No
write ok = Yes
[export]
path = /export
writable = yes
guest ok = yes
[home]
path = /home/
read only = no
[root@c ~]#
*ユーザホームは従来の[homes]の代わりに[home]を使ってます。またパスの指定も語尾に'/'を入れている
*sssdでkeytab経由でメンバーサーバを配下に入れるなら必要。これがないとkeytabが期限切れを起こす
あるいはmachine password timeout = 0でマシンアカウントのパスワード期限を無効にする
ドメインに参加したマシンもADではアカウントとして用意される。しかもパスワード付きで。そのパスワードが規定で7日
Step 11: Configure samba.service †
configureの際、--with-systemdとフラグを付けて*.serviceにて稼働させるようにした
[root@c samba-4.3.0]# find . -name *.service -exec ls -l {} \;
-rw-rw-r-- 1 root root 306 7月 21 18:47 ./ctdb/config/ctdb.service
-rw-rw-r-- 1 root root 286 7月 21 18:47 ./packaging/systemd/nmb.service
-rw-rw-r-- 1 root root 306 7月 21 18:47 ./packaging/systemd/samba.service
-rw-rw-r-- 1 root root 332 7月 21 18:47 ./packaging/systemd/smb.service
-rw-rw-r-- 1 root root 315 7月 21 18:47 ./packaging/systemd/winbind.service
[root@c samba-4.3.0]#
service稼働に読み込まれる設定ファイル(samba.sysconfig)を、/etc/sysconfig/sambaとして、samba.serviceは下記のようにした。
[root@c samba-4.3.0]# cd ./packaging/systemd/
[root@c systemd]# cp samba.sysconfig /etc/sysconfig/samba
[root@c systemd]# cp samba.service /etc/systemd/system
[root@c systemd]# vi /etc/systemd/system/samba.service
[Unit]
Description=Samba AD Daemon
After=syslog.target network.target
[Service]
Type=notify
NotifyAccess=all
PIDFile=/opt/samba/var/run/samba.pid
LimitNOFILE=16384
EnvironmentFile=-/etc/sysconfig/samba
ExecStart=/opt/samba/sbin/samba $SAMBAOPTIONS
ExecReload=/usr/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@c systemd]#
留意 PIDFile は、/opt/samba/var/run/samba.pid とした。
その後、新しいUnitなのでsystemdで読み込んで起動時に起動させるように手配後、起動する。
[root@c systemd]# systemctl daemon-reload
[root@c systemd]# systemctl list-unit-files --type=service | grep samba
samba.service disabled
[root@c systemd]# systemctl enable samba.service
[root@c systemd]# systemctl start samba.service
[root@c systemd]# journalctl -u samba --full -e
これでインストールと起動は完了。次はユーザ作成