- 質問:AWSにEC2インスタンスを立てたことがある人?
- Ubuntu 22.04のインスタンスを起動してsshでログインしてみよう
- ubuntuユーザーでログインしてみよう
.ssh/config
Host infra-training
User ubuntu
Port 22
IdentityFile 鍵ファイル
HostName パブリックIPアドレス
ServerAliveInterval 5
ServerAliveCountMax 12
ps aux
を打ってみよう- 質問:プロセスは何個ぐらい起動してる?
- 自分のMacでも打ってみて数えてみよう
- 質問:プロセスは何個ぐらい起動してる?
top
を打ってみよう- 質問:このサーバーのメモリはどのぐらい?そのうちどのぐらい使われてる?
df -h
を打ってみよう- 質問:このサーバーのディスク容量はどのぐらい?そのうちどのぐらい使われてる?
- 質問:このサーバーに入ってるテキストエディタは何がある?
- vimとかemacsとか入れたければaptで入れてみよう
- どれも得意じゃなければnanoを使おう
~/.bashrc
を開いてみよう
- vimとかemacsとか入れたければaptで入れてみよう
sudo apt install php
してみよう- その前に
sudo apt update
をしてみよう
- その前に
ps aux
を打ってみよう- 質問:Apacheのプロセスはいくつ起動してる?
less /etc/apache2/sites-enabled/000-default.conf
してみよう- 質問:どこにphpファイルを置けばブラウザから見られる?
<?php var_dump($_SERVER);
と書いたindex.phpというファイルを置いてブラウザでアクセスしてみよう- 質問:SERVER_SOFTWAREの値は?
- Apacheを止めてみよう
- systemctlを使ってApacheを止めてみよう
systemctl
# apache2の状態を見る
sudo systemctl status apache2
# apache2を再起動
sudo systemctl restart apache2
# apache2の設定を再読み込み
sudo systemctl reload apache2
# apache2を止める
sudo systemctl stop apache2
aptでphp8.1-fpmをインストールしてみよう
sudo systemctl status php8.1-fpm
と打ってみよう- 質問:php-fpmのプロセスはいくつ起動してる?
- 質問:php-fpm の設定ファイルはどこにある?
- 設定ファイルを開いてみよう
- 質問:php-fpmがlistenしているソケットファイルはどこにある?
- (トリッキーなので誰も手が上がらなければすぐに教える)
- aptでnginxをインストールしてみよう
- nginxでphp-fpmにリバースプロキシしてみよう
- 手元のマシンで
/etc/hosts
を書いてブラウザでアクセスしてみよう - 質問:SERVER_SOFTWAREの値は?
- 手元のマシンで
nginx
# /etc/nginx/sites-enabled/php.conf
server {
listen 80;
server_name php.aws;
root /var/www/html;
location / {
fastcgi_pass unix:/run/php/php8.1-fpm.sock;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
}
nginxの設定を反映するときは
sudo nginx -t
してから
sudo systemctl reload nginx
再起動しても良い
sudo systemctl restart nginx
- nginxのアクセスログにレスポンスタイムを出すようにしてみよう
- htopコマンドを使ってみよう
- メモリ順に並べてみよう
- CPU順に並べてみよう
- ウェブブラウザで負荷をかけてみよう
- dstatコマンドをインストールしてみよう
dstat -tlamp --top-cpu-adv --top-io-adv
と打ってみよう- ウェブブラウザで負荷をかけてみよう
nginx
log_format ltsv "time:$time_local"
"\thost:$remote_addr"
"\tforwardedfor:$http_x_forwarded_for"
"\treq:$request"
"\tstatus:$status"
"\tmethod:$request_method"
"\turi:$request_uri"
"\tsize:$body_bytes_sent"
"\treferer:$http_referer"
"\tua:$http_user_agent"
"\treqtime:$request_time"
"\tcache:$upstream_http_x_cache"
"\truntime:$upstream_http_x_runtime"
"\tapptime:$upstream_response_time"
"\tvhost:$host";
# 既にあるこの行の一番後ろにltsvと追加
access_log /var/log/nginx/access.log ltsv;