LoginSignup
2
3

More than 1 year has passed since last update.

LDAPで快適Linux環境 #5 NFSの設定

Last updated at Posted at 2022-11-29

この記事は2020年に今は無き別サービスに投稿した記事を、今更Qiitaに再投稿したものです。

前回はクライアントからLDAPアカウントでログインするところまでいきました。今回は、ホームディレクトリをサーバーで管理するためにNFSの設定をしていきます。ここが一番苦労したところです。

NFSサーバーの設定

サーバーパッケージをインストールします。

root@server:~# apt install nfs-kernel-server
グループの共有ディレクトリを作成します。グループ`1st`の場合です。
root@server:~# mkdir /home/share
root@server:~# cd /home/share

root@server:/home/share# mkdir 1st
root@server:/home/share# chown root:1st 1st
root@server:/home/share# chmod 770 1st

NFS共有の設定をします。/etc/idmapd.confに自ドメインを記述します。

root@server:~# vi /etc/idmapd.conf

Domain = example.local

/etc/exportsの最終行にマウント情報を記述します。

root@server:~# vi /etc/exports

/home/ldap 192.168.x.x/24(rw,root_squash)
/home/share 192.168.x.x/24(rw,no_root_squash)

x.xは適宜置き換えてください。rwで読み書き両方を許可します。/home/ldaprootであっても所有者でなければ見ることができないようにroot_squashとします。/home/sharerootでも見られるように、no_root_squashとします。

設定を変更したら、デーモンを再起動します。

root@server:~# systemctl restart nfs-server

autofsの設定

クライアントがNFS共有されているディレクトリにアクセスしたときに自動でマウントされるように、autofsを使います。また、そのためのautomountマップはLDAPで管理します。

LDAPautofsの連携に必要なschemaファイルを取り寄せるため、autofs-ldapをインストールします。

root@server:~# apt install autofs-ldap

autofs-ldapをインストールすると、/etc/ldap/schema/autofs.schemaが作成されます。これをldifファイルに変換し、LDAPサーバーに読み込ませます。
autofs.confを新規作成し、以下の内容を記述します。

autofs.conf
include /etc/ldap/schema/core.schema
include /etc/ldap/schema/autofs.schema
これをldifファイルに変換してサーバーに読み込ませます。
root@server:~# slaptest -f autofs.conf -F /etc/ldap/slapd.d

config file testing succeededと出たら成功です。しかしここでslapcatをするとbad configulation directory!と出てしまいます。これは生成されたldifファイルの所有者がroot:rootになっているのが原因なので、openldap:openldapに変更する。

root@server:~# chown openldap:openldap /etc/ldap/slapd.d/cn=config/cn=schema/autofs.ldif

一応デーモンを再起動してから、slapcatしてみます。

root@server:~# systemctl restart slapd
root@server:~# slapcat

automountマップをLDAPに登録

mount.ldifを新規作成し、以下の内容を記述します。

root@server:~# vi mount.ldif 

dn: ou=automount,dc=example,dc=local
objectClass: organizationalUnit
ou: automount

dn: ou=auto.master,ou=automount,dc=example,dc=local
ou: auto.master
objectClass: top
objectClass: automountMap

dn: cn=/homes,ou=auto.master,ou=automount,dc=example,dc=local
objectClass: top
objectClass: automount
automountInformation: ldap:ou=auto.home,ou=automount,dc=example,dc=local
cn: /homes

dn: ou=auto.home,ou=automount,dc=example,dc=local					
ou: auto.home
objectClass: top
objectClass: automountMap

dn: cn=*,ou=auto.home,ou=automount,dc=example,dc=local
objectClass: top
objectClass: automount
description: generic home directory
automountInformation: -rw,fstype=nfs,soft,intr 192.168.x.x:/home/ldap/&
cn: *

dn: cn=/mnt/share,ou=auto.master,ou=automount,dc=example,dc=local
objectClass: top
objectClass: automount
automountInformation: ldap:ou=auto.share,ou=automount,dc=uken,dc=local
cn: /mnt/share

dn: ou=auto.share,ou=automount,dc=example,dc=local	
ou: auto.share
objectClass: top
objectClass: automountMap

dn: cn=*,ou=auto.share,ou=automount,dc=example,dc=local
objectClass: top
objectClass: automount
description: share directory
automountInformation: -rw,fstype=nfs,soft,intr 192.168.x.x:/home/share/&
cn: *

dc=example,dc=localの下に、ou=automountを作成し、ここにautofsの設定を格納します。
ou=automountの下にou=auto.masterを作成し、この中にマウント情報を記述します。cnでクライアント側のマウントポイントを指定し、automountInformationでサーバー側のマウントマップの場所を指定します。
ou=automountの下にou=auto.home,ou=auto.shareを作成し、それぞれホームディレクトリのマウントマップ、共有ディレクトリのマウントマップとします。cn=*とし、automountInformation/hoge/&と記述すると/hoge内の全てのサブディレクトリがマウント対象になります。

ldapaddコマンドで登録します。

root@server:~# ldapadd -x -D cn=admin,dc=example,dc=local -W -f mount.ldif

クライアントの設定

クライアントにパッケージnfs-common,autofs,autofs-ldapをインストールします。

root@client:~# apt install nfs-common autofs autofs-ldap

/etc/default/autofsにautomountマップがあるLDAPサーバーの情報を記述します。

root@client:~# vi /etc/default/autofs

MASTER_MAP_NAME="ou=auto.master,ou=automount,dc=example,dc=local"
LOGGING="verbose"
LDAP_URI="ldap://192.168.x.x"
SEARCH_BASE="ou=automount,dc=example,dc=local"
MAP_OBJECT_CLASS="automountMap"
ENTRY_OBJECT_CLASS="automount"
MAP_ATTRIBUTE="ou"
ENTRY_ATTRIBUTE="cn"
VALUE_ATTRIBUTE="automountInformation"

/etc/nsswitch.confの最終行にautomountの設定を記述しておきます。

root@client:~# vi /etc/nsswitch.conf

#最終行に追記
automount:    files ldap

設定が正しければ、再起動してログイン画面からLDAPユーザーにログインできるようになります。ログイン後、envHOMEを確かめてみましょう。

次回はsudoの設定をしていきます。

2
3
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
2
3