4. MPIクラスターを作ろう! - 実行用ユーザー作成
前回のつづきです。
3. MPIクラスターを作ろう! - OpenMPIをインストール - 電子計算記
rootでMPIプログラムを実行することは危険とのことで、一般ユーザーを作成しましょう。
ここではmpiuserという名前で進めていきます。
root@compute-1:~# adduser mpiuser Adding user `mpiuser' ... Adding new group `mpiuser' (1000) ... Adding new user `mpiuser' (1000) with group `mpiuser' ... Creating home directory `/home/mpiuser' ... Copying files from `/etc/skel' ... Enter new UNIX password: Retype new UNIX password: passwd: password updated successfully Changing the user information for mpiuser Enter the new value, or press ENTER for the default Full Name []: Room Number []: Work Phone []: Home Phone []: Other []: Is the information correct? [Y/n]
パスワード入力以外はデフォルトのままでいいのでエンターでOKです。
ユーザー作成後は、各ノード間との通信にSSHを使いますので、SSHキーペアを作成し設置していきます。
root@compute-1:~# su - mpiuser mpiuser@compute-1:~$ ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/home/mpiuser/.ssh/id_rsa): Created directory '/home/mpiuser/.ssh'. Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in /home/mpiuser/.ssh/id_rsa. Your public key has been saved in /home/mpiuser/.ssh/id_rsa.pub. The key fingerprint is: SHA256:〜省略〜 mpiuser@compute-1.cs30idcfcloud.internal The key's randomart image is: +---[RSA 2048]----+ 〜省略〜 +----[SHA256]-----+ mpiuser@compute-1:~$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys mpiuser@compute-1:~$ chmod 600 ~/.ssh/authorized_keys mpiuser@compute-1:~$ ls -al ~/.ssh/ total 20 drwx------ 2 mpiuser mpiuser 4096 Dec 31 18:01 . drwxr-xr-x 3 mpiuser mpiuser 4096 Dec 31 17:59 .. -rw------- 1 mpiuser mpiuser 422 Dec 31 18:01 authorized_keys -rw------- 1 mpiuser mpiuser 1675 Dec 31 17:57 id_rsa -rw-r--r-- 1 mpiuser mpiuser 422 Dec 31 17:57 id_rsa.pub
秘密鍵としてid_rsa、公開鍵としてauthorized_keysが設置されていればOKです。自分だけになるように権限にも注意しておきましょう。
これで終わりですが、この後ひと手間減らすためにSSHのコンフィグを追加しておきます。
mpiuser@compute-1:~$ echo "StrictHostKeyChecking no" >> ~/.ssh/config mpiuser@compute-1:~$ chmod 600 ~/.ssh/config mpiuser@compute-1:~$ ls -l ~/.ssh/config -rw------- 1 mpiuser mpiuser 25 Dec 31 18:09 /home/mpiuser/.ssh/config
StrictHostKeyChecking no の設定を入れておくと、初回ログイン時やホストキーが変わったときの警告やエラーを無視できます。プログラム実行時に出ると邪魔なので予め設定しておくとよいでしょう。
セキュリティ的にはダメですが、今回はFirewall配下で閉じられた環境ということで設定してもよいでしょう。
動作確認として、自分のマシンにSSHログインしてみましょう。
mpiuser@compute-1:~$ ssh localhost Warning: Permanently added 'localhost' (ECDSA) to the list of known hosts. Welcome to Ubuntu 16.04.2 LTS (GNU/Linux 4.4.0-79-generic x86_64) * Documentation: https://help.ubuntu.com * Management: https://landscape.canonical.com * Support: https://ubuntu.com/advantage The programs included with the Ubuntu system are free software; the exact distribution terms for each program are described in the individual files in /usr/share/doc/*/copyright. Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by applicable law. ________ ______ ______ __ _ / _/ __ \/ ____/ / ____/________ ____ / /_(_)__ _____ / // / / / / / /_ / ___/ __ \/ __ \/ __/ / _ \/ ___/ _/ // /_/ / /___ / __/ / / / /_/ / / / / /_/ / __/ / /___/_____/\____/ /_/ /_/ \____/_/ /_/\__/_/\___/_/ mpiuser@compute-1:~$
こうなればOKです。
The authenticity of host 'localhost (::1)' can't be established.
〜省略〜
Are you sure you want to continue connecting (yes/no)?
と出ないように StrictHostKeyChecking no を設定しています。
では、最後に前回同様ホスト名を確認します。
mpiuser@compute-1:~$ mpirun -np 1 hostname compute-1.cs30idcfcloud.internal
rootのオプション入れずに結果返ってきたので成功ですね。
では、次回はMPI用のコードをコンパイルして実行してみます。