ONTAP 9.5でsambaドメインに参加できない & ONTAP 9.7で失敗

samba 4.11.6で作ったActive DirectoryにONTAP 9.5を参加させようとするとエラーになる。

ONTAP API が失敗しました: Failed to create the Active Directory machine account "ファイルサーバ名". Reason: LDAP Error: Strong authentication is required Details: Error: Machine account creation procedure failed [ 136] Loaded the preliminary configuration. [ 215] Successfully connected to ip ADサーバIP, port 88 using TCP [ 284] Successfully connected to ip ADサーバIP, port 389 using TCP [ 308] Unable to connect to LDAP (Active Directory) service on ADサーバホスト名 (Error: Strong(er) authentication required) **[ 308] FAILURE: Unable to make a connection (LDAP (Active ** Directory):AD名), result: 7609 . (エラー:13001)

調べたところ、sambaのglobal設定で「ldap server require strong auth = no」を設定する、とのこと。

これを設定し、sambaを再起動したところ、参加できた。


ONTAP 9.7にて、上記手順を実施した上で参加を試みたところ「Unable to connect to NetLogon service on」というエラーになった。

netapp::> vserver cifs create -vserver ファイルサーバ名 -cifs-server ファイルサーバ名 -domain AD名 -ou CN=Computers -default-site "" -status-admin up -comment "" -netbios-aliases ファイルサーバ名

In order to create an Active Directory machine account for the CIFS server, you
must supply the name and password of a Windows account with sufficient
privileges to add computers to the "CN=Computers" container within the
"AD名" domain.

Enter the user name: administrator

Enter the password:

Warning: An account by this name already exists in Active Directory at
         CN=ファイルサーバ名,CN=Computers,DC=xx,DC=xx.
         If there is an existing DNS entry for the name ファイルサーバ名, it must be
         removed. Data ONTAP cannot remove such an entry.
         Use an external tool to remove it after this command completes.
         Ok to reuse this account? {y|n}: y

Error: Machine account creation procedure failed
  [    31] Loaded the preliminary configuration.
  [   107] Created a machine account in the domain
  [   108] SID to name translations of Domain Users and Admins
           completed successfully
  [   113] Modified account 'cn=ファイルサーバ名,CN=Computers,dc=xx
           =CO,dc=JP'
  [   114] Successfully connected to ip xx.xx.xx.xx, port 88 using
           TCP
  [   129] Successfully connected to ip xx.xx.xx.xx, port 464
           using TCP
  [   216] Kerberos password set for 'ファイルサーバ名$@AD名'
           succeeded
  [   216] Set initial account password
  [   223] Successfully connected to ip xx.xx.xx.xx, port 445
           using TCP
  [   274] Successfully connected to ip xx.xx.xx.xx, port 88 using
           TCP
  [   297] Successfully authenticated with DC
           adserver.AD名
  [   322] Unable to connect to NetLogon service on
           adserver.AD名 (Error:
           RESULT_ERROR_GENERAL_FAILURE)
**[   322] FAILURE: Unable to make a connection
**         (NetLogon:AD名), result: 3
  [   322] Unable to make a NetLogon connection to
           adserver.AD名 using the new machine account

Error: command failed: Failed to create the Active Directory machine account
       "ファイルサーバ名". Reason: general failure.

netapp::>

このとき「vserver cifs security show -vserver ファイルサーバ名」で確認する「SMB? Enabled for DC Connections」は下記の通り。

netapp::> vserver cifs security show -vserver ファイルサーバ名

Vserver: ファイルサーバ名

                            Kerberos Clock Skew:                   - minutes
                            Kerberos Ticket Age:                   - hours
                           Kerberos Renewal Age:                   - days
                           Kerberos KDC Timeout:                   - seconds
                            Is Signing Required:                   -
                Is Password Complexity Required:                   -
           Use start_tls for AD LDAP connection:               false
                      Is AES Encryption Enabled:               false
                         LM Compatibility Level:  lm-ntlm-ntlmv2-krb
                     Is SMB Encryption Required:                   -
                        Client Session Security:                none
                SMB1 Enabled for DC Connections:               false
                SMB2 Enabled for DC Connections:      system-default
  LDAP Referral Enabled For AD LDAP connections:               false
               Use LDAPS for AD LDAP connection:               false

netapp::>

「SMB1 Enabled for DC Connections」をtrueに変更しても状況は変わらず。

Sambaサーバの /usr/local/samba/var/log.samba を確認すると、以下の出力があった。

[2020/08/07 14:26:55.226653,  0] ../../source4/rpc_server/netlogon/dcerpc_netlogon.c:284(dcesrv_netr_ServerAuthenticate3_helper)
  dcesrv_netr_ServerAuthenticate3_helper: schannel required but client failed to offer it. Client was ファイルサーバ名$

「schannel」というオプションが必要らしい。

Netlogon Issue “schannel required”」を参考に設定してみたところ、schannelというオプションはないというエラー…「Bug 13464 – smb.conf-configuration “server schannel = auto” needed in future versions」を見ると「server schannel = auto」が正しい模様。

/usr/local/samba/etc/smb.conf を下記の様に修正して、sambaを再起動したところ、ONTAP 9.7でのActive Directoryの参加が可能になった。

# Global parameters
[global]
        netbios name = ADサーバ名
        realm = AD名
        server role = active directory domain controller
        workgroup = AD名
        idmap_ldb:use rfc2307 = yes
        ldap server require strong auth = no
        server schannel = auto

[netlogon]
        path = /usr/local/samba/var/locks/sysvol/AD名/scripts
        read only = No

[sysvol]
        path = /usr/local/samba/var/locks/sysvol
        read only = No

samba 4で構築したドメインにNetApp 9.5が登録できない

注:この記事での事象はsamba 4で使用していた証明書の期限切れが原因でした。
「LDAP Error: Strong authentication is required Details」もしくは「「Unable to connect to NetLogon service on」」というエラーがでる場合については別途「ONTAP 9.5でsambaドメインに参加できない & ONTAP 9.7で失敗」という記事にしています。


テスト環境作成のためNetAppシミュレータの9.5P6を作ってsamba 4で構築したActive Directory環境に登録しようとした・・・

netapp95sim::*> vserver cifs create -cifs-server netappcifs -domain ad.osakana.net -ou CN=Computers -vserver netappcifs -netbios-aliases netappcifs

In order to create an Active Directory machine account for the CIFS server, you must supply the name and password of a
Windows account with sufficient privileges to add computers to the "CN=Computers" container within the "AD.OSAKANA.NET"
domain.

Enter the user name: administrator

Enter the password:

Error: Machine account creation procedure failed
  [   215] Loaded the preliminary configuration.
  [   267] Successfully connected to ip 172.17.44.49, port 88 using
           TCP
  [   342] Successfully connected to ip 172.17.44.49, port 636 using
           TCP
  [   379] Required certificate with CA ADSERVER.ad.osakana.net is
           not installed
  [   381] Unable to start LDAPS: Can't contact LDAP server
  [   381] Additional info: error:14090086:SSL
           routines:ssl3_get_server_certificate:certificate verify
           failed
  [   381] Unable to connect to LDAP (Active Directory) service on
           adserver.ad.osakana.net (Error: Can't contact LDAP
           server)
**[   381] FAILURE: Unable to make a connection (LDAP (Active
**         Directory):AD.OSAKANA.NET), result: 7642

Error: command failed: Failed to create the Active Directory machine account "netappcifs". Reason: LDAP Error: Cannot
       contact the LDAP server.

netapp95sim::*>

エラー発生。

なんか調べたところ、active-directoryというコマンドでも登録できるらしいのでそれでもテストしてみる。

