2012/03/31 Apacheスタートスクリプト読書会発表資料

18
2012/04/04 @usptomo 1 @usptomo USP友の会 2012/03/31 Apacheスタートスクリプト読書会

Transcript of 2012/03/31 Apacheスタートスクリプト読書会発表資料

Page 1: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 1

@usptomo

USP友の会 2012/03/31 Apacheスタートスクリプト読書会

Page 2: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 2

ごあいさつ USP友の会とは?

• USP (ユニバーサル・シェル・プログラミング)友の会は、2009年5月に日本唯一のシェルプログラミングコミュニティとしてスタートしました。

• 現在ではUNIX/Linux/シェルスクリプトの技術を中心としながらも、各種言語( C、Python、Ruby、Java、php、perl等々 ) の技術者が集まるグルーコミュニティとして活発な活動を行っています。

• 参加者は、アプリ開発や運用技術者にとどまらず、組み込み、ネットワーク技術者、運用エンジニア、システム営業、ベンチャー起業者等、UNIX哲学に共感する幅広い職種の人が集まり、それぞれの技術について語り合い、互いに技術を磨き合う場になりつつあります。

Page 3: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 3

USP友の会公式サイト http://www.usptomonokai.jp/

Page 4: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 4

USP友の会facebookサイト http://www.facebook.com/usptomo

Page 5: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 5

USP友の会Twitter http://twitter.com/#!/usptomo

Page 6: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 6

自己紹介 名前: 濱田康貴 HN: (っ´∀`)っ ゃー Twitter ID: @nullpopopo Facebook: http://www.facebook.com/nullpopopo 職業: インフラエンジニア 趣味: 勉強会運営 自転車 Linux 7つ道具: vim awk grep ps netstat パイプ リダイレクト 将来の夢: geek団地 (iDC併設) 建設

Page 7: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 7

Apacheスタートスクリプト読書会とは • 久々にシェルスクリプトな勉強会をしてみたくなった • 最近上田会長がUSP友の会サイトをWordPressからbash製CMSへリプレースし

たので、記念にApacheへの理解を深めよう • そういや読書会形式の勉強会って今までやったことなかったなー。これを機会

にやってみよう

Page 8: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 8

読書会のすすめかた • 各グループに別れて /etc/init.d/httpd を解読していきます • グループごとに、解読箇所を分担します • 印刷されたスクリプトの右側に解読結果を書いてください • 時間が余ったら他の箇所も解読してみてください • 時間がきたらグループごとに解読結果を発表していきます

Page 9: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 9

今日のタイムテーブル 14:30 開始 ごあいさつ 自己紹介 グループ分け 15:00 読書会開始 (適宜休憩しながら) 16:00 休憩 16:10 発表 #1 16:20 発表 #2 16:30 発表 #3 16:40 発表 #4 16:50 終了のごあいさつ 17:00 撤収 その後懇親会 (希望者のみ)

Page 10: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 10

/etc/init.d/httpd とは • rpmからインストールされるApache ( httpd ) に含まれるスタートスクリプト • シェルスクリプト ( bash ) で記述されている • 引数ごとに動作が決められており ( start stop restart 等 ) 、Apacheの起動停止

などを行う

Page 11: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 11

httpdが起動するまで Linuxが起動するまでの大まかな流れ ( カーネルが起動された後 ) • 各種デバイスの初期化 • initプログラムのなどの起動 • ブート時の処理 • rcスクリプトの実行 が行われる。

Page 12: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 12

httpdが起動するまで /etc/init.d とは -> /etc/rc.d/init.d のシンボリックリンク sh-3.2$ pwd /etc sh-3.2$ ls -lA | grep init.d lrwxrwxrwx 1 root root 11 Jun 20 2010 init.d -> rc.d/init.d

Page 13: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 13

httpdが起動するまで sh-3.2$ pwd /etc/rc.d sh-3.2$ ls -l drwxr-xr-x 2 root root 4096 Mar 21 20:39 init.d -rwxr-xr-x 1 root root 2255 Dec 20 02:00 rc drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc0.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc1.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc2.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc3.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc4.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc5.d drwxr-xr-x 2 root root 4096 Mar 21 20:39 rc6.d -rwxr-xr-x 1 root root 220 Dec 20 02:00 rc.local -rwxr-xr-x 1 root root 27052 Feb 22 23:47 rc.sysinit

Page 14: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 14

httpdが起動するまで sh-3.2$ pwd /etc/rc.d sh-3.2$ ls -l rc*.d/*httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc0.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc1.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Feb 20 22:49 rc2.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Feb 20 22:49 rc3.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Feb 20 22:49 rc4.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Feb 20 22:49 rc5.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc6.d/K15httpd -> ../init.d/httpd

K = Kill 数字は優先度を表す

Page 15: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 15

httpdが起動するまで sh-3.2$ pwd /etc/rc.d sh-3.2$ sudo /sbin/chkconfig httpd on sh-3.2$ ls -l rc*.d/*httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc0.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc1.d/K15httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Mar 25 18:38 rc2.d/S85httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Mar 25 18:38 rc3.d/S85httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Mar 25 18:38 rc4.d/S85httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Mar 25 18:38 rc5.d/S85httpd -> ../init.d/httpd lrwxrwxrwx 1 root root 15 Jul 16 2011 rc6.d/K15httpd -> ../init.d/httpd

S = Start 数字は優先度を表す

Page 16: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 16

httpdが起動するまで runlevel 0 シャットダウン 1 シングルユーザモード ( rootしかログインできない ) 2 ネットワークなしのマルチユーザモード 3 マルチユーザモード ( テキストログイン ) 4 未使用 5 マルチユーザモード ( GUIログイン not Gijinka User Interface ) 6 システムの再起動

Page 17: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 17

httpdが起動するまで 数字は優先度を表す。小さいほうが優先度高。 sh-3.2$ echo $(ls /etc/rc.d/rc3.d/ | egrep ^S) S03sysstat S08iptables S10network S12syslog S13portmap S14nfslock S18rpcidmapd S19rpcgssd S25netfs S26lvm2-monitor S26unbound S28autofs S55sshd S60nfs S64mysqld S80postfix S85httpd S90crond S90xfs S91smb S95anacron S95atd S99local

Page 18: 2012/03/31 Apacheスタートスクリプト読書会発表資料

2012/04/04 @usptomo 18

apachectl とどう違う? 例) statusオプションの挙動の違い sh-3.2$ sudo /usr/sbin/apachectl status The 'links' package is required for this functionality. sh-3.2$ sudo /etc/init.d/httpd status httpd (pid 22431) is running... apachectl ではlynxでlocalhostの80番ポートを叩いてステータスを確認しているのに対し、httpd では /etc/rc.d/init.d/functions の status 関数を呼び出し、プロセスの有無を確認している