投げ銭

★当サイトへの投げ銭(PayPal)★

LINK


(無償、寄付歓迎) logo
世界中で使われるISO標準オフィスソフト(MSオフィス互換)

★LibreOfficeの導入事例★
詳細について

人気の投稿(1ヶ月間)

Ad

Ad

投げ銭

★当サイトへの投げ銭(PayPal)★

2022年7月11日月曜日

【Linux CentOS 7】OpenLDAP(2.5.12)をソースファイルからインストールする手順【OpenLDAP 2.5.12】

CentOS 7にOpenLDAP(2.5.12)をソースファイルからインストールする手順

ここでは、Dockerコンテナを用いている。
CentOS 7といくつかのソフトウェアが動作するコンテナをベースとして、そこにOpenLDAPを追加した。



■ 既存のDockerイメージから特権コンテナを動作させた

◯ 次のページの方法で既にベースとなるコンテナは作成済みである。



◯ 上記の方法で作成したイメージからコンテナを始動させた。

# docker run --privileged -d --net MYNETWORK --dns 192.168.1.1 --name ldap_justinstalled_centos7_priv image_centos7_basic_priv /sbin/init
[root@89192c461c39 /]#

(以下の設定を行うためには必須)
--privileged 特権でコンテナを動作させる
/sbin/init initを起動する。

(オプション)
--net MYNETWORK 指定したDockerネットワークを利用する。(リモート接続しないなら不要)
--dns 192.168.1.1 コンテナに利用させるリゾルバを指定する。(ホストのものを使うなら不要)



■ 予め必要なものとして新しいバージョンのOpenSSLをインストール

 CentOS7に標準リポジトリから入れられるopensslのバージョンは古いため、OpenLDAPの要件を満たさない。そのため、ソースから新しいバージョンのOpenSSLを導入する。


◯ 必要なパッケージをインストールした。

[root@89192c461c39 /]# yum install make gcc perl-core pcre-devel wget zlib-devel
Total download size: 55 M
Installed size: 126 M

◯ OpenSSL本体の導入作業

・OpenSSLのソースをダウンロードと展開

 適当な場所にOpenSSLディレクトリを作成しカレントディレクトリを移動した。

[root@89192c461c39 OpenSSL]# wget https://ftp.openssl.org/source/openssl-1.1.1q.tar.gz
[root@89192c461c39 OpenSSL]# tar zxvf openssl-1.1.1q.tar.gz


・OpenSSLのインストール

 展開済みのディレクトリにカレントディレクトリを移動してから、順にコマンドを実行していく。

[root@89192c461c39 OpenSSL]# cd openssl-1.1.1q
[root@89192c461c39 openssl-1.1.1q]# ./config
Operating system: x86_64-whatever-linux2
Configuring OpenSSL version 1.1.1q (0x1010111fL) for linux-x86_64
Using os-specific seed configuration
Creating configdata.pm
Creating Makefile

**********************************************************************
***                                                                ***
***   OpenSSL has been successfully configured                     ***
***                                                                ***
***   If you encounter a problem while building, please open an    ***
***   issue on GitHub <https://github.com/openssl/openssl/issues>  ***
***   and include the output from the following command:           ***
***                                                                ***
***       perl configdata.pm --dump                                ***
***                                                                ***
***   (If you are new to OpenSSL, you might want to consult the    ***
***   'Troubleshooting' section in the INSTALL file first)         ***
***                                                                ***
**********************************************************************

[root@89192c461c39 openssl-1.1.1q]# make
[root@89192c461c39 openssl-1.1.1q]# make test

 次の項目についてはskippedになっていたが、それ以外はすべてokだった。
