backup and recovery approach using AWS

Durability
Use 99.999999999% durability of safe storage of data provided by Amazon S3.

Security
Use flexible access control applicable to data transfer and storage and various encryption options.

Global infrastructure
Since it can be used all over the world, will use regions that comply with organization’s compliance requirements, local laws and regulations, standards etc.

Compliance
Since AWS complies with various security standards around the world including SOC, ISO 27001, PCI DSS, etc., it is possible to easily match the backup mechanism to existing compliance standards.

Scalability
Since a storage area that automatically changes according to the size of the backup data is provided, there is no need to manage the storage capacity

Reduced TCO
By using full managed services, operation costs are reduced, leading to a reduction in the total cost of ownership(TCO) of backup storage.

Price based on metered basis
Since it is a usage fee based on the used capacity and duration, a life cycle plan is set so that only data necessary for backup and recovery plan is saved.

169.254.169.254 port 80: Connection refused

Failed to connect to 169.254.169.254 port 80: Connection refused
ん? なんだこれは?

git hub issueを見てみましょう。
https://github.com/future-architect/vuls/issues/402
そもそもvulsってなに?
-> 脆弱性検知ツール Golangだあああああああああああああああああ
osはcentosの模様

で、issueを見ると、
>Yes, if you don’t use AWS, you can ignore this error.
awsでなければ無視していいよ、とのこと。
え、awsなら、何のエラー???

そもそも、169.254.169.254は、ping meatdata serverのことらしい。
metadata serverとは? :メタデータ環境で個別ユーザーまたはユーザーグループを表すメタデータオブジェクト?

メタデータサーバは、各データ(ファイル)の保管場所、保存方法等のメタデータ管理に利用される。

え、メタデータって何?HTMLのmetaのこと??
データの付帯情報

つまり、メタデータサーバーは付帯情報を保管しているサーバーって理解であってる?

aaaaaaaaaaaaa、なるほど

169.254.169.254にアクセスして、IPやホスト名、VPC情報などインスタンスのメタ情報が保存されている!?

169.254.169.254 port 80: Connection refused だから、インスタンスのメタ情報サーバーへのアクセスが禁止されているってことね。了解!

LinuxのCPU使用率100%と下げ方

CPU使用率とは、プログラムがどの程度CPUを使っているかとうこと。
CPU使用率が100%でないということは、CPUに遊びがあるという状態。

CPU使用率とは: 一定の時間に対して、どれだけCPUが稼働したか。
1000ミリ秒中550ミリ秒、稼働すれば、CPU使用率は55%になる。当たり前か。

CPU使用率が高いと、アプリケーションのパフォーマンスが落ちるイメージがあるが、つまり、CPU使用率は高い方がいいのか?

CPU周波数とは
1秒間で送信できる0か1のデジタル信号の数
3.2GHzのCPUの場合、Coreで1秒間に32億回0か1の信号を送って処理ができる。つまり、クロック周波数 = 最大通信回数
3.2GHzのCoreに対して、22億4千万回の信号を送って処理すると、Core使用率は70%になる。

で、AWSのCPU周波数は?
M3.Midium Maximum Capacity:3840 MB

DBインスタンスクラスの仕様
https://docs.aws.amazon.com/ja_jp/AmazonRDS/latest/UserGuide/Concepts.DBInstanceClass.html
ECU: Intel XeonまたはAMD Opteronの1.0G~1.2GHz相当(クロック周波数)=最大10~12億通信回数
M3.midiumが3ECU = 3.0G~3.6GHz相当のクロック周波数 = 30~36億通信回数
M3.large(6.5ECU)に上げる?

ElasticIPとPublicIP

プライベートIPv4は、インターネットから到達できないIP
プライベートIPv4は、同じネットワーク内のインスタンス間の通信に使用

RFC1918

パブリックIPアドレス インターネットから到達可能なIPv4アドレス
インスタンスとインターネット間で通信するにはパブリックアドレスを使用

Elastic IPアドレス(IPv4) : アカウントに割り当てることができるパブリックIPv4アドレス
IPv6アドレス:IPv6 CIDRブロックをVPCと関連付けることができる

プライベートIPは、要するに1つのインスタンスから別のインスタンスに接続する際に使用するIPアドレス

プライベートIPとパブリックIPはサーバを再起動すると変わるが、ElasticIPは固定できる。

AWS 踏み台サーバー(bastion)経由でSSH接続

踏み台サーバーの英語:bastion
英語名のbastionをそのままAWSのインスタンス名に使用することが多いかと思います。

