Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create private subnet #10

Merged
merged 3 commits into from
Dec 2, 2017
Merged

create private subnet #10

merged 3 commits into from
Dec 2, 2017

Conversation

litencatt
Copy link
Owner

@litencatt litencatt commented Dec 2, 2017

  • create private subnet
  • create security group "db-sg" and assign to db-server
    • check ping
  • ssh to db-server from web-server

@litencatt
Copy link
Owner Author

litencatt commented Dec 2, 2017

プライベートサブネット作成

image

@litencatt
Copy link
Owner Author

litencatt commented Dec 2, 2017

EC2にDBサーバ追加

image

@litencatt
Copy link
Owner Author

litencatt commented Dec 2, 2017

DBサーバにセキュリティグループを追加

image
image

ICMPエコー許可設定追加

ICMPの許可設定でfrom_port = 0to_port = 65535としていしたらエラーが出た

* aws_security_group.db-sg: Error revoking security group ingress rules: InvalidParameterValue: ICMP code (65535) out of range

issue: hashicorp/terraform#1313

https://www.terraform.io/docs/providers/aws/r/security_group.html#from_port
protocolがICMPの場合、from_portto_portはポート番号ではなくICMP番号を指定しなければならない

+  ingress {
+    from_port   = 8
+    to_port     = 0
+    protocol    = "icmp"
+    cidr_blocks = ["0.0.0.0/0"]
+  }
+ 

上記設定をapply後
image

@litencatt
Copy link
Owner Author

litencatt commented Dec 2, 2017

Webサーバ(10.0.1.10)からDBサーバ(10.0.2.10)へのICMPエコー確認

プライベートIPに対して

[ec2-user@ip-10-0-1-10 ~]$ ping 10.0.2.10
PING 10.0.2.10 (10.0.2.10) 56(84) bytes of data.
64 bytes from 10.0.2.10: icmp_seq=1 ttl=255 time=0.567 ms
64 bytes from 10.0.2.10: icmp_seq=2 ttl=255 time=0.421 ms
64 bytes from 10.0.2.10: icmp_seq=3 ttl=255 time=0.325 ms
64 bytes from 10.0.2.10: icmp_seq=4 ttl=255 time=0.470 ms
64 bytes from 10.0.2.10: icmp_seq=5 ttl=255 time=0.500 ms
^C
--- 10.0.2.10 ping statistics ---
5 packets transmitted, 5 received, 0% packet loss, time 4074ms
rtt min/avg/max/mdev = 0.325/0.456/0.567/0.084 ms

プライベートDNSに対して

[ec2-user@ip-10-0-1-10 ~]$ ping ip-10-0-2-10.ap-northeast-1.compute.internal
PING ip-10-0-2-10.ap-northeast-1.compute.internal (10.0.2.10) 56(84) bytes of data.
64 bytes from ip-10-0-2-10.ap-northeast-1.compute.internal (10.0.2.10): icmp_seq=1 ttl=255 time=0.348 ms
64 bytes from ip-10-0-2-10.ap-northeast-1.compute.internal (10.0.2.10): icmp_seq=2 ttl=255 time=0.522 ms
64 bytes from ip-10-0-2-10.ap-northeast-1.compute.internal (10.0.2.10): icmp_seq=3 ttl=255 time=0.609 ms
64 bytes from ip-10-0-2-10.ap-northeast-1.compute.internal (10.0.2.10): icmp_seq=4 ttl=255 time=0.538 ms
^C
--- ip-10-0-2-10.ap-northeast-1.compute.internal ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3004ms
rtt min/avg/max/mdev = 0.348/0.504/0.609/0.097 ms

@litencatt
Copy link
Owner Author

litencatt commented Dec 2, 2017

WebサーバからDBサーバへのssh

# my-key.pemをweb-serverへコピー
$ scp -i my-key.pem my-key.pem ec2-user@13.230.158.124:~/
my-key.pem                                                                                                        100% 1696     1.7KB/s   00:00

$ ssh -i my-key.pem ec2-user@13.230.158.124
Last login: Sat Dec  2 04:21:32 2017 from 133.208.249.39

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2017.09-release-notes/

# my-key.pemの権限変更
[ec2-user@ip-10-0-1-10 ~]$ chmod 400 my-key.pem

[ec2-user@ip-10-0-1-10 ~]$ ssh -i my-key.pem ec2-user@10.0.2.10

       __|  __|_  )
       _|  (     /   Amazon Linux AMI
      ___|\___|___|

https://aws.amazon.com/amazon-linux-ami/2017.09-release-notes/
[ec2-user@ip-10-0-2-10 ~]$

@litencatt litencatt merged commit 69a07a3 into master Dec 2, 2017
@litencatt litencatt deleted the create-private-subnet branch December 2, 2017 04:36
litencatt added a commit that referenced this pull request Dec 3, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant