はじめに
ldap環境を構築したい。widowsならActiveDirectory、LinuxならOpenLDAP。そう思っていた時期がありました。しかし、今回はOpenDJです。OpenLDAP以外にもあるのです。妻は「オープンなDJ?(yo!yo!」と言ってますが、そうではない。ちゃんとしたLDAPサーバです。
なぜOpenDJ?
OpenAMの検証をしたかったので、その流れで構築したことがきっかけです。chatGPTに聞いた結果、おすすめされ、OpenAM用で推奨ならそうしょうかなーというノリで構築を試みることになりました。
Q: OpenLDAPとOpenDJは何が違いますか A: OpenLDAP と OpenDJ はどちらも LDAP サーバー ですが、用途や設計に違いがあります。 本番環境で OpenAM のバックエンドとして使うなら、OpenDJ が推奨 されます。
結果的にOpenAMの検証は失敗続きで、正直記事にできるものなんてなくて、ふと「何のためにわざわざOpenDJ構築したんだろ」と思うようになってしまいました。せっかくなので構築した記録を載せたいと思います。
コマンドとコマンドの実行結果を載せています(所々コマンドのみ)。参考になれば幸いです。
構築環境
簡単に環境を記載。SELinuxやfirewalldは無効にしておきます(検証時はだいたいそうする)。また、ドメインは「lab.ricecake24book.com」にしています。(本サイトも同じドメインで運営しています)
[root@opendj01 ~]# getenforce
Disabled
[root@opendj01 ~]# systemctl status firewalld.service
○ firewalld.service - firewalld - dynamic firewall daemon
Loaded: loaded (/usr/lib/systemd/system/firewalld.service; disabled; preset: enabled)
Active: inactive (dead)
Docs: man:firewalld(1)
[root@opendj01 ~]# uname -a
Linux opendj01 5.14.0-503.22.1.el9_5.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Jan 24 03:55:12 EST 2025 x86_64 x86_64 x86_64 GNU/Linux
[root@opendj01 ~]# nslookup opendj01.lab.ricecake24book.com
Server: 172.16.1.31
Address: 172.16.1.31#53
Name: opendj01.lab.ricecake24book.com
Address: 172.16.1.32
DNSで名前解決できるのであればhostsは不要ですが、念のため書いておきます。
インストール
dnfコマンドでjavaをインストールします。
dnf install -y java-11-openjdk wget unzip
インストール完了後、バージョン確認。
java -version
以下は実行結果。
[root@opendj01 ~]# java -version
openjdk version "11.0.25" 2024-10-15 LTS
OpenJDK Runtime Environment (Red_Hat-11.0.25.0.9-1) (build 11.0.25+9-LTS)
OpenJDK 64-Bit Server VM (Red_Hat-11.0.25.0.9-1) (build 11.0.25+9-LTS, mixed mode, sharing)
javaのパスを通します。
ll /usr/lib/jvm/java-11-openjdk-11.0.25.0.9-3.el9.x86_64/bin/java
cat <<EOF >> /etc/profile
export JAVA_HOME=/usr/lib/jvm/java-11-openjdk-11.0.25.0.9-3.el9.x86_64/bin/java
export PATH=$JAVA_HOME/bin:$PATH
export PATH=$PATH:/opt/opendj/bin
EOF
変更を有効化。
source /etc/profile
次にOpenDJ関連のファイルをダウンロードします。ダウンロード後、ファイルを解凍して、適切な権限を付与します。
wget https://github.com/OpenIdentityPlatform/OpenDJ/releases/download/4.4.11/opendj-4.4.11.zip
unzip opendj-4.4.11.zip
mv ./opendj /opt/opendj
chown -R root:root /opt/opendj
chmod -R 755 /opt/opendj
cd /opt/opendj
chmod +x /opt/opendj/setup
セットアップ
setupファイルを実行します。LISTENするポート番号やbaseBN等のオプションは構築したい環境に合わせて、適宜変更します。
/opt/opendj/setup \
--cli \
--rootUserDN "cn=Directory Manager" \
--rootUserPassword "orange1234!" \
--hostname opendj01 \
--ldapPort 1389 \
--adminConnectorPort 4444 \
--baseDN "dc=lab,dc=ricecake24book,dc=com" \
--addBaseEntry \
--acceptLicense
以下はsetup実行時のログです。選択肢は最低限のインストールとなります。
[root@opendj01 opendj]# /opt/opendj/setup \
--cli \
--rootUserDN "cn=Directory Manager" \
--rootUserPassword "orange1234!" \
--hostname opendj01 \
--ldapPort 1389 \
--adminConnectorPort 4444 \
--baseDN "dc=lab,dc=ricecake24book,dc=com" \
--addBaseEntry \
--acceptLicense
Provide the backend type:
1) JE Backend
2) PDB Backend
Enter choice [1]: 1
Do you want to enable SSL? (yes / no) [no]: no
Do you want to enable Start TLS? (yes / no) [no]: no
Do you want to start the server when the configuration is completed? (yes /
no) [yes]: yes
Setup Summary
=============
LDAP Listener Port: 1389
Administration Connector Port: 4444
JMX Listener Port:
LDAP Secure Access: disabled
Root User DN: cn=Directory Manager
Directory Data: Backend Type: JE Backend
Create New Base DN dc=lab,dc=ricecake24book,dc=com
Base DN Data: Only Create Base Entry (dc=lab,dc=ricecake24book,dc=com)
Start Server when the configuration is completed
What would you like to do?
1) Set up the server with the parameters above
2) Provide the setup parameters again
3) Print equivalent non-interactive command-line
4) Cancel and exit
Enter choice [1]: 1
Configuring Directory Server ..... Done.
Creating Base Entry dc=lab,dc=ricecake24book,dc=com .....
Error Creating Base Entry.
See /tmp/opendj-setup-8014265261478578222.log for a detailed log of the failed
operation.
Please report this error and provide the log file mentioned above.
To see basic server configuration status and configuration, you can launch
/opt/opendj/bin/status
エラー発生したので、別途BaseDNを設定します。
以下のコマンドでLDAPサービスをスタートさせます。
/opt/opendj/bin/start-ds
baseDNを登録します。
/opt/opendj/bin/ldapmodify \
--hostname opendj01.lab.ricecake24book.com \
--port 1389 \
--bindDN "cn=Directory Manager" \
--bindPassword "orange1234!" <<EOF
dn: dc=lab,dc=ricecake24book,dc=com
objectClass: top
objectClass: domain
dc: lab
EOF
以下は実行ログです。「successful」が出力されています。
[root@opendj01 opendj]# /opt/opendj/bin/ldapmodify \
--hostname opendj01.lab.ricecake24book.com \
--port 1389 \
--bindDN "cn=Directory Manager" \
--bindPassword "orange1234!" <<EOF
dn: dc=lab,dc=ricecake24book,dc=com
objectClass: top
objectClass: domain
dc: lab
EOF
Processing ADD request for dc=lab,dc=ricecake24book,dc=com
ADD operation successful for DN dc=lab,dc=ricecake24book,dc=com
ldapsearchでOpenDJを検索します。以下のコマンドは一例です。
/opt/opendj/bin/ldapsearch \
--hostname opendj01.lab.ricecake24book.com \
--port 1389 \
--bindDN "cn=Directory Manager" \
--bindPassword "orange1234!" \
--baseDN "dc=lab,dc=ricecake24book,dc=com" \
"(objectClass=*)"
以下は実行結果。
[root@opendj01 opendj]# /opt/opendj/bin/ldapsearch \
--hostname opendj01.lab.ricecake24book.com \
--port 1389 \
--bindDN "cn=Directory Manager" \
--bindPassword "orange1234!" \
--baseDN "dc=lab,dc=ricecake24book,dc=com" \
"(objectClass=*)"
dn: dc=lab,dc=ricecake24book,dc=com
dc: lab
objectClass: domain
objectClass: top
LDAP(1389番)への接続は成功していますね。
ステータス確認
以下のコマンドで確認できます。
/opt/opendj/bin/status
以下は実行結果です。
[root@opendj01 opendj]# /opt/opendj/bin/status
>>>> Specify OpenDJ LDAP connection parameters
Administrator user bind DN [cn=Directory Manager]:
Password for user 'cn=Directory Manager':
--- Server Status ---
Server Run Status: Started
Open Connections: 1
--- Server Details ---
Host Name: opendj01.lab.ricecake24book.com
Administrative Users: cn=Directory Manager
Installation Path: /opt/opendj
Version: OpenDJ Server 4.4.11
Java Version: 11.0.25
Administration Connector: Port 4444 (LDAPS)
--- Connection Handlers ---
Address:Port : Protocol : State
-------------:----------:---------
-- : LDIF : Disabled
0.0.0.0:636 : LDAPS : Disabled
0.0.0.0:1389 : LDAP : Enabled
0.0.0.0:1689 : JMX : Disabled
0.0.0.0:8080 : HTTP : Disabled
--- Data Sources ---
Base DN: dc=lab,dc=ricecake24book,dc=com
Backend ID: userRoot
Entries: 1
Replication:
ここまでは結構サクッと進めました。別でLDAPSを実現するまでの手順を紹介してますが、こちらの方がけっこうきつかったです。
参考にしたい方は、是非こちらもご確認いただければよろしいかと。

