CentOS7 へ Samba4 をインストールし、AD 環境を構築する
CentOS7 へ Samba4 をインストールし、Active Directory の Domain Controller として構築する手順をメモしておきます。
パッケージのインストール
最初に EPEL から必要なパッケージを追加しておきます。
| yum -y install epel-release
yum -y install authconfig krb5-workstation
|
CentOS 標準リポジトリにある Samba パッケージは古い為、有志の方が公開している「wing-net.ddo.jp」というリポジトリから Samba をインストールします。
| cd /etc/yum.repos.d/
curl http://wing-net.ddo.jp/wing/7/EL7.wing.repo -o /etc/yum.repos.d/EL7.wing.repo
sed -i 's@enabled=0@enabled=1@g' /etc/yum.repos.d/EL7.wing.repo
yum -y install samba-dc samba-client samba-winbind samba-winbind-clients
|
設定ファイルの作成
デフォルトで存在している設定ファイルは削除し、samba-tool という対話的ツールを使って設定を行います。
| rm -rf /etc/krb5.conf /etc/samba/smb.conf
samba-tool domain provision --use-rfc2307 --interactive
|
設定例は以下の通りです。
| # samba-tool domain provision --use-rfc2307 --interactive
Realm [US-EAST-2.COMPUTE.AMAZONAWS.COM]: EXAMPLE.COM
Domain [EXAPMLE]: EXAMPLE
Server Role (dc, member, standalone) [dc]: dc
DNS backend (SAMBA_INTERNAL, BIND9_FLATFILE, BIND9_DLZ, NONE) [SAMBA_INTERNAL]: SAMBA_INTERNAL
DNS forwarder IP address (write 'none' to disable forwarding) [10.0.0.2]: 8.8.8.8
Administrator password: PASSWORD
Retype password: PASSWORD
|
自動起動用のスクリプトを用意する
/etc/systemd/system/samba.service に自動起動用のスクリプトを用意しておきます。
1
2
3
4
5
6
7
8
9
10
11
12
13
14 | cat << EOF > /etc/systemd/system/samba.service
[Unit]
Description= Samba4 Active Directory
After=syslog.target
After=network.target
[Service]
Type=forking
PIDFile=/var/run/samba.pid
ExecStart=/usr/sbin/samba
[Install]
WantedBy=multi-user.target
EOF
|
/etc/krb5.conf には Kerberos5 用の設定ファイルを用意しておきます。 ドメイン名等は環境に合わせて適宜、変更します。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 | cat << EOF > /etc/krb5.conf
[libdefaults]
default_realm = EXAMPLE.COM
dns_lookup_realm = false
dns_lookup_kdc = true
[realms]
EXAMPLE.COM = {
kdc = ds.example.com
admin_server = ds.example.com
}
[domain_realm]
.example.com = EXAMPLE.COM
example.com = EXAMPLE.COM
EOF
|
ここまでの設定が完了したら Samba を起動します。 合わせて自動起動の設定も実施しておきます。
| systemctl enable samba
systemctl start samba
|
認証のテスト
Samba が起動したら初期作成されている administrator ユーザで認証出来るか、テストしてみます。
| kinit administrator@EXAMPLE.COM
|
セキュリティエラーが出た場合
New Default for LDAP Connections Requires Strong Authentication に以下と書かれていますが、あるバージョンから Samba はデフォルトで(LDAP では無く)LDAPS を期待するように変更されています。
The security updates 4.4.1, 4.3.7 and 4.2.10 introduced a new smb.conf option for the Active Directory (AD) LDAP server to enforce strong authentication. The default for this new option ldap server require strong auth is yes and allows only simple binds over TLS encrypted connections. In consequence, external applications that connect to AD using LDAP, cannot establish a connection if they do not use or support TLS encrypted connections.
アプリケーション側がどうしても実装変更出来ず、(LDAPS では無く)LDAP での接続を許可するには /etc/samba/smb.conf の global セクションへ以下のように追記し、デーモンを再起動します。
| [global]
client ldap sasl wrapiping = plain
ldap server require strong auth = no
|