netapp95sim::*> active-directory create -vserver netappcifs -account-name adserver -domain ad.osakana.net
  (vserver active-directory create)

In order to create an Active Directory machine account, you must supply the name and password of a Windows account with
sufficient privileges to add computers to the "CN=Computers" container within the "AD.OSAKANA.NET" domain.

Enter the user name: administrator

Enter the password:

Error: Machine account creation procedure failed
  [   179] Loaded the preliminary configuration.
  [   230] Successfully connected to ip 172.17.44.49, port 88 using
           TCP
  [   298] Successfully connected to ip 172.17.44.49, port 636 using
           TCP
  [   333] Required certificate with CA ADSERVER.ad.osakana.net is
           not installed
  [   335] Unable to start LDAPS: Can't contact LDAP server
  [   335] Additional info: error:14090086:SSL
           routines:ssl3_get_server_certificate:certificate verify
           failed
  [   336] Unable to connect to LDAP (Active Directory) service on
           adserver.ad.osakana.net (Error: Can't contact LDAP
           server)
**[   336] FAILURE: Unable to make a connection (LDAP (Active
**         Directory):AD.OSAKANA.NET), result: 7642

Error: command failed: Failed to create the Active Directory machine account "ADSERVER". Reason: LDAP Error: Cannot
       contact the LDAP server.

netapp95sim::*>

同じようにエラー。

この後いろいろ試行錯誤した結果、自己証明CAをNetAppに入れればいいのでは?とやってみた。(「クラスタまたはSVMがクライアントであるSSLサーバを認証するためのサーバCA証明書のインストール」)

netapp95sim::*> security certificate install -vserver netappcifs -type server-ca

Please enter Certificate: Press <Enter> when done
-----BEGIN CERTIFICATE-----
<sambaの/usr/local/samba/private/tls/ca.pemの内容を張り付け>
-----END CERTIFICATE-----


Error: command failed: The certificate has expired.

netapp95sim::*>

ん?「The certificate has expired.」???

samba公式「Configuring LDAP over SSL (LDAPS) on a Samba AD DC」の「Verifying the certificate」に書いてある手法で確認してみます。

# ls -l  /usr/local/samba/private/tls
合計 12
-rw-r--r--. 1 root root 2041  3月 27  2018 ca.pem
-rw-r--r--. 1 root root 2045  3月 27  2018 cert.pem
-rw-------. 1 root root 3243  3月 27  2018 key.pem
#

# openssl verify /usr/local/samba/private/tls/cert.pem -CApath /usr/local/samba/private/tls/ca.pem
/usr/local/samba/private/tls/cert.pem: O = Samba Administration, OU = Samba - temporary autogenerated HOST certificate, CN = ADSERVER.AD.OSAKANA.NET
error 20 at 0 depth lookup:unable to get local issuer certificate
Error opening certificate file -CApath
140285523859344:error:02001002:system library:fopen:No such file or directory:bss_file.c:402:fopen('-CApath','r')
140285523859344:error:20074002:BIO routines:FILE_CTRL:system lib:bss_file.c:404:
unable to load certificate
/usr/local/samba/private/tls/ca.pem: O = Samba Administration, OU = Samba - temporary autogenerated CA certificate, CN = ADSERVER.AD.OSAKANA.NET
error 18 at 0 depth lookup:self signed certificate
O = Samba Administration, OU = Samba - temporary autogenerated CA certificate, CN = ADSERVER.AD.OSAKANA.NET
error 10 at 0 depth lookup:certificate has expired
OK
#

はい。証明書の有効期限切れでした。

手順がめんどいので、/usr/local/samba/private/tlsにあるファイルをリネームしてから「systemctl stop samba-ad-dc.service」「systemctl start samba-ad-dc.service」で強制再作成させました。

samba 4.10.x環境で出てたsamba_dnsupdateのエラー対処

