オンプレミスからVPC内の名前解決が可能になる。。。
なるほどー なんかよくわからん…
[Direct Connect] Transit Gatewayとは
Transit Gatewayとは?
-> VPCとオンプレミスネットワークを相互接続するために使用できるネットワーク中継ハブ
-> 複数のVPCと接続する場合などにルーティング接続(VPC, VPN接続を指定できる)
-> オンプレミスを単一のゲートウェイで接続することができるサービス
ルートテーブルを作成し、アソシエーション、プロパゲーションし、サブネットのルートテーブルに経路を追加する
### Create transit gateway
transit gatewayを作成: transit-gateway-01
transit gateway route tableを作成: transit-gateway-route-table-01
Transit gateway attachments: VPC attachmentでVPCをattachする
なるほど、なんとなく、仕組み自体は理解した
AWS DynamoDBとは?
– Managed NoSQLデータベース(Key Value Store)
– 3つのAZに分散して格納される
### DynamoDBを触ってみる
– table作成

テーブル名: Music
パーティションキー: Artist
ソートキー(任意設定): SongTitle
Default setting
-> Create Table
### DynamoDB操作
$ aws dynamodb put-item –table-name Music –item ‘{ “Artist”: { “S”: “Ryosuke” }, “SongTitle”: { “S”: “FirstSong” }}’
$ aws dynamodb put-item –table-name Music –item ‘{ “Artist”: { “S”: “Ryosuke” }, “SongTitle”: { “S”: “SecondSong” }}’
$ aws dynamodb put-item –table-name Music –item ‘{ “Artist”: { “S”: “Michael” }, “SongTitle”: { “S”: “FirstSong” }}’
$ aws dynamodb scan –table-name Music
$ aws dynamodb get-item –table-name Music –key ‘{ “Artist”: { “S”: “Ryosuke” }, “SongTitle”: { “S”: “SecondSong” }}’
$ aws dynamodb query –table-name Music –key-condition-expression ‘Artist = :Artist’ –expression-attribute-values ‘{ “:Artist”> : { “S”: “Ryosuke” }}’
ほうほう、なるほどー
Redisみたいな感じかー
PHPのエラーログ
まず、php.iniの場所
$ php -r “echo phpinfo();” | grep “php.ini”
Configuration File (php.ini) Path => /etc/php/7.4/cli
Loaded Configuration File => /etc/php/7.4/cli/php.ini
$ cat /etc/php/7.4/cli/php.ini | grep error_log
; server-specific log, STDERR, or a location specified by the error_log
; Set maximum length of log_errors. In error_log information about the source is
;error_log = php_errors.log
;error_log = syslog
; to syslog. Only used when error_log is set to syslog.
; the message. Only used when error_log is set to syslog.
; OPcache error_log file name. Empty string assumes “stderr”.
;opcache.error_log=
あれ、コメントアウトされていて、出力されていない…?
$ sudo vi /etc/php/7.4/cli/php.ini
$ G
$ error_log = /var/log/php.log
ini_set('display_errors', "On");
$num1 = 2;
$num2 = 0;
try {
echo calc1($num1, $num2);
} catch (Exception $e){
echo $e->getMessage();
error_log("[". date('Y-m-d H:i:s') . "]". "保存に失敗しました。\n", 3, "/var/www/html/debug.log");
}
function calc1($a, $b){
if ($b == 0){
throw new Exception("エラー");
}
return $a/$b;
}
$ sudo touch debug.log
$ sudo chmod 777 /var/www/html/debug.log
$ cat /var/www/html/debug.log
[2022-04-09 23:37:07]保存に失敗しました。
これで、エラーログを出力できる。
error_log("[". date('Y-m-d H:i:s') . "]". "保存に失敗しました。\n", 3, "/var/log/php.log");
なるほど、理解した。
Ubuntu20.04でterraformを動かしてみる
hashicorpにインストール手順が記載
https://www.terraform.io/downloads
$ curl -fsSL https://apt.releases.hashicorp.com/gpg | sudo apt-key add –
$ sudo apt-add-repository “deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main”
$ sudo apt-get update && sudo apt-get install terraform
$ terraform –version
Terraform v1.1.8
on linux_amd64
mysql.tf
terraform {
required_providers {
mysql = {
source = "terraform-providers/mysql"
}
}
}
provider "mysql" {
endpoint = "localhost:3306"
username = "root"
password = "password"
}
resource "mysql_database" "app" {
name = "my_database"
}
$ terraform init
$ terraform plan
$ terraform apply
mysql> show databases;
### リソースを変更
resource "mysql_database" "app" {
name = "my_database"
default_character_set = "utf8mb4"
default_collation = "utf8mb4_ja_0900_as_cs_ks"
}
$ terraform plan
$ terraform apply
### 破棄
$ terraform destroy
なるほどー
PHPのtry & catch(Exception $e)の挙動
ini_set('display_errors', "On");
$num1 = 2;
$num2 = 0;
try {
echo calc1($num1, $num2);
} catch (Exception $e){
echo $e->getMessage();
}
function calc1($a, $b){
if ($b == 0){
throw new Exception("エラー");
}
return $a/$b;
}
http://192.168.56.10:8000/
エラー
function calc1($a, $b){
// if ($b == 0){
// throw new Exception("エラー");
// }
return $a/$b;
}
http://192.168.56.10:8000/
Warning: Division by zero in /home/vagrant/dev/php/index.php on line 18
INF

