name: exercises-unix class: title, smokescreen, shelf, no-footer # 第12回 Unix演習<br><small>今回は無し</small> <div class=footnote> <small><small> </small></small> </div> --- name: exercises-aws class: title, smokescreen, shelf, no-footer # 第12回 AWS演習<br><small>EC2上にqemuをインストール</small> <div class=footnote> <small><small> </small></small> </div> --- class: compact # おしながき <div class=footnote> <small><small> (脚注) 課題(自由)もあるよ </small></small> </div> 1. 例題: まずqemuコマンドをインストールします 1. 例題: qemu形式のサーバイメージをダウンロード 1. 例題: qemuでサーバイメージを起動する 1. 課題(必須): qemuのサーバでホームページを公開する <!-- section-begin debian.qemu.install --> --- name: debian.qemu.install class: title, smokescreen, shelf, no-footer # qemuのインストール <div class=footnote> <small><small> </small></small> </div> --- class: compact # 例題: qemuのインストール - まずqemuコマンドをインストールします ``` [コマンド] $ sudo apt install qemu-system -y [実行例] admin@ip-172-31-38-63:~$ sudo apt install qemu-system -y 〜 省略(かなり長い) 〜 ``` - すごい量(300個弱)のインストールですが、それであっています ``` [動作確認] admin@ip-172-31-38-63:~$ qemu-system-x86_64 gtk initialization failed ``` - このコマンドがあるなら、エラーメッセージ`gtk initialization failed`が出るはずです <!-- section-end debian.qemu.install --> --- class: title, smokescreen, shelf, no-footer # <small>qemuイメージのサーバをqemuで起動する</small> <div class=footnote> <small><small> </small></small> </div> --- class: compact # 例題: qemuでサーバイメージを起動する <small> - あらかじめOSイメージファイル(alpine-nginx.qcow)を作成してS3に置いてあります 1. OSイメージファイル(alpine-nginx.qcow)をS3からダウンロードし 1. qemuコマンドの引数にダウンロードしたファイルを指定して起動します - qemuはエミュレーションするターゲットごとに異なるコマンドが用意されています - 今回はqemu-system-x86_64を使います ``` [実行するコマンド] $ curl -O http://public-os2023.s3-website-us-east-1.amazonaws.com/alpine-nginx.qcow $ sudo qemu-system-x86_64 -nographic -nic user,hostfwd=tcp::80-:80 alpine-nginx.qcow ``` - 実行している様子/解説については3頁先以降を参照 </small> --- class: compact # 課題(必須): qemuのサーバでホームページを公開する - いまqemuで配布したOSイメージを起動できているはずです(という前提で) - 課題: ホームページを`Welcome to 学籍番号`に変更してください - この課題は全自動で確認できるので作成後、起動しておいてください <small> ``` [動作確認の例 (CLIの場合)] $ curl http://www1.学籍番号.cloud.fml.org/ Welcome to b2902900 (on QEMU IMAGE) ``` </small> --- class: compact # 課題(自由): qemuのサーバの仕組みを考える <small> - ホームページの書き換えはEC2と同じように出来たと思いますが、仕組みは全然違います - EC2のときと何が違うのか?構成図を書いて「どうつながっているのか」を説明してください ``` [構成図の例] Browser -> vocareum -> EC2(debian) -> qemu -> Alpine ``` - Q: 各矢印は何を意味するか?(SSHなどの通信部分もあれば、違う仕組みも混ざっています) </small> <!-- section-begin debian.qemu.run.server --> --- class: title, smokescreen, shelf, no-footer # <small> qemuイメージのサーバを起動する</small> <div class=footnote> <small><small> </small></small> </div> --- class: compact # qemu形式のサーバイメージをダウンロード <small> ``` admin@ip-172-31-47-134:~$ curl -O http://public-os2023.s3-website-us-east-1.amazonaws.com/alpine-nginx.qcow % Total % Received % Xferd Average Speed Time Time Time Current Dload Upload Total Spent Left Speed 100 227M 100 227M 0 0 52.6M 0 0:00:04 0:00:04 --:--:-- 52.6M admin@ip-172-31-47-134:~$ ``` - 注意 - 同じリージョンのS3からのダウンロードなので、そこそこ高速です - 40-50MB/sくらいでダウンロードできるようです。5秒くらいで終了 </small> --- class: compact # サーバイメージをqemuで起動する <small> ``` admin@ip-172-31-47-134:~$ qemu-system-x86_64 -nographic -nic user,hostfwd=tcp::80-:80 alpine-nginx.qcow ``` - オプションについて - <B>-nographicは必須</B>です。普通とは違う使い方なので、<B>これがないと動きません</B> - <B>-nic user,hostfwd=tcp::80-:80</B>は80/tcpをqemu世界の中に通す命令です - 無理に例えるならVPCがqemuで、EC2がqemu上で動くOS、security groupが-nic 〜 - 80/tcpを通す命令がないと、外部からはqemu上(中)で動いているOSに通信できません ``` Welcome to Alpine Linux 3.19 Kernel 6.6.14-0-lts on an x86_64 (/dev/ttyS0) bc2 login: ``` - 起動には数十秒かかります。しばし待つと、 画面に上のようなAlpine Linuxのログイン画面が現れます </small> --- class: compact # サーバへのログイン(1) <small> ``` Welcome to Alpine Linux 3.19 Kernel 6.6.14-0-lts on an x86_64 (/dev/ttyS0) bc2 login: ``` - ユーザ root、パスワードなしでログインしてください - ターミナルが乗っ取られた状態に見えますが、それで正解です。 このサーバにログインして終了させればターミナルに戻れます </small> --- class: compact # サーバへのログイン(2) <small> ``` Welcome to Alpine Linux 3.19 Kernel 6.6.14-0-lts on an x86_64 (/dev/ttyS0) bc2 login: root Password: Welcome to Alpine! The Alpine Wiki contains a large amount of how-to guides and general information about administrating Alpine systems. See <https://wiki.alpinelinux.org/>. You can setup the system with the command: setup-alpine You may change this message by editing /etc/motd. bc2:~# ``` </small> --- class: compact # サーバの終了(1) <small> ``` Welcome to Alpine Linux 3.19 Kernel 6.6.14-0-lts on an x86_64 (/dev/ttyS0) bc2 login: root Password: Welcome to Alpine! The Alpine Wiki contains a large amount of how-to guides and general information about administrating Alpine systems. See <https://wiki.alpinelinux.org/>. You can setup the system with the command: setup-alpine You may change this message by editing /etc/motd. bc2:~# poweroff ``` - `poweroff`コマンドを実行してください </small> --- class: compact # サーバの終了(2) <small> ``` bc2:~# poweroff bc2:~# admin@ip-172-31-38-63:~$ ``` - `poweroff`実行後、数秒でEC2のプロンプト(`admin@ip-172-31-38-63:~$`)が出てきます - (改行コードが足りないため)プロンプトが乱れていますが、そういうものです。 ENTERをおせば、みなれた状態に戻ります - いつものEC2に戻って来ました </small> <!-- section-end debian.qemu.run.server -->