../test/recipes/05-test_md2.t ...................... skipped: md2 is not supported by this OpenSSL build
../test/recipes/05-test_rc5.t ...................... skipped: rc5 is not supported by this OpenSSL build
../test/recipes/30-test_afalg.t .................... skipped: test_afalg not supported for this build
../test/recipes/90-test_gost.t ..................... skipped: No test GOST engine found
../test/recipes/90-test_overhead.t ................. skipped: Only supported in no-shared builds
../test/recipes/95-test_external_boringssl.t ....... skipped: No external tests in this configuration
../test/recipes/95-test_external_krb5.t ............ skipped: No external tests in this configuration
../test/recipes/95-test_external_pyca.t ............ skipped: No external tests in this configuration
All tests successful.
最後に次のように表示された。
Files=158, Tests=2641, 156 wallclock secs ( 3.23 usr  0.38 sys + 111.18 cusr 57.48 csys = 172.27 CPU)
Result: PASS
make[1]: Leaving directory `/root/Software/OpenSSL/openssl-1.1.1q'

[root@89192c461c39 openssl-1.1.1q]# make install


・リンクを張る(その1)

[root@89192c461c39 openssl-1.1.1q]# openssl version
openssl: error while loading shared libraries: libssl.so.1.1: cannot open shared object file: No such file or directory
[root@89192c461c39 openssl-1.1.1q]# ln -s /usr/local/lib64/libssl.so.1.1 /usr/lib64/


・リンクを張る(その2)

[root@89192c461c39 openssl-1.1.1q]# openssl version
openssl: error while loading shared libraries: libcrypto.so.1.1: cannot open shared object file: No such file or directory
[root@89192c461c39 openssl-1.1.1q]# ln -s /usr/local/lib64/libcrypto.so.1.1 /usr/lib64/


・バージョン確認

[root@89192c461c39 openssl-1.1.1q]# openssl version
OpenSSL 1.1.1q  5 Jul 2022



■ OpenLDAPのインストール

◯ 必要なパッケージをインストールした。

[root@89192c461c39 ~]# yum install gcc gcc-c++ libxml2 libxml2-devel openssl-devel ncurses-devel sqlite-devel newt-devel libuuid-devel uuid-devel make wget


◯ OpenSSL本体の導入作業

・OpenSSLのソースをダウンロードと展開

 適当な場所にOpenLDAPディレクトリを作成しカレントディレクトリを移動した。

[root@89192c461c39 OpenLDAP]# wget https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.5.12.tgz
Length: 6444482 (6.1M)
[root@89192c461c39 OpenLDAP]# tar zxvf openldap-2.5.12.tgz


・OpenSSLのインストール

 さらに必要になるパッケージを予めインストールした。

[root@89192c461c39 openldap-2.5.12]# yum install cyrus-sasl-devel gnutls-devel systemd-devel file

 展開済みのディレクトリにカレントディレクトリを移動してから、順にコマンドを実行していく。

[root@89192c461c39 OpenLDAP]# cd openldap-2.5.12
[root@89192c461c39 openldap-2.5.12]# ./configure --with-tls --enable-crypt --with-cyrus-sasl --enable-rwm
Making servers/slapd/backends.c
    Add config ...
    Add ldif ...
    Add monitor ...
    Add mdb ...
    Add relay ...
Making servers/slapd/overlays/statover.c
    Add rwm ...
    Add syncprov ...
Please run "make depend" to build dependencies

[root@89192c461c39 openldap-2.5.12]# make depend
[root@89192c461c39 openldap-2.5.12]# make
[root@89192c461c39 openldap-2.5.12]# make test

6コアマシンで15分くらいかかった。
(略)
0 tests for mdb were skipped.
make[2]: Leaving directory `/root/Software/OpenLDAP/openldap-2.5.12/tests'
make[2]: Entering directory `/root/Software/OpenLDAP/openldap-2.5.12/tests'
run configure with --enable-balancer to run the Load Balancer tests
make[2]: Leaving directory `/root/Software/OpenLDAP/openldap-2.5.12/tests'
make[1]: Leaving directory `/root/Software/OpenLDAP/openldap-2.5.12/tests'

[root@89192c461c39 openldap-2.5.12]# make install



■ OpenLDAPを自動起動できるように設定

 最初、次のような起動用スクリプトが存在していた。

[root@89192c461c39 openldap-2.5.12]# cat /lib/systemd/system/slapd.service
[Unit]
Description=OpenLDAP Server Daemon
After=syslog.target network-online.target
Documentation=man:slapd
Documentation=man:slapd-config
Documentation=man:slapd-mdb

[Service]
Type=notify
Environment="SLAPD_URLS=ldap:/// ldapi:///" "SLAPD_OPTIONS="
EnvironmentFile=/etc/sysconfig/slapd
ExecStart=/usr/local/libexec/slapd -d 0 -h ${SLAPD_URLS} $SLAPD_OPTIONS

[Install]
WantedBy=multi-user.target

 しかし、これを用いても次のようにうまくLDAPサーバーは動作しなかった。

[root@89192c461c39 ~]# systemctl status slapd             
Job for slapd.service failed because the control process exited with error code. See "systemctl status slapd.service" and "journalctl -xe" for details.
[root@89192c461c39 ~]# systemctl status slapd
● slapd.service - OpenLDAP Server Daemon
   Loaded: loaded (/usr/lib/systemd/system/slapd.service; disabled; vendor preset: disabled)
   Active: failed (Result: resources)
     Docs: man:slapd
           man:slapd-config
           man:slapd-mdb

Jun 30 08:30:19 89192c461c39 systemd[1]: Failed to load environment files: No such file or directory
Jun 30 08:30:19 89192c461c39 systemd[1]: slapd.service failed to run 'start' task: No such file or directory
Jun 30 08:30:19 89192c461c39 systemd[1]: Failed to start OpenLDAP Server Daemon.
Jun 30 08:30:19 89192c461c39 systemd[1]: Unit slapd.service entered failed state.
Jun 30 08:30:19 89192c461c39 systemd[1]: slapd.service failed.

◯  起動できるように設定

・次のようにリンクが張られていることを確認した。

[root@89192c461c39 ~]# ls /lib -al
lrwxrwxrwx 1 root root 7 Nov 13  2020 /lib -> usr/lib
 つまり、/libは、/usr/libディレクトリに繋がっている。
以下では、/libを指定してファイル操作を行う。


・念の為、オリジナルのバックアップを取った。

[root@89192c461c39 ~]# cp /lib/systemd/system/slapd.service /lib/systemd/system/slapd.service.org


・次のように編集した

[root@89192c461c39 ~]# vi /lib/systemd/system/slapd.service
[Unit]
Description=OpenLDAP Server
After=syslog.target network.target

[Service]
Type=forking
PIDFile=/usr/local/var/run/slapd.pid
ExecStart=/usr/local/libexec/slapd -h "ldap:/// ldapi:///"
ExecReload=/bin/kill -HUP $MAINPID
ExecStop=/bin/kill -TERM $MAINPID

[Install]
WantedBy=multi-user.target

[root@89192c461c39 ~]# systemctl daemon-reload


・起動を試行

 しかし、次のように起動が失敗した。

[root@89192c461c39 ~]# systemctl start slapd
Job for slapd.service failed because the control process exited with error code. See "systemctl status slapd.service" and "journalctl -xe" for details.

 失敗の原因を調べた。

[root@89192c461c39 ~]# systemctl status slapd
● slapd.service - OpenLDAP Server
   Loaded: loaded (/usr/lib/systemd/system/slapd.service; disabled; vendor preset: disabled)
   Active: failed (Result: exit-code) since Thu 2022-07-07 08:35:45 JST; 29min ago

Jul 07 08:35:45 89192c461c39 systemd[1]: Starting OpenLDAP Server...
Jul 07 08:35:45 89192c461c39 slapd[276]: @(#) $OpenLDAP: slapd 2.5.12 (Jul  6 2022 07:01:28) $
                                                 root@89192c461c39:/root/Software/OpenLDAP/openldap-2.5.12/servers/slapd
Jul 07 08:35:45 89192c461c39 slapd[276]: /usr/local/etc/openldap/slapd.conf: line 72: invalid path: No such file or directory
Jul 07 08:35:45 89192c461c39 slapd[276]: slapd stopped.
Jul 07 08:35:45 89192c461c39 slapd[276]: connections_destroy: nothing to destroy.
Jul 07 08:35:45 89192c461c39 systemd[1]: slapd.service: control process exited, code=exited status=1
Jul 07 08:35:45 89192c461c39 systemd[1]: Failed to start OpenLDAP Server.
Jul 07 08:35:45 89192c461c39 systemd[1]: Unit slapd.service entered failed state.
Jul 07 08:35:45 89192c461c39 systemd[1]: slapd.service failed.

 /usr/local/etc/openldap/slapd.confの72行目(directory       /usr/local/var/openldap-data)で指定されているパスにファイルが存在せず、起動が失敗しているとわかった。
まずは、初期設定を正しく行うことが必要であるとわかった。


◯ 初期設定については次のページに、引き続き記述することにする。

【Docker Linux CentOS 7】ソースから導入したOpenLDAP(2.5.12)の初期設定と、エントリに関する理解【OpenLDAP 2.5.12】




■ ここまで構築してきたコンテナのイメージを作成しておく

 いったんインストール作業としてはここで完了として、Dockerコンテナのコミットしイメージ化することにした。


・作業の続きに備えて、OpenLDAPについて自動起動試行しないように設定した。

[root@89192c461c39 ~]# systemctl disable slapd


◯ イメージの作成

・コンテナを終了した。

[root@89192c461c39 /]# poweroff


・コミットコマンドを実行してイメージを作成した。(Dockerホストにおいて)

# docker commit ldap_justinstalled_centos7_priv image_centos7_openldap-ver-2.5.12_202207XX_justinstalled
ldap_justinstalled_centos7_priv
…ターゲットのコンテナ名称
image_centos7_openldap-ver-2.5.12_202207XX_justinstalled…作成するイメージにつける名前

・イメージの確認

# docker image list
REPOSITORY                                                         TAG       IMAGE ID       CREATED         SIZE
image_centos7_openldap-ver-2.5.12_202207XX_justinstalled           latest    xxxxxxxxxxxx   3 seconds ago   1.42GB



<参考>

・デージーネット. 入門LDAP/OpenLDAPディレクトリサービス導入・運用ガイド第3版. 秀和システム, 2017, 430p.

・デーモン管理をdaemontoolsからsystemdに移行させる
< https://techblog.kayac.com/advent-calendar-2019-daemontools-systemd > 2022年7月7日

・How to configure systemd to kill and restart a daemon on reload?
< https://serverfault.com/questions/767360/how-to-configure-systemd-to-kill-and-restart-a-daemon-on-reload > 2022年7月7日

・Installing OpenLDAP from Source on CentOS 7
< https://tylersguides.com/guides/install-openldap-source-centos-7/ > 2022年7月7日

投げ銭

★当サイトへの投げ銭(PayPal)★

Ad

Ad