なるほど、そういうことか、表示が違うのね…
[Docker] Postfixを実装したい
Dockerfile
FROM ubuntu:20.04 RUN apt update && apt upgrade -y # postfix install RUN DEBIAN_FRONTEND=noninteractive apt install postfix -y # SMTPにはSMTP AUTHが必要 # SMTP AUTHの為のSASLにはCyrus SaslとCyrus IAMPを使う RUN apt install sasl2-bin -y RUN DEBIAN_FRONTEND=noninteractive apt install cyrus-imapd -y # コンテナ起動のスクリプト COPY ./entrypoint.sh / ENTRYPOINT ["sh", "/entrypoint.sh"]
docker-compose.yml
version: '3.3'
services:
docker-ubuntu-postfix-example:
build:
context: ./
dockerfile: Dockerfile
image: docker-ubuntu-postfix-example-image:latest
container_name: docker-ubuntu-postfix-example-container
volumes:
# Postfixの設定をマウントする
- type: bind
source: ./configs/main.cf
target: /etc/postfix/main.cf
# SASL認証のパスワードをマウントする
- type: bind
source: ./configs/sasl_passwd
target: /etc/postfix/sasl_passwd
entrypoint.sh
#!/bin/bash # postfix起動 postfix start # Postfixは/var/spool/postfixにchrootするので、 # /etc/resolv.confではなく/var/spool/postfix/etc/resolv.confを見に行く。 cp /etc/resolv.conf /var/spool/postfix/etc/resolv.conf # SASL認証用テーブル作成 chown root:root /tec/postfix/sasl_passwd postmap /etc/postfix/sasl_passwd # postfixの設定を反映させる postfix reload # コンテナの起動を維持 tail -f /dev/null
configs/main.cf
L postfixを使う場合
# ログの出力設定 mainlog_file = /var/log/mail.log # SMTPリレーの設定 relayhost = [smtp.mailtrap.io]:2525 smtp_sasl_auth_enable = yes smtp_sasl_mechanism_filter = plain smtp_sasl_security_options = noanonymous smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
configs/sasl_passwd
-> postfixのcredential情報
<メールサーバのFQDN>]:587 <ユーザ名>:<パスワード> #★
$ sudo docker-compose build –no-cache
$ sudo docker-compose up -d
$ sudo docker exec -it docker-ubuntu-postfix-example-container /bin/bash
root@7b16a3765167:/# sendmail your-email@example.com
From:your-email@example.com
To:your-email@example.com
Subject:Hello World
Hello World
.
[Docker] 環境変数を渡す
Dockerfile
FROM ubuntu:latest
ARG hoge
ENV HOGE=${hoge}
$ sudo docker build ./ -t test –build-arg hoge=”abc”
$ sudo docker run -itd –rm –name my_container test:latest
$ sudo docker exec -it my_container /bin/bash
root@1ae829aee3fc:/# echo $HOGE
abc
なるほどー
次はdockerでpostfix
[Docker] CentOS httpdのdocument root変更
FROM centos:centos7
ENV APACHE_DOCUMENT_ROOT /var/www/html/ssl/
RUN yum update -y && yum clean all
RUN yum install -y epel-release
RUN yum -y install install http://rpms.famillecollet.com/enterprise/remi-release-7.rpm
RUN yum install -y httpd
RUN yum -y install --enablerepo=remi,remi-php74 php php-devel php-mbstring php-pdo php-xml php-gd php-fpm php-mysqlnd php-opcache php-pecl-zip libzip5
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/sites-available/*.conf
COPY . /var/www/html/
EXPOSE 80 443
CMD ["/usr/sbin/httpd", "-D", "FOREGROUND"]
$ sudo docker build -t mycentos .
$ sudo docker run -dit –name myapp -p 8080:80 mycentos
あれ、うまくいかんな…
[Docker] php:8.0-apacheのdocument root変更
FROM php:8.0-apache
ENV APACHE_DOCUMENT_ROOT /var/www/html/ssl/
COPY . /var/www/html/
RUN sed -ri -e 's!/var/www/html!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/sites-available/*.conf
RUN sed -ri -e 's!/var/www/!${APACHE_DOCUMENT_ROOT}!g' /etc/apache2/apache2.conf /etc/apache2/sites-available/*.conf
$ sudo docker build -t myapache .
$ sudo docker run -dit –name myapp -p 8080:80 myapache
http://192.168.56.10:8080/api/
ん? これ、CentOSでもいけるのか??