hello, systemd

17
Hello, systemd! Haruka Iwao 2014/07/24

Upload: haruka-iwao

Post on 20-Dec-2014

13.425 views

Category:

Engineering


5 download

DESCRIPTION

Systemd を使うと何がうれしいのかについて説明しています。

TRANSCRIPT

Page 1: Hello, systemd

Hello, systemd!

Haruka Iwao2014/07/24

Page 2: Hello, systemd

自己紹介• 岩尾 はるか (@Yuryu)• 恵比寿方面から来ました– 発表は個人の見解です ( お約束 )– 担当はストレージです (GlusterFS, Ceph)

• クックパッドプレミアム会員です

Page 3: Hello, systemd

Hello, systemd!

• Systemd がやってきた• RHEL 7, CentOS 7, Fedora に採用• Debian と Ubuntu も将来は採用– たぶん Gentoo 以外みんな systemd

• SysV Init と upstart 、今までありがとう

Page 4: Hello, systemd

Systemd とは• PID 1 を置き換える新しいデーモン• すべてのプロセスの親– Systemd 自体はカーネルにより直接起動され

る• 今までより担当範囲が広くなった• 後方互換性はほとんど無い

Page 5: Hello, systemd

追加されたコマンド• systemctl– service コマンドに相当– systemctl < コマンド > < サービス名 >

• journalctl – ログを表示 (syslog の代わり )

• systemd-*– いっぱいあるけどとりあえず気にしない

Page 6: Hello, systemd

何がうれしいの?• init はサービスと点で接していた– 起動とシグナル送信だけに責任を持つ

• systemd はサービスの一生を監視– 起動前から終了後まですべてに責任を持つ– cgroup によるリソースの分離

• 「 unit 」単位でシステムを抽象化• シェルスクリプトからの解放• 高速化、柔軟性、 etc

Page 7: Hello, systemd

サービスの一生を監視• init で起動した後 SIGKILL 送るとどうな

る?– 例 ) Apache の親プロセスだけ SIGKILL

• 従来の init は知らぬ存ぜぬ• systemd はちゃんと見ている

Page 8: Hello, systemd

SIGKILL したらどうなるか

# systemctl status httpdhttpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: active (running) since Thu 2014-07-24 03:57:50 JST; 1min 21s ago Main PID: 1311 (httpd) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─1311 /usr/sbin/httpd -DFOREGROUND ├─1451 /usr/sbin/httpd -DFOREGROUND ├─1452 /usr/sbin/httpd -DFOREGROUND ├─1453 /usr/sbin/httpd -DFOREGROUND ├─1455 /usr/sbin/httpd -DFOREGROUND └─1457 /usr/sbin/httpd -DFOREGROUND

Jul 24 03:57:50 centos7.local httpd[1311]: AH00558: httpd: Could not reliably determine the server's fully qualified ...essageJul 24 03:57:50 centos7.local systemd[1]: Started The Apache HTTP Server.

Page 9: Hello, systemd

# kill -9 1311# systemctl status httpdhttpd.service - The Apache HTTP Server Loaded: loaded (/usr/lib/systemd/system/httpd.service; enabled) Active: deactivating (stop-sigterm) (Result: signal) since Thu 2014-07-24 04:00:40 JST; 3s ago Process: 2554 ExecStop=/bin/kill -WINCH ${MAINPID} (code=exited, status=0/SUCCESS) Process: 1311 ExecStart=/usr/sbin/httpd $OPTIONS -DFOREGROUND (code=killed, signal=KILL) Main PID: 1311 (code=killed, signal=KILL) Status: "Total requests: 0; Current requests/sec: 0; Current traffic: 0 B/sec" CGroup: /system.slice/httpd.service ├─1451 /usr/sbin/httpd -DFOREGROUND ├─1452 /usr/sbin/httpd -DFOREGROUND ├─1453 /usr/sbin/httpd -DFOREGROUND ├─1455 /usr/sbin/httpd -DFOREGROUND └─1457 /usr/sbin/httpd -DFOREGROUND

Jul 24 03:57:50 centos7.local httpd[1311]: AH00558: httpd: Could not reliably determine the server's fully qualified ...essageJul 24 03:57:50 centos7.local systemd[1]: Started The Apache HTTP Server.Jul 24 04:00:40 centos7.local systemd[1]: httpd.service: main process exited, code=killed, status=9/KILL

Page 10: Hello, systemd

systemd がみてる• サービスに対する SIGKILL をしっかり監視• 子プロセスも迷子にならない• ついでにログも見てる– 従来は syslog がごっちゃに吐いてた

• プロセスの自動再起動も可能– daemontools っぽいよね

Page 11: Hello, systemd

cgroup によるリソースの分離• リソース制限といえば ulimit– プロセス単位なので fork すると別になる

• cgroup で「サービス単位」の制限が可能– すべて systemd 経由で指定できる– わかりやすい、漏れが無い– ulimit どこに書くのが正解か議論に終止符

Page 12: Hello, systemd

unit 概念の追加• あらゆるタスクを「 unit 」とした• unit には service, target, device などがある• runlevel も「 multi-user.target 」と unit 化• それぞれに依存関係を記述– race condition による事故が無い– システムの起動が高速化

Page 13: Hello, systemd

起動と終了が高速化• 「サーバーなんだから」と思うなかれ– AWS みたいな環境だと結構効くと思う

• reboot 打ってから login: 出るまで– RHEL 6.5: 29 秒– RHEL 7.0: 10 秒

Page 14: Hello, systemd

シェルスクリプトからの解放• ポータブルな init.d スクリプト、書けます

か?• シェルスクリプトは遅い• init.d スクリプトのバグに悩む…• 数行の設定ファイルで大丈夫– そう、 systemd ならね。

Page 15: Hello, systemd

柔軟性• パケットが届いてからサービスを起動– それって inetd じゃね

• ファイルが作成されたらサービスを起動• 複数の unit をまとめた target を作れる• サービス専用の /tmp を用意

Page 16: Hello, systemd

おまけ : 単発コマンドを実行• リソース制限したり、ログを残したり、状

態を監視しつつ簡単に実行できるよ

# systemd-run echo abcRunning as unit run-2942.service.# systemctl status run-2942run-2942.service Loaded: not-found (Reason: No such file or directory) Active: inactive (dead)

Jul 24 04:50:36 centos7.local systemd[1]: Starting /bin/echo abc...Jul 24 04:50:36 centos7.local systemd[1]: Started /bin/echo abc.Jul 24 04:50:36 centos7.local echo[2943]: abc

Page 17: Hello, systemd

おしまい