LoginSignup
1
0

More than 3 years have passed since last update.

CentOSでLDAPサーバの初期設定

Last updated at Posted at 2019-08-19

はじめに

LDAPサーバをインストールしベースDNとあらかじめ用意しておいたスキーマファイルを取り込んで起動するところまでを記載

OpenLDAP のインストール

面倒なので一切合切インストールしておく


# yum -y install openldap*

設定ツリーの管理

まず、設定ツリーにログインしないと始まらないので、設定ツリーの管理ユーザを設定する。

以下のLDIFファイルを用意。「パスワード」のところは適当なパスワードを設定する。

# cat add_config_rootdn_rootpw.ldif
dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootDN
olcRootDN: cn=config

dn: olcDatabase={0}config,cn=config
changetype: modify
add: olcRootPw
olcRootPW: パスワード

作成したLDIFファイルを以下のコマンドで実行して設定を更新する。

# ldapadd -Y EXTERNAL -H ldapi:// -f ./add_config_rootdn_rootpw.ldif

これで、「cn=config」の設定画面にログインができる。

自作したスキーマファイルの取り込み

自作したスキーマを取り込むには、まず「/etc/openldap/schema」ディレクトリにスキーマファイルを置く必要がある。
(どこでもいいのだけど、スキーマファイルを指定するときにデフォルトと同じところにしている)

そして、 slaptest コマンドを実行して LDIF 形式に変換して、そのファイルを OpenLDAP のスキーマファイルを読み込むディレクトリにコピーする必要がある。

スキーマファイル一覧

変換したいスキーマファイル

# cat schema_convert.conf
include /etc/openldap/schema/core.schema
include /etc/openldap/schema/collective.schema
include /etc/openldap/schema/corba.schema
include /etc/openldap/schema/cosine.schema
include /etc/openldap/schema/duaconf.schema
include /etc/openldap/schema/dyngroup.schema
include /etc/openldap/schema/inetorgperson.schema
include /etc/openldap/schema/java.schema
include /etc/openldap/schema/misc.schema
include /etc/openldap/schema/nis.schema
include /etc/openldap/schema/openldap.schema
include /etc/openldap/schema/ppolicy.schema
include /etc/openldap/schema/personalSchema0001.schema
include /etc/openldap/schema/personalSchema0002.schema
include /etc/openldap/schema/personalSchema0003.schema

自作のスキーマを変換してコピーするスクリプト(サンプル)

自作のスキーマを変換してcn=schema のフォルダにコピーするスクリプトのサンプル。

# cat schema_change.sh
#clean up tmpdir
rm  -rf `pwd`/ldif_output/*

#change schema file to conf
slaptest -f schema_convert.conf -F `pwd`/ldif_output

#slapd stop
#/etc/init.d/slapd stop
systemctl stop slapd

# copy schema conf and set config file
mv /etc/openldap/slapd.d/cn\=config/cn\=schema /etc/openldap/slapd.d/cn\=config/cn\=schema.`date +"%Y%m%d%H%M"`

cp -fr `pwd`/ldif_output/cn\=config/cn\=schema /etc/openldap/slapd.d/cn\=config/cn\=schema

chown -R ldap:ldap /etc/openldap

#slapd start
# /etc/init.d/slapd start
systemctl start slapd

管理者用アカウントの設定とベースDNの設定

管理者用のアカウント名とパスワードと、ベースDNの設定が必要。

以下の管理者用のアカウント名とパスワードと、ベースDNの設定したLDIFファイルを作成する。

# cat add_rootdn_rootpw.ldif
dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcSuffix
olcSuffix: o=sample

dn: olcDatabase={2}hdb,cn=config
changetype: modify
replace: olcRootDN
olcRootDN: cn=Manager,o=sample

dn: olcDatabase={2}hdb,cn=config
changetype: modify
add: olcRootPW
olcRootPW: パスワード

上記で作成したLDIFファイルを利用し、以下のコマンドでエントリを更新。

#ldapadd -Y EXTERNAL -H ldapi:// -f add_rootdn_rootpw.ldif

ベースDNの作成

ベースDN用のLDIFファイルを用意する。

 cat create_basedn.ldif
dn: o=sample
objectClass: top
objectclass: organization
o: sample

上記で作成したLDIFファイルを以下のコマンドを実行しベースDNのエントリを追加する。

#ldapadd -x -w password -D 'cn=Manager,o=sample' -f create_basedn.ldif

これで、ベースDNが作成されて利用できるようになる。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0