踏み台サーバのセキュリティ
踏み台サーバーは、例えば アクセスする地域が限定されていてアクセスできない場合に、許可されている地域のサーバ経由でアクセスするなど、悪いイメージがあるかもしれませんが、アプリケーションのセキュリティ対策としては有効な手段の一つとなっています。

踏み台サーバーとは?
踏み台サーバーとは中継サーバーで、踏み台サーバーを経由してでないとターゲットのサーバーにアクセスできないようセキュリティグループを設定する。
踏み台サーバーからアクセスすれば、接続先のWebサーバに踏み台サーバから接続してきたと思わせることができる。

– パブリックIPをインスタンスに割り当てる必要がない
– アクセス制御の対象を踏み台サーバに限定できるため、運用負荷を軽減

AWSでの設定方法
1. VPCの作成
2. Subnetの作成(踏み台サーバ、アプリサーバ、データストア)
3. Internet Gateway
4. Route Tableの確認、設定
5. Security Groupの作成(踏み台サーバ、アプリケーションサーバ、DB用)
6. 踏み台サーバの構築

※セキュリティグループをそれぞれ作成する

VPCのセキュリティグループ

– セキュリティグループは、インスタンスの仮想ファイアウォールとして機能し、インバウンドトラフィックとアウトバウンドトラフィックをコントロール
– VPC 内でインスタンスを起動した場合、そのインスタンスには最大 5 つのセキュリティグループを割り当てることができる
– 起動時に特定のグループを指定しないと、インスタンスは VPC のデフォルトのセキュリティグループに自動的に割り当てられる

AWS「ネットワーク&セキュリティ」の「セキュリティグループ」を見ます。

セキュリティグループとは
インバウンド
送信元 プロトコル ポート範囲 コメント

アウトバウンド
送信先 プロトコル ポート範囲 コメント

SSHをAnywhere(0.0.0.0/0)に対して開放し、万一キーペアが流出してしまった場合、クラッキングを受けた場合、SSHに脆弱性が発見された場合など、
様々なリスクがある。

なるほど、セキュリティグループ(VPC)でインバウンド、アウトバウンドを制御しているのね。

ec2でperlを動かそう

/var/www/cgi-bin

[ec2-user@ cgi-bin]$ ls
hello.cgi
[ec2-user@ cgi-bin]$ sudo chmod +x hello.cgi

#!/usr/bin/perl --
print "Content-type: text/html \n\n";
print "Hello";

きた

mysql
mysql> create database perldb;
Query OK, 1 row affected (0.02 sec)

mysql> use perldb;
Database changed
mysql> create table t1(
-> a int,
-> b varchar(10)
-> );
Query OK, 0 rows affected (0.04 sec)

mysql> insert into t1 values(1, ‘asakura’),(2, ‘adachi’),(3, ‘kobayakawa’);
Query OK, 3 rows affected (0.00 sec)
Records: 3 Duplicates: 0 Warnings: 0

mysql> select * from t1;
+——+————+
| a | b |
+——+————+
| 1 | asakura |
| 2 | adachi |
| 3 | kobayakawa |
+——+————+
3 rows in set (0.01 sec)

$ perl hoge.pl
Can’t locate DBI.pm in @INC (@INC contains: /usr/local/lib64/perl5 /usr/local/share/perl5 /usr/lib64/perl5/vendor_perl /usr/share/perl5/vendor_perl /usr/lib64/perl5 /usr/share/perl5 .) at hoge.pl line 4.
BEGIN failed–compilation aborted at hoge.pl line 4.

sudo yum -y install perl-DBI perl-DBD-MySQL

きた!OKKKKKKKKKKKKKKKK

次はservlet mysqlだ。ここわなー

mysqlのpasswordを忘れた時

passwordが違うと表示
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)

さっぱり覚えていない
ec2の初期パスワードか?
[ec2-user@ ~]$ cat /var/log/mysqld.log

[ec2-user@ ~]$ mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
違うらしい。。

mysqlを止めて、/etc/my.cnfを編集
[ec2-user@ ~]$ sudo service mysqld stop
Stopping mysqld: [ OK ]
[ec2-user@]$ sudo vi /etc/my.cnf

skip-grant-tables を追加

再起動して、-pなしでログイン
[ec2-user@~]$ sudo service mysqld start
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root

> UPDATE mysql.user SET authentication_string = PASSWORD(‘new password’) WHERE User = ‘root’ AND Host = ‘localhost’;
> FLUSH PRIVILEGES;

[ec2-user@]$ sudo vi /etc/my.cnf
# skip-grant-tables //コメントアウト

$ sudo service mysqld restart
Stopping mysqld: [ OK ]
Starting mysqld: [ OK ]
[ec2-user@ ~]$ mysql -u root -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 3
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

OK!ふう、焦った~