URAMIRAIKAN

1020のなれの果て (since 2005.6.19)

「389 Directory Server」でAutomountとNISネットグループを利用

 前回まででLDAPによるユーザー認証ができたので、今回はNFSサーバを追加して次のことをやってみます。

  • クライアント環境でautofsを利用し、マップ情報をLDAPで管理する。
  • NFSサーバの"/etc/exports"で使うNISネットグループをLDAPで管理する。

 基本的には389-ds固有のものではなく、LDAP全般のことですね。

 環境は前回までと同様ですが、今回は新たにNFSサーバを追加します。
 (例によってNFSサーバの構築は省略)

ホスト名FQDNIPアドレス備考
ds-1ds-1.example.com172.16.11.51LDAPサーバ
ds-2ds-2.example.com172.16.11.52LDAPサーバ
nfsnfs.example.com172.16.11.53NFSサーバ
stgstg.example.com172.16.11.55クライアント

LDAPサーバ側の設定

 LDAPサーバ側にはautofsで使うマップ情報とNISネットグループの情報を入れていきます。

 まずマップ情報ですが、今回はユーザーのホームディレクトリをマウントするようにします。
 LDAPに格納する情報としては下図のように、"Automount"というOUの配下に情報をまとめるようにしてみます。


 マップ情報を扱うオブジェクトクラスや属性についてはスキーマとの兼ね合いで下表のような3パターンがあるようですが、389-dsでは左側のRFC2307のパターンになります。

キーワードRFC2307RFC2307bisNIS
Map ObjectclassautomountMapautomountMapnisMap
Entry ObjectclassautomountautomountnisObject
Map AttributeouautomountMapNamenisMapName
Entry AttributecnautomountKeycn
Value AttributeautomountInformationautomountInformationnisMapEntry

 投入するLDIFは次の通りです。("ldapadd"は省略)

dn: ou=Automount,dc=example,dc=com objectClass: organizationalUnit ou: Automount dn: ou=auto.master,ou=Automount,dc=example,dc=com ou: auto.master objectClass: top objectClass: automountMap objectClass: organizationalUnit dn: cn=/home,ou=auto.master,ou=Automount,dc=example,dc=com cn: /home objectClass: top objectClass: automount automountInformation: auto.home dn: ou=auto.home,ou=Automount,dc=example,dc=com ou: auto.home objectClass: top objectClass: automountMap objectClass: organizationalUnit dn: cn=/,ou=auto.home,ou=Automount,dc=example,dc=com cn: / objectClass: top objectClass: automount automountInformation: -fstype=nfs nfs.example.com:/exports/home/&

 "auto.master"配下のマウントポイントを示す"/home"ではマップ先となる"auto.home"を指し、"auto.home"配下の"/"では実際のマウントオプションやNFSサーバを指しています。
 マウントターゲット"/exports/home/&"の"&"は任意の文字列となり、今回であればユーザー名に対応するディレクトリをマウントするようになります。

 次にNISネットグループです。
 これも"Netgroup"というOUを作成し、配下に"nfsclient"をいうグループを作成します。
 グループのメンバーはNFSクライアント(今回は"stg.example.com")です。
 LDIFは次の通りです。

dn: ou=Netgroup,dc=example,dc=com objectClass: organizationalUnit ou: Netgroup dn: cn=nfsclient,ou=Netgroup,dc=example,dc=com objectClass: top objectClass: nisNetgroup cn: dataldap nisNetgroupTriple: (stg,,example.com)

 グループのメンバーは"nisNetgroupTriple"属性で記述します。今回は1つだけですが、メンバーの数だけこの属性を追加していきます。

 これでLDAPサーバ側に情報は揃いましたので、クライアントやNFSサーバでこの情報を利用できるようにしていきます。

NFSサーバ側の設定

 NFSサーバでは"/etc/exports"のアクセス許可でLDAPに格納したNISネットグループの情報を利用します。
 まず、クライアント環境と同様にSSSD等を設定し、LDAPを参照できるようにします。
 この際に"/etc/sssd/sssd.conf"の"[domain/default]"セクションへ次の設定を追加します。

ldap_netgroup_search_base = ou=Netgroup,dc=example,dc=com

 LDAPを参照できていれば、"getent"コマンドでNISネットグループが確認できます。

# getent netgroup nfsclient
nfsclient (stg,,example.com)

 これを使って"/etc/exports"を設定し、NFSを公開します。
 NISネットグループは次の例のように"@"をつけて記述します。

/exports/home @nfsclient(rw,sync,no_root_squash)

 ついでにユーザーのホームディレクトリも作ってパーミッションを設定しておきます。
 (今回の環境ではホームディレクトリを自動作成することは考慮されていないため)

# mkdir -p /exports/home/test
# chown -R test:ldapusers /exports/home/test

クライアント側の設定

 クライアントは前回まででLDAPによるユーザー認証ができている前提です。
 これに加えてautofsのマップ情報を参照するようにします。
 autofsパッケージが入っていない場合はインストールしておいてください。

 クライアント側でも"/etc/sssd/sssd.conf"に設定を追加して、マップ情報を参照するようにします。
 以前の設定例の通りなら"services = nss, pam, autofs"とか"autofs_provider = ldap"のような設定が入っていて機能自体は有効になっている想定で、[domain/default]"セクションへ次の設定を追加します。

ldap_autofs_search_base = ou=Automount,dc=example,dc=com ldap_autofs_map_object_class = automountMap ldap_autofs_entry_object_class = automount ldap_autofs_map_name = ou ldap_autofs_entry_key = cn ldap_autofs_entry_value = automountInformation

 マップ情報の参照先となる設定ですね。
 設定が完了したらSSSDを再起動して、autofsも起動します。

# systemctl restart sssd.service
# systemctl start autofs.service
# systemctl enable autofs.service

 設定が正しくできていると、"automount -m"コマンドでLDAPから取得したマップ情報を確認できます。

# automount -m

autofs dump map information
===========================

global options: none configured

Mount point: /home

source(s):

instance type(s): sss
map: auto.home

* | -fstype=nfs nfs.example.com:/exports/home/&

 ここまでできたら、先程ホームディレクトリを作成した"test"ユーザーでログインしてみます。
 次の例のように、ホームディレクトリでNFSをマウントしている状態になるはずです。

$ df -h
Filesystem Size Used Avail Use% Mounted on
(省略)
nfs.example.com:/exports/home/test 55G 2.1G 53G 4% /home/test

 以上、LDAPサーバ(389-ds)とNFSの連携でした。

 とりあえず今回やりたかった所はここまでです。
 あとは補足とか気になったところとか整理できたら追加していきます。