本家様 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 8 に samba-4.x.yをインストールして
- ActiveDirectoryドメインコントローラによるアカウント・マシン管理
- SMBによるwindowsファイル共有、ボリュームシャドーコピー
- 簡単なログオンスクリプト、グループポリシー付与
- MacOSXとのNFS接続
について記します。
samba/CAL?
方針 †
過去、いろいろな方針の元、構築してきましたが、今回は素直に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 8で、sambaのソースコードからコンパイルしてインストールします。
*まだAD機能を有するパッケージ(samba-dc)がCentOS 8から提供されていないのです。リポジトリを追加すれば利用可能にもなりますけどね
通常の管理運営はwindowsPCにインストールしたリモートサーバ管理ツールで行う事を念頭にしますが、
Linuxでのコマンドラインでの方法も記載します。
下準備 †
CentOS 8 を最小構成で構築して、開発環境とドキュメントに書かれたパッケージ(samba/packages)をインストール
/etc/hostsファイルは下記の様に調整します。
[root@c ~]# vi /etc/hosts
127.0.0.1 localhost localhost.localdomain localhost.sybyl.local
192.168.0.3 c.sybyl.local c
[root@c ~]#
/etc/resolv.conf はCentOS 8では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.11.0.tar.gz
Step 2: Compile Samba †
[root@c src]# gzip -cd samba-4.11.0.tar.gz | tar xf - && cd samba-4.11.0
[root@c samba-4.11.0]# ./configure --prefix=/opt/samba --with-utmp --with-ads --with-systemd
[root@c samba-4.11.0]# make
Step 3: Install Samba †
[root@c samba-4.11.0]# make install
[root@c samba-4.11.0]# ( cd /lib64 ; ln -sv /opt/samba/lib/libnss_* .)
[root@c samba-4.11.0]# ( cd /lib64/security ; ln -sv /opt/samba/lib/security/* . )
あと、yum install/updateでsamba関係がインストールされないように /etc/yum.conf を調整する
パスの影響は無視して、ファイル名が被るものは
/lib64/libnss_winbind.so --> samba-winbind-modules
/lib64/libnss_winbind.so.2 --> samba-winbind-modules
/lib64/libnss_wins.so --> samba-winbind-modules
/lib64/libnss_wins.so.2 --> samba-winbind-modules
/lib64/security/pam_winbind.so --> samba-winbind-modules
なので、基本 samba-winbind-modules をyum updateの際に適用されないようにする
[root@c ~]# vi /etc/yum.conf
[main]
:
exclude=samba-winbind-modules
[root@c ~]#
*ただし、他のパッケージのインストールでこの「samba-winbind-modules」が要求されると、エラーになる可能性があります
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) [127.0.0.1]: 192.168.0.1
Administrator password:
Retype password:
(略
(途中、python3のログに続いてメッセージが表示される。python3のログが邪魔すぎる)
Fixing provision GUIDs
A Kerberos configuration suitable for Samba AD has been generated at /opt/samba/private/krb5.conf
Merge the contents of this file with your system krb5.conf or replace it with this one. Do not create a symlink!
Setting up fake yp server settings
Once the above files are installed, your Samba AD 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-2087677174-1672655504-2050380489
[root@c ~]#
*他の引数はsamba-tool domain provision --help を参照
再度provisionを行うなら、設定ファイルらを予め削除してから行う事
[root@c ~]# rm -rf /opt/samba/private/*
[root@c ~]# rm -rf /opt/samba/etc/smb.conf
次に、上記provisionの際に指摘されたように「krb5.conf」ファイルを差し替えます。
[root@c ~]# mv /etc/krb5.conf /etc/krb5.conf.orig
[root@c ~]# cp /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 ~]#
Step 5: Starting Samba †
シングルモードでテスト実行を行う
ほかのモードについてはここを参照 https://wiki.samba.org/index.php/Samba_server_process_model
[root@c ~]# /opt/samba/sbin/samba -i -M single
samba version 4.11.0 started.
Copyright Andrew Tridgell and the Samba Team 1992-2019
binary_smbd_main: 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
*もしここで「stream_setup_socket: Failed to listen on 0.0.0.0:53 - NT_STATUS_ADDRESS_ALREADY_ASSOCIATED」と出たらそれはlibvrtd関連のdnsmasqが動いているから。libvirtdを止めて再起動すれば回避可能. あと「lsof -i:53」とかでも確認する
「systemctl stop systemd-resolved」とかも
あと
/opt/samba/sbin/samba_dnsupdate: Traceback (most recent call last):
/opt/samba/sbin/samba_dnsupdate: File "/opt/samba/sbin/samba_dnsupdate", line 57, in <module>
/opt/samba/sbin/samba_dnsupdate: import dns.resolver
/opt/samba/sbin/samba_dnsupdate: ModuleNotFoundError: No module named 'dns'
dnsupdate_nameupdate_done: Failed DNS update with exit code 1
と表記されたら「python3-dns.noarch」をインストールする
*CentOS7ならpython36-dns
このまま動かしておいて、別のターミナルから
Step 6: Testing Samba †
別ターミナルを立ち上げて自分自身にアクセスしてみます。
[root@c ~]# /opt/samba/bin/smbclient --version
Version 4.11.0
[root@c ~]#
[root@c ~]# /opt/samba/bin/smbclient -L c.sybyl.local -U%
Sharename Type Comment
--------- ---- -------
sysvol Disk
netlogon Disk
IPC$ IPC IPC Service (Samba 4.11.0)
SMB1 disabled -- no workgroup available
[root@c ~]#
さらにnetlogon共有ドライブへアクセスしてみます。
[root@c ~]# /opt/samba/bin/smbclient //c.sybyl.local/netlogon -Uadministrator
Enter SYBYL\administrator's password:
Try "help" to get a list of possible commands.
smb: \> ls
. D 0 Mon Oct 14 08:20:01 2019
.. D 0 Mon Oct 14 08:20:27 2019
67076096 blocks of size 1024. 65360204 blocks available
smb: \> pwd
Current directory is \\c.sybyl.local\netlogon\
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 †
別ターミナルでkerberosチケット受領後のDNS動的更新を行ってみる
[root@c ~]# LANG=C kinit administrator@SYBYL.LOCAL
Password for administrator@SYBYL.LOCAL:
Warning: Your password will expire in 41 days on Mon Nov 25 08:33:46 2019
[root@c ~]#
[root@c ~]# klist -e
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@SYBYL.LOCAL
Valid starting Expires Service principal
10/14/2019 08:51:42 10/14/2019 18:51:42 krbtgt/SYBYL.LOCAL@SYBYL.LOCAL
renew until 10/15/2019 08:51:37, 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-4.11.0でも削除はできないみたい....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 8の時計合わせはchronyがデフォルトのご様子。
ここではそのままchronyを使います。OSインストールの際にntpサーバを指定していれば、
[root@c ~]# chronyc sources
210 Number of sources = 1
MS Name/IP address Stratum Poll Reach LastRx Last sample
===============================================================================
^* ntp-b2.nict.go.jp 1 10 377 390 -192us[ -792us] +/- 8694us
[root@c ~]#
とか表示されいると思います。設定ファイル「/etc/chrony.conf」は
[root@c ~]# sed '/^#/d' /etc/chrony.conf | sed '/^$/d'
server ntp.nict.jp iburst
driftfile /var/lib/chrony/drift
makestep 1.0 3
rtcsync
keyfile /etc/chrony.keys
leapsectz right/UTC
logdir /var/log/chrony
[root@c ~]#
となっているかと。
sambaとの時計連携はhttps://wiki.samba.org/index.php/Time_Synchronisation#With_chrony
に記載があるように
「bindcmdaddress」「ntpsigndsocket」「allow」を加えて
[root@c ~]# cat << _EOF_ >>/etc/chrony.conf
allow 192.168.0.0/24
bindcmdaddress 192.168.0.3
ntpsigndsocket /opt/samba/var/lib/ntp_signd
_EOF_
[root@c ~]#
[root@c ~]# chown root:chrony /opt/samba/var/lib/ntp_signd/
[root@c ~]# chmod 750 /opt/samba/var/lib/ntp_signd/
[root@c ~]# systemctl restart chronyd
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]
dns forwarder = 192.168.0.1
netbios name = C
realm = SYBYL.LOCAL
server role = active directory domain controller
workgroup = SYBYL
idmap_ldb:use rfc2307 = yes
#server services = s3fs, rpc, nbt, wrepl, ldap, cldap, kdc, drepl, winbindd, ntp_signd, kcc, dnsupdate, dns
# 「dns」をdnsmasqで提供しているので削除
server services = s3fs, rpc, nbt, wrepl, ldap, cldap, kdc, drepl, winbindd, ntp_signd, kcc, dnsupdate
password server = c.sybyl.local
printing = bsd
log level=1
log file = /var/log/samba.log
utmp = yes
ldap server require strong auth = no
kerberos method = secrets and keytab
[sysvol]
path = /opt/samba/var/locks/sysvol
read only = No
[netlogon]
path = /opt/samba/var/locks/sysvol/sybyl.local/scripts
read only = No
[home]
path = /home/
read only = no
[root@c ~]#
*ユーザホームは従来の[homes]の代わりに[home]を使ってます。またパスの指定も語尾に'/'を入れている
*隠されているパラメーターは「/opt/samba/bin/testparm -v」で確認できます。
Step 11: Configure samba.service †
samba起動スクリプトを用意します。ここではCentOS 8なのでsystemd向けの
ファイルを用意します。
configureの際、--with-systemdとフラグを付けて*.serviceにて稼働させるようにした
[root@c samba-4.11.0]# find . -name *.service -exec ls -l {} \;
-rw-rw-r-- 1 root root 387 Jul 9 19:08 ./ctdb/config/ctdb.service
-rw-r--r-- 1 root root 501 Oct 14 07:33 ./bin/default/packaging/systemd/smb.service
-rw-r--r-- 1 root root 455 Oct 14 07:33 ./bin/default/packaging/systemd/nmb.service
-rw-r--r-- 1 root root 438 Oct 14 07:33 ./bin/default/packaging/systemd/winbind.service
-rw-r--r-- 1 root root 457 Oct 14 07:33 ./bin/default/packaging/systemd/samba.service
[root@c samba-4.11.0]#
service稼働に読み込まれる設定ファイル(samba.sysconfig)を、/etc/sysconfig/sambaとして、samba.serviceは下記のようにした。
[root@c samba-4.11.0]# cp packaging/systemd/samba.sysconfig /etc/sysconfig/samba
[root@c samba-4.11.0]# echo "d /run/samba 755 root root" > /etc/tmpfiles.d/samba.conf
[root@c samba-4.11.0]# /usr/bin/systemd-tmpfiles --create /etc/tmpfiles.d/samba.conf
[root@c samba-4.11.0]# cp packaging/systemd/samba.service.in /etc/systemd/system/samba.service
(samba.serviceを修正)
[root@c samba-4.11.0]# vi /etc/systemd/system/samba.service
[Unit]
Description=Samba AD Daemon
Documentation=man:samba(8) man:samba(7) man:smb.conf(5)
Wants=network-online.target
After=network.target network-online.target
[Service]
#Type=notify <-- Typeを「notify」から「simple」へ変更します
Type=simple
NotifyAccess=all
PIDFile=/run/samba/samba.pid
LimitNOFILE=16384
EnvironmentFile=/etc/sysconfig/samba
ExecStart=/opt/samba/sbin/samba --foreground --no-process-group $SAMBAOPTIONS
ExecReload=/bin/kill -HUP $MAINPID
[Install]
WantedBy=multi-user.target
[root@c samba-4.11.0]#
留意 PIDFile は、/run/samba/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
現在までに「Step 5: Starting Samba」で起動しているsambaプロセスがあるならCtrl+Cで止める。
それから下記を実行します。
[root@c systemd]# systemctl start samba.service
[root@c systemd]# journalctl -f -u samba --full -e
journalctl とかで正常に動いているかを確認します。
これでインストールと起動は完了。次はユーザ作成
firewall-cmd †
firewallが有効なら下記を設定して外部からのアクセスを許容させます
[root@c ~]# firewall-cmd --add-service=samba-dc --permanent
(nfsサーバにもなるなら下記も実行する)
firewall-cmd --add-service=mountd --permanent
firewall-cmd --add-service=nfs --permanent
firewall-cmd --add-service=rpc-bind --permanent
[root@c ~]# firewall-cmd --reload