LoginSignup
0
0

Ubuntu2x.04でNISとNFSでユーザー・ファイル管理

Last updated at Posted at 2024-01-09

はじめに

Ubuntu20.04、Ubuntu22.04の計算機群でNISでユーザー管理をして、NFSでファイルを共有する一連の計算機を連携させるために必要な手続きをまとめる。やりたいことは大体CentOS7(研究室内新設サーバー)の設定メモ #centos7 - Qiitaなんだけど、Ubuntuで組むことにしたのでまとめなおす。
いつも書きかけ

お世話になったリファレンス: ubuntu 16.04 or raspberry pi 3 でのNISの設定 #Raspberrypi3 - Qiita

構築環境の構造

ドメイン名: hoge

構成マシン IP (Intra) 役割・コメント
hoge000 192.168.x.y1 hoge00nのNIS+NFSサーバー
hoge001 192.168.x.y2 NIS+NFSクライアント1
hoge002 192.168.x.y3 NIS+NFSクライアント2
... ... ...

hoge000:/homehoge000:/opt_shareがNFSのマウント元。マウント先もPATHは同じ。
サーバーとクライアントでOSのバージョンや、CPU、GPUの有無等の環境が異なるので、各計算機でoptにはローカライズしたアプリを入れて、本構築環境全体にわたって、共有したいものを/opt_shareとして準備して、NFSでマウントする。

準備

ホスト名の恒久的変更

hostnamectl set-hostname hoge000でホスト名をhoge000に変更。hoge001, hoge002も同様に。

NISクライアント管理用アカウントの作成(クライアント)

ユーザー名がNISのサーバーとクライアントで被っていると、(設定にもよるが)NISサーバーのユーザーにしかログインできなくなる。
一方で、管理用アカウントはNISクライアントのローカルにもあった方が良い(RedHat系と違ってrootを使わずsudoを使うので)ので、専用アカウントを作っておくと便利。

sudo adduser kanri_hoge001 #ユーザー追加
sudo gpasswd -a kanri_hoge001 sudo #該当ユーザーにsudo権限追加

NIS+NFSサーバー

NISとNFSのサーバーの設定はどちらを先にやってもよい。

NISサーバーの設定

お世話になりまくったリファレンス: 自作クラスタ計算機:nisの基本設定 [雑多な記録]

インストール

OS: Ubuntu 20.04

sudo apt install nisでNISをインストール。
この際に、NISDOMAINを尋ねられるので、適当にhogehoge.hogehoge.co.jp等と適当なドメインを埋める。

ドメイン名はdomainnameコマンドで確認できる。

NISサーバーの設定

/etc/defaults/nis(抜粋)
# Are we a NIS server and if so what kind (values: false, slave, master)?       
NISSERVER=master

# Are we a NIS client?                                                          
NISCLIENT=false

NISサーバーのアドレスを指定

/etc/yp.conf(抜粋)
# ypserver ypserver.network.com          
ypserver 192.168.xxx.yyy

/etc/ypserv.securenets(抜粋)
# Always allow access for localhost
255.0.0.0       127.0.0.0

# This line gives access to everybody. PLEASE ADJUST!
#0.0.0.0                0.0.0.0
255.255.255.0          192.168.xxx.0

NISを再起動

sudo systemctl restart rpcbind
sudo systemctl restart nis 

なんでかわからないけれど、nisの方のデーモンの起動に時間がかかる。(2分くらい)

データベースの更新

sudo /usr/lib/yp/ypinit -m

出力
At this point, we have to construct a list of the hosts which will run NIS
servers.  hoge000 is in the list of NIS server hosts.  Please continue to add
the names for the other hosts, one per line.  When you are done with the
list, type a <control D>.
	next host to add:  hoge000
	next host to add:  (ここで、ctrl + D を入力)
The current list of NIS servers looks like this:

hoge000

Is this correct?  [y/n: y]  y
We need a few minutes to build the databases...
Building /var/yp/hoge.hogehoge.co.jp/ypservers...
Running /var/yp/Makefile...
make[1]: ディレクトリ '/var/yp/hoge.hogehoge.co.jp' に入ります
Updating passwd.byname...
Updating passwd.byuid...
Updating group.byname...
Updating group.bygid...
Updating hosts.byname...
Updating hosts.byaddr...
Updating rpc.byname...
Updating rpc.bynumber...
Updating services.byname...
Updating services.byservicename...
Updating netid.byname...
Updating protocols.bynumber...
Updating protocols.byname...
Updating netgroup...
Updating netgroup.byhost...
Updating netgroup.byuser...
Updating shadow.byname...
make[1]: ディレクトリ '/var/yp/hoge.hogehoge.co.jp' から出ます

hoge000 has been set up as a NIS master server.

Now you can run ypinit -s hoge000 on all slave server.

NFSサーバーの設定

インストール

sudo apt install nfs-kernel-serverでNFSサーバーをインストール。

NFSサーバーの設定

/etc/exports(抜粋)
/home  192.168.x.0/255.255.255.0(rw,async)      #読み書き許可、非同期
/opt_share  192.168.x.0/255.255.255.0(rw,async) #読み書き許可、非同期

設定の反映

sudo systemctl restart nfs-serverでサービス再起動。

sudo exportfsで正しく設定出来ているか確認できる。

NIS+NFSサーバー

NISでアカウント共有はできていなくとも、ひとまずNFSは確認ができるので、まずはNFSクライアントの設定をして動作確認後、NISクライアントの動作確認をした方がスムーズだと思う。

NFSクライアントの設定

インストール

sudo apt install nfs-commonでインストール。

手動マウントテスト

sudo mount -t nfs hoge000:/home /home, sudo mount -t nfs hoge000:/opt_share /opt_shareでマウントできていることを確認する。
例えばdf -h

(抜粋)
hoge000:/home       1.8T   52G  1.7T   3% /home
hoge000:/opt_share  1.8T   52G  1.7T   3% /opt_share

のような感じでマウントされていることがわかる。

NISクライアントの設定

インストール

OS: Ubuntu 22.04

sudo apt install nisでインストール。(20.04の時と異なり、NISドメインはこの時点では聞かれなかった。

NISサーバーのアドレスを指定

/etc/yp.conf(抜粋)
# ypserver ypserver.network.com          
ypserver 192.168.xxx.yyy

NISで管理する項目を設定

passwd, group, shadow, hostsをNISで管理する項目にする。コロン(:)の右の項目の第一項目にnisの文字を足す。

/etc/nsswitch.conf(抜粋)
passwd:         nis files systemd sss
group:          nis files systemd sss
shadow:         nis files sss
gshadow:        files

hosts:          nis files mdns4_minimal [NOTFOUND=return] dns

NISクライアント再起動

sudo systemctl restart rpcbind ypbind
sudo systemctl restart rpcbind nis

domainnameの指定

インストール時に聞かれなかったドメイン名を指定。

/etc/defaultdomain(自身で作成)
hoge

以上のファイルを作って、sudo systemctl enable --now ypbindで反映完了。domainnameコマンドで期待通りのドメイン名が出ることを確認。ypwhichでサーバーのホスト名が出ていれば問題なし。

トラブルシューティング

systemctl status nisを入力するとUnit nis.service could not be found.という出力が返ってくる。

Ubuntu22.04では、これはnisではなくて、ypbindになっている。
つまり、Ubuntu20.04でデーモン名としてnisだったものは基本的にすべてypbindに差し替える必要がある。

この辺の事情Ubuntu 22.04 LTS で NIS Client を設定する #Ubuntu - Qiitaだろうか。

/etc/defaults/nisの設定していないのに動いている...

0
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
0
0