samba 4.10.7へアップデートしたあと、「systemctl status samba-ad-dc.service」で出力されるログを見てみたら、微妙な感じのエラーがあった。

 8月 29 08:54:02 adserver samba[107156]: [2019/08/29 08:54:02.287210,  0] ../../lib/util/util_runcmd.c:327(samba_runcmd_io_handler)
 8月 29 08:54:02 adserver samba[107156]:   /usr/local/samba/sbin/samba_dnsupdate: ImportError: No module named dns.resolver
 8月 29 08:54:02 adserver samba[107156]: [2019/08/29 08:54:02.295161,  0] ../../source4/dsdb/dns/dns_update.c:331(dnsupdate_nameupdate_done)
 8月 29 08:54:02 adserver samba[107156]:   dnsupdate_nameupdate_done: Failed DNS update with exit code 1
 8月 29 08:54:03 adserver winbindd[107159]: [2019/08/29 08:54:03.430795,  0] ../../source3/winbindd/winbindd_cache.c:3166(initialize_winbindd_cache)
 8月 29 08:54:03 adserver winbindd[107159]:   initialize_winbindd_cache: clearing cache and re-creating with version number 2
 8月 29 08:54:03 adserver smbd[107151]: [2019/08/29 08:54:03.438943,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
 8月 29 08:54:03 adserver smbd[107151]:   daemon_ready: daemon 'smbd' finished starting up and ready to serve connections
 8月 29 08:54:03 adserver winbindd[107159]: [2019/08/29 08:54:03.454411,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
 8月 29 08:54:03 adserver winbindd[107159]:   daemon_ready: daemon 'winbindd' finished starting up and ready to serve connections

「samba_dnsupdate: ImportError: No module named dns.resolver」の対応

現状の確認方法

[root@adserver ~]# samba_dnsupdate --verbose
Traceback (most recent call last):
  File "/usr/local/samba/sbin/samba_dnsupdate", line 57, in <module>
    import dns.resolver
ImportError: No module named dns.resolver
[root@adserver ~]#

原因はpythonのDNS toolkitがインストールされていないこと。

CentOS7環境で対処するには「yum search dnspython」を実行してモジュール名を確認

[root@adserver ~]# yum search dnspython
読み込んだプラグイン:fastestmirror
Determining fastest mirrors
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
=============================== 一致: dnspython ================================
python-dns.noarch : DNS toolkit for Python
python36-dns.noarch : DNS toolkit for Python 3
[root@adserver ~]#

今回使っている環境はpython 2環境なので、「yum install python-dns」でインストール。

[root@adserver ~]# yum install python-dns.noarch
読み込んだプラグイン:fastestmirror
Loading mirror speeds from cached hostfile
epel/x86_64/metalink                                     | 7.3 kB     00:00
 * base: ftp.riken.jp
 * epel: ftp.riken.jp
 * extras: ftp.riken.jp
 * updates: ftp.riken.jp
base                                                     | 3.6 kB     00:00
epel                                                     | 5.4 kB     00:00
extras                                                   | 3.4 kB     00:00
packages-microsoft-com-prod                              | 2.9 kB     00:00
updates                                                  | 3.4 kB     00:00
(1/3): epel/x86_64/updateinfo                              | 998 kB   00:02
(2/3): packages-microsoft-com-prod/primary_db              | 200 kB   00:00
(3/3): epel/x86_64/primary_db                              | 6.8 MB   00:03
依存性の解決をしています
--> トランザクションの確認を実行しています。
---> パッケージ python-dns.noarch 0:1.12.0-4.20150617git465785f.el7 を インスト ール
--> 依存性解決を終了しました。

依存性を解決しました

================================================================================
 Package        アーキテクチャー
                           バージョン                            リポジトリー
                                                                           容量
================================================================================
インストール中:
 python-dns     noarch     1.12.0-4.20150617git465785f.el7       base     233 k

トランザクションの要約
================================================================================
インストール  1 パッケージ

総ダウンロード容量: 233 k
インストール容量: 1.0 M
Is this ok [y/d/N]: y
Downloading packages:
python-dns-1.12.0-4.20150617git465785f.el7.noarch.rpm      | 233 kB   00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  インストール中          : python-dns-1.12.0-4.20150617git465785f.el7.no   1/1
  検証中                  : python-dns-1.12.0-4.20150617git465785f.el7.no   1/1

インストール:
  python-dns.noarch 0:1.12.0-4.20150617git465785f.el7

完了しました!
[root@adserver ~]#

動作確認・・・

[root@adserver ~]# samba_dnsupdate --verbose
IPs: ['172.17.44.49']
Looking for DNS entry A adserver.adosakana.local 172.17.44.49 as adserver.adosakana.local.
Looking for DNS entry NS adosakana.local adserver.adosakana.local as adosakana.local
<略>
Checking 0 100 389 adserver.adosakana.local. against SRV _ldap._tcp.Default-First-Site-Name._sites.ForestDnsZones.adosakana.local adserver.adosakana.local 389
No DNS updates needed
[root@adserver ~]#

それ以外のログについて

samba_dnsupdateに関するエラーについて対処した後、sambaを再起動してログを見てみると、下記の様な感じになっていた。

 8月 29 09:06:46 adserver samba[107294]: [2019/08/29 09:06:46.991243,  0] ../../source4/smbd/server.c:773(binary_smbd_main)
 8月 29 09:06:46 adserver samba[107294]:   binary_smbd_main: samba: using 'standard' process model
 8月 29 09:06:47 adserver samba[107294]: [2019/08/29 09:06:47.021548,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
 8月 29 09:06:47 adserver samba[107294]:   daemon_ready: daemon 'samba' finished starting up and ready to serve connections
 8月 29 09:06:49 adserver winbindd[107312]: [2019/08/29 09:06:49.157089,  0] ../../source3/winbindd/winbindd_cache.c:3166(initialize_winbindd_cache)
 8月 29 09:06:49 adserver winbindd[107312]:   initialize_winbindd_cache: clearing cache and re-creating with version number 2
 8月 29 09:06:49 adserver winbindd[107312]: [2019/08/29 09:06:49.266323,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
 8月 29 09:06:49 adserver winbindd[107312]:   daemon_ready: daemon 'winbindd' finished starting up and ready to serve connections
 8月 29 09:06:50 adserver smbd[107311]: [2019/08/29 09:06:50.436561,  0] ../../lib/util/become_daemon.c:136(daemon_ready)
 8月 29 09:06:50 adserver smbd[107311]:   daemon_ready: daemon 'smbd' finished starting up and ready to serve connections

RHEL7だと上記出力を赤文字で出力してるけど、内容を見る限りではinformation的なものであるので、特に対処する必要はなさそうである。

Samba 4.10.xでActive Directoryを1から立てる

Samba 4.10.2に更新した際に、python関連で修正点があったので更新。なお、この記事は、Active Directoryサーバとして使用することについてのみ解説しています。ファイルサーバとして使用することについては記述していません。

Samba 4.10.xにおける大きな変更点は「python3がデフォルト」「python2サポートの最終バージョン」です。RHEL7/CentOS7環境はpython2なので、あまり変更せずに使える最終バージョンといった感じです。なお、RHEL7/CentOS7のEPELには「python36」というパッケージ名でpython 3.6があるので、それを追加インストールすることはできます。

なお、過去バージョンの履歴。2018年12月版「Samba 4.9.xでActive Directoryを1から立てる」、2018年3月版「Samba 4.7.xでActive Directoryを1から立てる」、2016年7月版「Samba 4.4.xでActive Directoryを1から立てる」、2014年2月版「Samba 4.xでActive Directoryを1から立てる

さて、Linux上でSambaを使ってActive Directoryサーバを立てるメリットは以下の点です。

その1:Windows Serverを買わなくてもActive Directoryを作れる

WindowsのCALを買わずにActive Directory環境の構築ができるため、ライセンス費用の低減になります。

その2:Active Directoryユーザの作成などのユーザ管理をWindowsマシンからWindows標準ツールで行える

ユーザーの作成/変更、コンピューターアカウントの作成、DNSの管理など、Active Directoryの管理を行う際に頻繁に使う操作については、WindowsのActive Directory管理ツールやDNS管理ツールを使用することができる。このため、普段はLinuxのCLIコマンド(samba-toolsやnetコマンドなど)を使う必要はない。

Active Directoryに参加しているWindowsマシンに、Windows機能のActive Directory管理ツールを追加インストールし、Active Directoryの管理者にてログオンすることで、管理ができる。

その3:sambaの設定は難しくない

10年ぐらい前のsambaでは、DNSサーバやLDAPサーバをsambaとは別に用意し、連携する必要がありました。いまのsambaはDNSサーバとLDAPサーバの機能が統合されているため設定が容易になりました。

Active Directory名とActive Directory上の役割、管理者パスワードを設定するぐらいで環境を作成することができます。

逆にデメリットとしてどのようなものがあるか?

その1:Active Directoryの全機能が搭載されていない

ドメイン/フォレストの機能レベルがWindows Server 2012R2レベルまで対応になったものの、「Kerberos関連機能が未搭載」となっています。(samba公式wiki「Raising the Functional Levels」)

「Windows Server 2008 R2」レベルまでであればフルサポートしています。このレベルであれば、Windows Server 2016環境でフェイルオーバークラスターマネージャーでクラスタを組むこともできました。(samba 4.7ぐらいから可能になった)


手順は、公式の「Setting up Samba as an Active Directory Domain Controller」と「Package Dependencies Required to Build Samba」を参照しながら実施していきます。

1. CentOS7の最小インストールを実施

2. /etc/hostsの修正

自ホスト名を/etc/hostsに追加。
追加の際は、ショートのホスト名と、ドメイン付きのFQDNの両方を列挙すること。

[root@adserver ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.17.44.40    adserver adserver.adosakana.local
[root@adserver ~]#

3. 好みに応じて使うツールをインストール

セッションが途中で切れても良い様に「screen」か「tmux」と、ファイルダウンロードするためにwgetかcurlをインストールします。

[root@adserver ~]# yum install wget screen
<略>
[root@adserver ~]#

4. 必要なパッケージをインストール

Samba公式の「Package Dependencies Required to Build Samba」に記載されているパッケージをインストール

[root@adserver ~]# yum install attr bind-utils docbook-style-xsl gcc gdb krb5-workstation \
       libsemanage-python libxslt perl perl-ExtUtils-MakeMaker \
       perl-Parse-Yapp perl-Test-Base pkgconfig policycoreutils-python \
       python2-crypto gnutls-devel libattr-devel keyutils-libs-devel \
       libacl-devel libaio-devel libblkid-devel libxml2-devel openldap-devel \
       pam-devel popt-devel python-devel readline-devel zlib-devel systemd-devel \
       lmdb-devel jansson-devel gpgme-devel pygpgme libarchive-devel
<略>
[root@adserver ~]#

ここで問題発生・・・上記の説明に「RHEL7ではEPELレポジトリを追加する必要があるが、CentOS7とScientific Linux7では不要」とあるが、CentOS7環境で試してみると「perl-Test-Base」と「lmdb-devel」は無い。

EPELレポジトリを追加してから、必要なパッケージのインストールをやり直します。(なお、perl-Test-Baseに関連付いていろいろパッケージが追加されます。)

[root@adserver ~]# yum install epel-release.noarch
<略>
[root@adserver ~]#

5. sambaのtar.gzをダウンロード

samba.orgからsambaをダウンロードします。

[root@adserver ~]# wget https://download.samba.org/pub/samba/stable/samba-4.10.2.tar.gz
--2018-12-28 13:10:22--  https://download.samba.org/pub/samba/stable/samba-4.10.2.tar.gz
download.samba.org (download.samba.org) をDNSに問いあわせています... 144.76.82.156, 2a01:4f8:192:486::443:2
download.samba.org (download.samba.org)|144.76.82.156|:443 に接続しています...  接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 18053738 (17M) [application/gzip]
`samba-4.10.2.tar.gz' に保存中

100%[======================================>] 18,053,738  3.65MB/s 時間 5.9s

2018-12-28 13:10:29 (2.93 MB/s) - `samba-4.10.2.tar.gz' へ保存完了 [18053738/18053738]

[root@adserver ~]# 

6. configure実施

samba 4.10.0より、標準で使用されるpythonのバージョンが3になりました。このため、RHEL7/CentOS7環境では「python3」が無いことにより下記の様なエラーとなります。

[root@adserver samba-4.10.2]# ./configure
/usr/bin/env: python3: そのようなファイルやディレクトリはありません
[root@adserver samba-4.10.2]#

これを避けるために「PYTHON=python2 ./configure」というような形で実行します。(Samba 4.10.0リリースノートより)

[root@adserver ~]# tar xfz samba-4.10.2.tar.gz
[root@adserver ~]# cd samba-4.10.2/
[root@adserver samba-4.10.2]# PYTHON=python2 ./configure
Setting top to                           : /root/samba-4.10.2
Setting out to                           : /root/samba-4.10.2/bin
Checking for 'gcc' (C compiler)          : /usr/bin/gcc
Checking for program 'git'               : /usr/bin/git
Checking for c flags '-MMD'              : yes
Checking for program 'gdb'               : /usr/bin/gdb
Checking for header sys/utsname.h        : yes

<略>
Checking if compiler accepts -fstack-protector                                                  : no
Checking if compiler accepts -fstack-protector                                                  : no
Checking if compiler accepts -fstack-clash-protection                                           : yes
'configure' finished successfully (1m43.247s)
[root@adserver samba-4.10.2]#

7. make & make install

こちらもRHEL7/CentOS7の場合は「PYTHON=python2 make」、「PYTHON=python2 make install」と実行します。

[root@adserver samba-4.10.2]# PYTHON=python2 make
PYTHONHASHSEED=1 WAF_MAKE=1 python2 ./buildtools/bin/waf build
Waf: Entering directory `/root/samba-4.10.2/bin/default'
<略>
[4112/4118] Compiling source4/scripting/man/samba-gpupdate.8.xml
Note: Writing samba-gpupdate.8

[4113/4118] Compiling pidl/lib/Parse/Pidl/Wireshark/NDR.pm
[4114/4118] Compiling pidl/lib/Parse/Pidl/Dump.pm
[4115/4118] Compiling pidl/lib/Parse/Pidl/Wireshark/Conformance.pm
[4116/4118] Compiling pidl/pidl
[4117/4118] Compiling pidl/lib/Parse/Pidl/NDR.pm
[4118/4118] Compiling pidl/lib/Parse/Pidl/Util.pm
Waf: Leaving directory `/root/samba-4.10.2/bin/default'
'build' finished successfully (19m50.933s)
[root@adserver samba-4.10.2]# PYTHON=python2 make install
PYTHONHASHSEED=1 WAF_MAKE=1 python2 ./buildtools/bin/waf install
Waf: Entering directory `/root/samba-4.10.2/bin/default'
        Selected embedded Heimdal build
Checking project rules ...
<略>
+ install /usr/local/samba/share/man/man3/Parse::Pidl::NDR.3pm (from bin/default/pidl/Parse::Pidl::NDR.3pm)
+ install /usr/local/samba/share/man/man3/Parse::Pidl::Util.3pm (from bin/default/pidl/Parse::Pidl::Util.3pm)
Waf: Leaving directory `/root/samba-4.10.2/bin/default'
'install' finished successfully (5m24.784s)
[root@adserver samba-4.10.2]#

8. インストール完了確認

インストールされたsambaのバージョンを確認します。

[root@adserver samba-4.10.2]# /usr/local/samba/sbin/samba -V
Version 4.10.2
[root@adserver samba-4.10.2]#

9. Active Directoryのセットアップ

ドメイン「adosakana.local」を作成します。
また、sambaの機能を使ってAD DNSを構築するので「SAMBA_INTERNAL」を選択します。

なお、「–use-rfc2307」はADにNIS連携機能を追加するオプションです。AD上にUnix用のUID/GID/shell情報なども格納できるようにします。Samba環境では有効にしておくべきものです。

また、セットアップ中、「Merge the contents of this file with your system krb5.conf or replace it with this one. Do not create a symlink!」とメッセージが出ますが、これは、この手順で自動生成されたkrb5.confをシステムのもつkrb5.confと統合しろ、というお知らせです。後の手順で対処します。

[root@adserver samba-4.10.2]# /usr/local/samba/bin/samba-tool domain provision --use-rfc2307 --interactive
Realm [example.com]:  ADOSAKANA.LOCAL
Domain [ADOSAKANA]:
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) [172.30.50.100]:  172.30.50.100
Administrator password:
Retype password:
Looking up IPv4 addresses
Looking up IPv6 addresses
No IPv6 address will be assigned
Setting up share.ldb
Setting up secrets.ldb
Setting up the registry
Setting up the privileges database
Setting up idmap db
Setting up SAM db
Setting up sam.ldb partitions and settings
Setting up sam.ldb rootDSE
Pre-loading the Samba 4 and AD schema
Unable to determine the DomainSID, can not enforce uniqueness constraint on local domainSIDs

Adding DomainDN: DC=adosakana,DC=local
Adding configuration container
Setting up sam.ldb schema
Setting up sam.ldb configuration data
Setting up display specifiers
Modifying display specifiers and extended rights
Adding users container
Modifying users container
Adding computers container
Modifying computers container
Setting up sam.ldb data
Setting up well known security principals
Setting up sam.ldb users and groups
Setting up self join
Adding DNS accounts
Creating CN=MicrosoftDNS,CN=System,DC=adosakana,DC=local
Creating DomainDnsZones and ForestDnsZones partitions
Populating DomainDnsZones and ForestDnsZones partitions
Setting up sam.ldb rootDSE marking as synchronized
Fixing provision GUIDs
A Kerberos configuration suitable for Samba AD has been generated at /usr/local/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:              wk70
NetBIOS Domain:        ADOSAKANA
DNS Domain:            adosakana.local
DOMAIN SID:            S-1-5-21-3471449246-245784766-327389652
[root@adserver samba-4.10.2]#

10. sambaを起動

sambaが起動していないことを確認した上で、sambaを起動します。

[root@adserver samba-4.10.2]# ps -ef|grep samba
root      30118   5011  0 18:40 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.10.2]# /usr/local/samba/sbin/samba
[root@adserver samba-4.10.2]# ps -ef|grep samba
root      30120      1 12 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30121  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30122  30120  1 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30123  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30124  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30125  30120 11 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30126  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30127  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30128  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30129  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30130  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30131  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30132  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30133  30120  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30134  30121  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30136  30129  0 18:41 ?        00:00:00 /usr/local/samba/sbin/samba
root      30137  30134 17 18:41 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      30140  30136 16 18:41 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      30144  30137  0 18:41 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      30145  30137  0 18:41 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      30146  30140  1 18:41 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      30151  30140  0 18:41 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      30152  30140  0 18:41 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      30153  30137  0 18:41 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      30155   5011  0 18:41 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.10.2]#

11. 動作確認

CentOS内部からSMB接続を行うテストを実施。

[root@adserver samba-4.10.2]# /usr/local/samba/bin/smbclient --version
Version 4.10.2
[root@adserver samba-4.10.2]# /usr/local/samba/bin/smbclient -L localhost -U%

        Sharename       Type      Comment
        ---------       ----      -------
        netlogon        Disk
        sysvol          Disk
        IPC$            IPC       IPC Service (Samba 4.10.2)
Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
[root@adserver samba-4.10.2]#

以前は「Domain=[ADOSAKANA.LOCAL] OS=[Unix] Server=[Samba x.y.z]」という出力もあったのですが、Samba 4.7以降では無くなっています。

netlogon共有にAdministrator権限でアクセスできるか確認。

[root@adserver samba-4.10.2]# /usr/local/samba/bin/smbclient //localhost/netlogon -UAdministrator -c 'ls'
Enter ADOSAKANA\Administrator's password:
  .                                   D        0  Tue Mar 27 17:47:04 2018
  ..                                  D        0  Tue Mar 27 17:47:51 2018

                17811456 blocks of size 1024. 12499620 blocks available
[root@adserver samba-4.10.2]#

12. AD DNSの動作テスト

AD DNSが想定通りに動作しているかテストします。

まず、どんなzoneが登録されているのか確認します。

[root@adserver samba-4.10.2]# /usr/local/samba/bin/samba-tool dns zonelist 127.0.0.1 -U Administrator
Password for [ADOSAKANA\Administrator]:
  2 zone(s) found

  pszZoneName                 : adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_DOMAIN_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : DomainDnsZones.adosakana.local

  pszZoneName                 : _msdcs.adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_FOREST_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : ForestDnsZones.adosakana.local
[root@adserver samba-4.10.2]#

Active Directoryで使用するDNSのSRVレコードが登録されているかをhostコマンドを使って確認します。

[root@adserver samba-4.10.2]# host -t SRV _ldap._tcp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_ldap._tcp.adosakana.local has SRV record 0 100 389 adserver.adosakana.local.
[root@adserver samba-4.10.2]# host -t SRV _kerberos._udp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_kerberos._udp.adosakana.local has SRV record 0 100 88 adserver.adosakana.local.
[root@adserver samba-4.10.2]#

ADサーバのホスト名が登録されているか確認します。

[root@adserver samba-4.10.2]# host -t A adserver.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

adserver.adosakana.local has address 172.17.15.70
[root@adserver samba-4.10.2]#

13. DNSサーバの変更

ADサーバの/etc/resolv.confを、ADサーバ自身を使う様に書き換えます。

14. /etc/krb5.conf の変更

/usr/local/samba/private/krb5.conf に元となるものが自動生成されているので、それを使用する。

[root@adserver samba-4.10.2]# ls -l /etc/krb5.conf /usr/local/samba/private/krb5.conf
-rw-r--r--. 1 root root 641 10月 30 23:40 /etc/krb5.conf
-rw-rw-rw-. 1 root root  96 12月 28 14:13 /usr/local/samba/private/krb5.conf
[root@adserver samba-4.10.2]# cat /usr/local/samba/private/krb5.conf
[libdefaults]
        default_realm = ADOSAKANA.LOCAL
        dns_lookup_realm = false
        dns_lookup_kdc = true
[root@adserver samba-4.10.2]# cp /usr/local/samba/private/krb5.conf /etc/krb5.conf
cp: `/etc/krb5.conf' を上書きしますか? y
[root@adserver samba-4.10.2]#

15. Kerberosの動作確認

「kinit administrator@ドメイン名」を実行して確認します。

[root@adserver samba-4.10.2]# kinit administrator@ADOSAKANA.LOCAL
Password for administrator@ADOSAKANA.LOCAL:
Warning: Your password will expire in 41 days on 2019年02月08日 14時13分15秒
[root@adserver samba-4.10.2]#

正常に設定されていれば、上記の様にAdministratorユーザのパスワード有効期限が表示されます。

「klist」コマンドでも確認することが出来ます。

[root@adserver samba-4.10.2]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@ADOSAKANA.LOCAL

Valid starting       Expires              Service principal
2018-12-28T14:26:25  2018-12-29T00:26:25  krbtgt/ADOSAKANA.LOCAL@ADOSAKANA.LOCAL
        renew until 2018-12-29T14:26:22
[root@adserver samba-4.10.2]#

なお、ドメイン名指定の大文字/小文字を間違えると下記の様なエラーとなります。

[root@adserver ~]# kinit administrator@adosakana.local
Password for administrator@adosakana.local:
kinit: KDC reply did not match expectations while getting initial credentials
[root@adserver ~]#

DNSサーバ指定が誤っている場合は下記の様なエラーです。

[root@adserver ~]# kinit administrator@ADOSAKANA.LOCAL
kinit: Cannot resolve servers for KDC in realm "ADOSAKANA.LOCAL" while getting initial credentials
[root@adserver ~]#

16. フォレストとドメインの機能レベル確認

作成したActive Directoryのドメインの機能レベルとフォレストの機能レベルを確認します。

[root@adserver samba-4.10.2]# /usr/local/samba/bin/samba-tool domain level show
Domain and forest function level for domain 'DC=adosakana,DC=local'

Forest function level: (Windows) 2008 R2
Domain function level: (Windows) 2008 R2
Lowest function level of a DC: (Windows) 2008 R2
[root@adserver samba-4.10.2]#

Samba 4.10.2でもWindows Server 2008R2が標準設定となっています。

17. firewalldの設定

CentOS7ではfirewalldによりポートが制限されています。
現状を「firewall-cmd –list-all」で確認します。

[root@adserver samba-4.10.2]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources:
  services: ssh dhcpv6-client
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@adserver samba-4.10.2]#

開けるべきポートのテンプレートがあらかじめ用意されているので「firewall-cmd –get-services」を実行して確認します 。

[root@adserver samba-4.10.2]# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry docker-swarm dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls managesieve mdns minidlna mongodb mosh mountd ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
[root@adserver samba-4.10.2]#
サービス ポート プロトコル firewalld定義
DNS 53 tcp/udp dns
Kerberos 88 tcp/udp kerberos,freeipa-ldap,freeipa-ldaps
End Point Mapper (DCE/RPC Locator Service) 135 tcp freeipa-trust
NetBIOS Name Service 137 udp samba,samba-client
NetBIOS Datagram 138 udp samba,samba-client,freeipa-trust
NetBIOS Session 139 tcp samba,freeipa-trust
LDAP 389 tcp/udp freeipa-trust(ldap,freeipa-ldapはtcpのみ)
SMB over TCP 445 tcp samba,freeipa-trust(freeipa-trustはudpも含む)
Kerberos kpasswd 464 tcp/udp kpasswd,freeipa-ldap,freeipa-ldaps
LDAPS 636 tcp ldaps,freeipa-ldaps
Dynamic RPC Ports(4.7以前) 1024-1300 tcp freeipa-trust
Dynamic RPC Ports(samba 4.7以降) 49152-65535 tcp ?
Global Catalog 3268 tcp freeipa-trust
Global Catalog SSL 3269 tcp なし

・firewalldの定義「samba」「dns」「freeipa-ldaps」「freeipa-trust」を使用
・「Dynamic RPC Ports(samba 4.7以降):49152-65535」を追加するか、smb.confで「rpc server port」を定義するか。
・「Global Catalog SSL:3269」を追加

[root@adserver samba-4.10.2]# firewall-cmd --permanent --zone=public --add-service=samba
success
[root@adserver samba-4.10.2]# firewall-cmd --permanent --zone=public --add-service=dns
success
[root@adserver samba-4.10.2]# firewall-cmd --permanent --zone=public --add-service=freeipa-ldaps
success
[root@adserver samba-4.10.2# firewall-cmd --permanent --zone=public --add-service=freeipa-trust
success
[root@adserver samba-4.10.2]# firewall-cmd --reload
success
[root@adserver samba-4.10.2]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.10.2#
[root@adserver samba-4.10.2]# firewall-cmd --permanent --zone=public --add-port=49152-65535/tcp
success
[root@adserver samba-4.10.2]# firewall-cmd --permanent --zone=public --add-port=3269/tcp
success
[root@adserver samba-4.10.2]# firewall-cmd --reload
success
[root@adserver samba-4.10.2]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports: 49152-65535/tcp 3269/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.10.2]#

18. systemdへの登録

systemdへの登録については「Managing the Samba AD DC Service Using Systemd」を参照のこと
CentOS6の場合は「Managing the Samba AD DC Service Using an Init Script

以上で設定は終了です。

Samba 4.9.xでActive Directoryを1から立てる

samba 4.10.2にアップデートした際にpython3関連で変更があったため「Samba 4.10.xでActive Directoryを1から立てる」という記事で内容を若干更新しています。


Samba 4.9.4に更新した際に、いろいろ修正点があったので更新。なお、この記事は、Active Directoryサーバとして使用することについてのみ解説しています。ファイルサーバとして使用することについては記述していません。

なお、過去バージョンの履歴。2018年3月版「Samba 4.7.xでActive Directoryを1から立てる」、2016年7月版「Samba 4.4.xでActive Directoryを1から立てる」、2014年2月版「Samba 4.xでActive Directoryを1から立てる

さて、Linux上でSambaを使ってActive Directoryサーバを立てるメリットは以下の点です。

その1:Windows Serverを買わなくてもActive Directoryを作れる

WindowsのCALを買わずにActive Directory環境の構築ができるため、ライセンス費用の低減になります。

その2:Active Directoryユーザの作成などのユーザ管理をWindowsマシンからWindows標準ツールで行える

ユーザーの作成/変更、コンピューターアカウントの作成、DNSの管理など、Active Directoryの管理を行う際に頻繁に使う操作については、WindowsのActive Directory管理ツールやDNS管理ツールを使用することができる。このため、普段はLinuxのCLIコマンド(samba-toolsやnetコマンドなど)を使う必要はない。

Active Directoryに参加しているWindowsマシンに、Windows機能のActive Directory管理ツールを追加インストールし、Active Directoryの管理者にてログオンすることで、管理ができる。

その3:sambaの設定は難しくない

10年ぐらい前のsambaでは、DNSサーバやLDAPサーバをsambaとは別に用意し、連携する必要がありました。いまのsambaはDNSサーバとLDAPサーバの機能が統合されているため設定が容易になりました。

Active Directory名とActive Directory上の役割、管理者パスワードを設定するぐらいで環境を作成することができます。

逆にデメリットとしてどのようなものがあるか?

その1:Active Directoryの全機能が搭載されていない

ドメイン/フォレストの機能レベルがWindows Server 2012R2レベルまで対応になったものの、「Kerberos関連機能が未搭載」となっています。(samba公式wiki「Raising the Functional Levels」)

「Windows Server 2008 R2」レベルまでであればフルサポートしています。このレベルであれば、Windows Server 2016環境でフェイルオーバークラスターマネージャーでクラスタを組むこともできました。(samba 4.7ぐらいから可能になった)


手順は、公式の「Setting up Samba as an Active Directory Domain Controller」と「Package Dependencies Required to Build Samba」を参照しながら実施していきます。

  1. CentOS7の最小インストールを実施

2. /etc/hostsの修正

自ホスト名を/etc/hostsに追加。
追加の際は、ショートのホスト名と、ドメイン付きのFQDNの両方を列挙すること。

[root@adserver ~]# cat /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
::1         localhost localhost.localdomain localhost6 localhost6.localdomain6
172.17.44.40    adserver adserver.adosakana.local
[root@adserver ~]#

3. 好みに応じて使うツールをインストール

セッションが途中で切れても良い様に「screen」か「tmux」と、ファイルダウンロードするためにwgetかcurlをインストールします。

[root@adserver ~]# yum install wget screen
<略>
[root@adserver ~]#

4. 必要なパッケージをインストール

Samba公式の「Package Dependencies Required to Build Samba」に記載されているパッケージをインストール

[root@adserver ~]# yum install attr bind-utils docbook-style-xsl gcc gdb krb5-workstation \
       libsemanage-python libxslt perl perl-ExtUtils-MakeMaker \
       perl-Parse-Yapp perl-Test-Base pkgconfig policycoreutils-python \
       python2-crypto gnutls-devel libattr-devel keyutils-libs-devel \
       libacl-devel libaio-devel libblkid-devel libxml2-devel openldap-devel \
       pam-devel popt-devel python-devel readline-devel zlib-devel systemd-devel \
       lmdb-devel jansson-devel gpgme-devel pygpgme libarchive-devel
<略>
[root@adserver ~]#

ここで問題発生・・・上記の説明に「RHEL7ではEPELレポジトリを追加する必要があるが、CentOS7とScientific Linux7では不要」とあるが、CentOS7環境で試してみると「perl-Test-Base」と「lmdb-devel」は無い。

ちなみにこの状態でsamab 4.9.xのconfigureを実行すると「Samba AD DC and –enable-selftest requires lmdb 0.9.16 or later」と言われて失敗します。

EPELレポジトリを追加してから、必要なパッケージのインストールをやり直します。(なお、perl-Test-Baseに関連付いていろいろパッケージが追加されます。)

[root@adserver ~]# yum install epel-release.noarch
<略>
[root@adserver ~]#

5. sambaのtar.gzをダウンロード

samba.orgからsambaをダウンロードします。

[root@adserver ~]# wget https://download.samba.org/pub/samba/stable/samba-4.9.4.tar.gz
--2018-12-28 13:10:22--  https://download.samba.org/pub/samba/stable/samba-4.9.4.tar.gz
download.samba.org (download.samba.org) をDNSに問いあわせています... 144.76.82.156, 2a01:4f8:192:486::443:2
download.samba.org (download.samba.org)|144.76.82.156|:443 に接続しています...  接続しました。
HTTP による接続要求を送信しました、応答を待っています... 200 OK
長さ: 18053738 (17M) [application/gzip]
`samba-4.9.4.tar.gz' に保存中

100%[======================================>] 18,053,738  3.65MB/s 時間 5.9s

2018-12-28 13:10:29 (2.93 MB/s) - `samba-4.9.4.tar.gz' へ保存完了 [18053738/18053738]

[root@adserver ~]# 

6. configure実施

[root@adserver ~]# tar xfz samba-4.9.4.tar.gz
[root@adserver ~]# cd samba-4.9.4/
[root@adserver samba-4.9.4]#  ./configure
Checking for program gcc or cc           : /usr/bin/gcc
Checking for program cpp                 : /usr/bin/cpp
Checking for program ar                  : /usr/bin/ar
Checking for program ranlib              : /usr/bin/ranlib
<略>
Checking if compiler accepts -fstack-protector                                                  : no
Checking if compiler accepts -fstack-clash-protection                                           : yes
'configure' finished successfully (1m24.346s)
[root@adserver samba-4.9.4]#

7. make & make install

[root@adserver samba-4.9.4]# make
WAF_MAKE=1 python ./buildtools/bin/waf build
Waf: Entering directory `/root/samba-4.9.4/bin'
<略>
Note: Writing nmblookup4.1
[4039/4039] Generating man/samba-gpupdate.8
Note: Writing samba-gpupdate.8
Waf: Leaving directory `/root/samba-4.9.4/bin'
'build' finished successfully (15m49.153s)
[root@adserver samba-4.9.4]# make install
WAF_MAKE=1 python ./buildtools/bin/waf install
Waf: Entering directory `/root/samba-4.9.4/bin'
        Selected embedded Heimdal build
Checking project rules ...
<略>
* installing bin/default/pidl/Parse::Pidl::Wireshark::NDR.3pm as /usr/local/samba/share/man/man3/Parse::Pidl::Wireshark::NDR.3pm
Waf: Leaving directory `/root/samba-4.9.4/bin'
'install' finished successfully (3m38.208s)
[root@adserver samba-4.9.4]#

8. インストール完了確認

インストールされたsambaのバージョンを確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/sbin/samba -V
Version 4.9.4
[root@adserver samba-4.9.4]#

9. Active Directoryのセットアップ

ドメイン「adosakana.local」を作成します。
また、sambaの機能を使ってAD DNSを構築するので「SAMBA_INTERNAL」を選択します。

なお、「–use-rfc2307」はADにNIS連携機能を追加するオプションです。AD上にUnix用のUID/GID/shell情報なども格納できるようにします。Samba環境では有効にしておくべきものです。

また、セットアップ中、「Merge the contents of this file with your system krb5.conf or replace it with this one. Do not create a symlink!」とメッセージが出ますが、これは、この手順で自動生成されたkrb5.confをシステムのもつkrb5.confと統合しろ、というお知らせです。後の手順で対処します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool domain provision --use-rfc2307 --interactive
Realm [example.com]:  ADOSAKANA.LOCAL
Domain [ADOSAKANA]:
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) [172.30.50.100]:  172.30.50.100
Administrator password:
Retype password:
Looking up IPv4 addresses
Looking up IPv6 addresses
No IPv6 address will be assigned
Setting up share.ldb
Setting up secrets.ldb
Setting up the registry
Setting up the privileges database
Setting up idmap db
Setting up SAM db
Setting up sam.ldb partitions and settings
Setting up sam.ldb rootDSE
Pre-loading the Samba 4 and AD schema
Unable to determine the DomainSID, can not enforce uniqueness constraint on local domainSIDs

Adding DomainDN: DC=adosakana,DC=local
Adding configuration container
Setting up sam.ldb schema
Setting up sam.ldb configuration data
Setting up display specifiers
Modifying display specifiers and extended rights
Adding users container
Modifying users container
Adding computers container
Modifying computers container
Setting up sam.ldb data
Setting up well known security principals
Setting up sam.ldb users and groups
Setting up self join
Adding DNS accounts
Creating CN=MicrosoftDNS,CN=System,DC=adosakana,DC=local
Creating DomainDnsZones and ForestDnsZones partitions
Populating DomainDnsZones and ForestDnsZones partitions
Setting up sam.ldb rootDSE marking as synchronized
Fixing provision GUIDs
A Kerberos configuration suitable for Samba AD has been generated at /usr/local/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:              wk70
NetBIOS Domain:        ADOSAKANA
DNS Domain:            adosakana.local
DOMAIN SID:            S-1-5-21-3471449246-245784766-327389652
[root@adserver samba-4.9.4]#

10. sambaを起動

sambaが起動していないことを確認した上で、sambaを起動します。

[root@adserver samba-4.9.4]# ps -ef|grep samba
root      45678  17315  0 14:16 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.9.4]# /usr/local/samba/sbin/samba
[root@adserver samba-4.9.4]# ps -ef|grep samba
root      45684      1 18 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45686  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45687  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45688  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45689  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45690  45684 36 14:16 ?        00:00:01 /usr/local/samba/sbin/samba
root      45691  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45692  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45693  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45694  45686  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45695  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45696  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45697  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45698  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45699  45684  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45700  45694  9 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45701  45695  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45702  45701  9 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45705  45698  0 14:16 ?        00:00:00 /usr/local/samba/sbin/samba
root      45706  45705 22 14:16 ?        00:00:00 python /usr/local/samba/sbin/samba_dnsupdate
root      45716  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45717  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45718  45702  1 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45719  45702  2 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45721  45702  0 14:16 ?        00:00:00 /usr/local/samba/sbin/winbindd -D --option=server role check:inhibit=yes --foreground
root      45722  45700  0 14:16 ?        00:00:00 /usr/local/samba/sbin/smbd -D --option=server role check:inhibit=yes --foreground
root      45724  17315  0 14:16 pts/0    00:00:00 grep --color=auto samba
[root@adserver samba-4.9.4]#

11. 動作確認

CentOS内部からSMB接続を行うテストを実施。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient --version
Version 4.9.4
[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient -L localhost -U%

        Sharename       Type      Comment
        ---------       ----      -------
        netlogon        Disk
        sysvol          Disk
        IPC$            IPC       IPC Service (Samba 4.9.4)
Reconnecting with SMB1 for workgroup listing.

        Server               Comment
        ---------            -------

        Workgroup            Master
        ---------            -------
[root@adserver samba-4.9.4]#

以前は「Domain=[ADOSAKANA.LOCAL] OS=[Unix] Server=[Samba x.y.z]」という出力もあったのですが、Samba 4.7以降では無くなっています。

netlogon共有にAdministrator権限でアクセスできるか確認。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/smbclient //localhost/netlogon -UAdministrator -c 'ls'
Enter ADOSAKANA\Administrator's password:
  .                                   D        0  Fri Dec 28 14:13:09 2018
  ..                                  D        0  Fri Dec 28 14:13:15 2018

                36936068 blocks of size 1024. 33797580 blocks available
[root@adserver samba-4.9.4]#

12. AD DNSの動作テスト

AD DNSが想定通りに動作しているかテストします。

まず、どんなzoneが登録されているのか確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool dns zonelist 127.0.0.1 -U Administrator
Password for [ADOSAKANA\Administrator]:
  2 zone(s) found

  pszZoneName                 : adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_DOMAIN_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : DomainDnsZones.adosakana.local

  pszZoneName                 : _msdcs.adosakana.local
  Flags                       : DNS_RPC_ZONE_DSINTEGRATED DNS_RPC_ZONE_UPDATE_SECURE
  ZoneType                    : DNS_ZONE_TYPE_PRIMARY
  Version                     : 50
  dwDpFlags                   : DNS_DP_AUTOCREATED DNS_DP_FOREST_DEFAULT DNS_DP_ENLISTED
  pszDpFqdn                   : ForestDnsZones.adosakana.local
[root@adserver samba-4.9.4]#

Active Directoryで使用するDNSのSRVレコードが登録されているかをhostコマンドを使って確認します。

[root@adserver samba-4.9.4]# host -t SRV _ldap._tcp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_ldap._tcp.adosakana.local has SRV record 0 100 389 adserver.adosakana.local.
[root@adserver samba-4.9.4]# host -t SRV _kerberos._udp.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

_kerberos._udp.adosakana.local has SRV record 0 100 88 adserver.adosakana.local.
[root@adserver samba-4.9.4]#

ADサーバのホスト名が登録されているか確認します。

[root@adserver samba-4.9.4]# host -t A adserver.adosakana.local 127.0.0.1
Using domain server:
Name: 127.0.0.1
Address: 127.0.0.1#53
Aliases:

adserver.adosakana.local has address 172.17.15.70
[root@adserver samba-4.9.4]#

13. DNSサーバの変更

ADサーバの/etc/resolv.confを、ADサーバ自身を使う様に書き換えます。

14. /etc/krb5.conf の変更

/usr/local/samba/private/krb5.conf に元となるものが自動生成されているので、それを使用する。

[root@adserver samba-4.9.4]# ls -l /etc/krb5.conf /usr/local/samba/private/krb5.conf
-rw-r--r--. 1 root root 641 10月 30 23:40 /etc/krb5.conf
-rw-rw-rw-. 1 root root  96 12月 28 14:13 /usr/local/samba/private/krb5.conf
[root@adserver samba-4.9.4]# cat /usr/local/samba/private/krb5.conf
[libdefaults]
        default_realm = ADOSAKANA.LOCAL
        dns_lookup_realm = false
        dns_lookup_kdc = true
[root@adserver samba-4.9.4]# cp /usr/local/samba/private/krb5.conf /etc/krb5.conf
cp: `/etc/krb5.conf' を上書きしますか? y
[root@adserver samba-4.9.4]#

15. Kerberosの動作確認

「kinit administrator@ドメイン名」を実行して確認します。

[root@adserver samba-4.9.4]# kinit administrator@ADOSAKANA.LOCAL
Password for administrator@ADOSAKANA.LOCAL:
Warning: Your password will expire in 41 days on 2019年02月08日 14時13分15秒
[root@adserver samba-4.9.4]#

正常に設定されていれば、上記の様にAdministratorユーザのパスワード有効期限が表示されます。

「klist」コマンドでも確認することが出来ます。

[root@adserver samba-4.9.4]# klist
Ticket cache: FILE:/tmp/krb5cc_0
Default principal: administrator@ADOSAKANA.LOCAL

Valid starting       Expires              Service principal
2018-12-28T14:26:25  2018-12-29T00:26:25  krbtgt/ADOSAKANA.LOCAL@ADOSAKANA.LOCAL
        renew until 2018-12-29T14:26:22
[root@adserver samba-4.9.4]#

なお、ドメイン名指定の大文字/小文字を間違えると下記の様なエラーとなります。

[root@adserver ~]# kinit administrator@adosakana.local
Password for administrator@adosakana.local:
kinit: KDC reply did not match expectations while getting initial credentials
[root@adserver ~]#

DNSサーバ指定が誤っている場合は下記の様なエラーです。

[root@adserver ~]# kinit administrator@ADOSAKANA.LOCAL
kinit: Cannot resolve servers for KDC in realm "ADOSAKANA.LOCAL" while getting initial credentials
[root@adserver ~]#

16. フォレストとドメインの機能レベル確認

作成したActive Directoryのドメインの機能レベルとフォレストの機能レベルを確認します。

[root@adserver samba-4.9.4]# /usr/local/samba/bin/samba-tool domain level show
Domain and forest function level for domain 'DC=adosakana,DC=local'

Forest function level: (Windows) 2008 R2
Domain function level: (Windows) 2008 R2
Lowest function level of a DC: (Windows) 2008 R2
[root@adserver samba-4.9.4]#

Samba 4.9.4でもWindows Server 2008R2が標準設定となっています。

17. firewalldの設定

CentOS7ではfirewalldによりポートが制限されています。
現状を「firewall-cmd –list-all」で確認します。

[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: ens160
  sources:
  services: ssh dhcpv6-client
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:
[root@adserver samba-4.9.4]#

開けるべきポートのテンプレートがあらかじめ用意されているので「firewall-cmd –get-services」を実行して確認します 。

[root@adserver samba-4.9.4]# firewall-cmd --get-services
RH-Satellite-6 amanda-client amanda-k5-client bacula bacula-client bgp bitcoin bitcoin-rpc bitcoin-testnet bitcoin-testnet-rpc ceph ceph-mon cfengine condor-collector ctdb dhcp dhcpv6 dhcpv6-client dns docker-registry docker-swarm dropbox-lansync elasticsearch freeipa-ldap freeipa-ldaps freeipa-replication freeipa-trust ftp ganglia-client ganglia-master git gre high-availability http https imap imaps ipp ipp-client ipsec irc ircs iscsi-target jenkins kadmin kerberos kibana klogin kpasswd kprop kshell ldap ldaps libvirt libvirt-tls managesieve mdns minidlna mongodb mosh mountd ms-wbt mssql murmur mysql nfs nfs3 nmea-0183 nrpe ntp openvpn ovirt-imageio ovirt-storageconsole ovirt-vmconsole pmcd pmproxy pmwebapi pmwebapis pop3 pop3s postgresql privoxy proxy-dhcp ptp pulseaudio puppetmaster quassel radius redis rpc-bind rsh rsyncd samba samba-client sane sip sips smtp smtp-submission smtps snmp snmptrap spideroak-lansync squid ssh syncthing syncthing-gui synergy syslog syslog-tls telnet tftp tftp-client tinc tor-socks transmission-client upnp-client vdsm vnc-server wbem-https xmpp-bosh xmpp-client xmpp-local xmpp-server zabbix-agent zabbix-server
[root@adserver samba-4.9.4]#
サービス ポート プロトコル firewalld定義
DNS 53 tcp/udp dns
Kerberos 88 tcp/udp kerberos,freeipa-ldap,freeipa-ldaps
End Point Mapper (DCE/RPC Locator Service) 135 tcp freeipa-trust
NetBIOS Name Service 137 udp samba,samba-client
NetBIOS Datagram 138 udp samba,samba-client,freeipa-trust
NetBIOS Session 139 tcp samba,freeipa-trust
LDAP 389 tcp/udp freeipa-trust(ldap,freeipa-ldapはtcpのみ)
SMB over TCP 445 tcp samba,freeipa-trust(freeipa-trustはudpも含む)
Kerberos kpasswd 464 tcp/udp kpasswd,freeipa-ldap,freeipa-ldaps
LDAPS 636 tcp ldaps,freeipa-ldaps
Dynamic RPC Ports(4.7以前) 1024-1300 tcp freeipa-trust
Dynamic RPC Ports(samba 4.7以降) 49152-65535 tcp ?
Global Catalog 3268 tcp freeipa-trust
Global Catalog SSL 3269 tcp なし

・firewalldの定義「samba」「dns」「freeipa-ldaps」「freeipa-trust」を使用
・「Dynamic RPC Ports(samba 4.7以降):49152-65535」を追加するか、smb.confで「rpc server port」を定義するか。
・「Global Catalog SSL:3269」を追加

[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=samba
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=dns
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=freeipa-ldaps
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-service=freeipa-trust
success
[root@adserver samba-4.9.4]# firewall-cmd --reload
success
[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports:
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.9.4]#
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-port=49152-65535/tcp
success
[root@adserver samba-4.9.4]# firewall-cmd --permanent --zone=public --add-port=3269/tcp
success
[root@adserver samba-4.9.4]# firewall-cmd --reload
success
[root@adserver samba-4.9.4]# firewall-cmd --list-all
public (active)
  target: default
  icmp-block-inversion: no
  interfaces: eth0
  sources:
  services: ssh dhcpv6-client samba dns freeipa-ldaps freeipa-trust
  ports: 49152-65535/tcp 3269/tcp
  protocols:
  masquerade: no
  forward-ports:
  source-ports:
  icmp-blocks:
  rich rules:

[root@adserver samba-4.9.4]#

18. systemdへの登録

systemdへの登録については「Managing the Samba AD DC Service Using Systemd」を参照のこと
CentOS6の場合は「Managing the Samba AD DC Service Using an Init Script

以上で設定は終了です。