サーバー側の設定が終わったので、次はopenldapで認証するクライアント(今回はnginx)側の設定を行ないます。

[root@nginx01 ~]# yum install authconfig openldap-clients nss-pam-ldapd openldap-devel

クライアント側で必要なモジュール、またnginxでldap認証を利用するために必要なモジュールをインストールします。

[root@nginx01 ~]# authconfig  --enableldap  --enableldapauth  --ldapserver="ldap://192.168.200.100/"  --ldapbasedn="dc=test,dc=local"  --enablemkhomedir  --update
[root@nginx01 ~]# chkconfig nslcd on


authconfigコマンドでldapサーバー、ドメイン名の指定を行ないます。
また、ldapクライアントデーモンのnslcdの自動起動をオンにします。

[root@nginx01 ~]# ssh user01@localhost
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is c6:59:b7:cc:d3:17:e4:d7:6f:a9:18:4f:bd:fd:42:5d.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
user01@localhost's password:
Creating directory '/home/user01'.
[user01@nginx01 ~]$ whoami
user01


早速、ldapユーザーでSSHにアクセス
正常にユーザー認証が行えることを確認しました。

[root@nginx01 nginx-1.9.12]# git clone https://github.com/kvspb/nginx-auth-ldap.git
Initialized empty Git repository in /tmp/src/nginx-1.9.12/nginx-auth-ldap/.git/
remote: Counting objects: 306, done.
remote: Total 306 (delta 0), reused 0 (delta 0), pack-reused 306
Receiving objects: 100% (306/306), 119.37 KiB, done.
Resolving deltas: 100% (165/165), done.


さらに、nginxのldap用プラグインをダウンロードします。

[root@nginx01 nginx-1.9.12]# ./configure --user=nginx --group=nginx --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-openssl=/tmp/openssl-1.0.2g --with-http_realip_module --add-module=nginx-auth-ldap


さらに、ldapモジュールを組み込んで、nginxをconfigureします。

[root@nginx01 nginx-1.9.12]# make && make install

nginxソースのコンパイル、インストールを行ないます。

[root@nginx01 nginx-1.9.12]# nginx -V
nginx version: nginx/1.9.12
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.2g  1 Mar 2016
TLS SNI support enabled
configure arguments: --user=nginx --group=nginx --prefix=/etc/nginx/ --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-log-path=/var/log/nginx/access.log --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --with-http_ssl_module --with-openssl=/tmp/openssl-1.0.2g --with-http_realip_module --add-module=nginx-auth-ldap


nginxの-Vコマンドでldapモジュールが組み込まれていることを確認します。