Notice
Recent Posts
Recent Comments
Link
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
Tags
more
Archives
Today
Total
관리 메뉴

JINIers

[GCP] 기본 구성 aws → gcp 구성 변경_2(220304)_실패 본문

GCP/구성연습

[GCP] 기본 구성 aws → gcp 구성 변경_2(220304)_실패

JINIers 2022. 3. 21. 09:37

제일 처음 이해하고 만든 버전으로 작성해야 했기에 vpc network 부터 설정해보았다.

실패는 성공의 어머니라고 했다..ಥ_ಥ


vpc 네트워크 만들기(서브넷 생성)

 

1. web-network 생성

name : web-network
subnet name : web-sub
10.100.0.0/24

gcloud compute networks create web-network --project=folkloric-alpha-342423 --subnet-mode=custom --mtu=1460 --bgp-routing-mode=regional

 

gcloud compute networks subnets create web-netsub --project=folkloric-alpha-342423 --range=10.100.0.0/24 --network=web-network --region=us-central1


2. db-network 생성     // 굳이 만들필요X, 하다보니 만들었지만 사용하지 않음

name : db-network
subnet name : db-sub
10.110.0.0/24

gcloud compute networks create db-network --project=folkloric-alpha-342423 --subnet-mode=custom --mtu=1460 --bgp-routing-mode=regional
gcloud compute networks subnets create db-netsub --project=folkloric-alpha-342423 --range=10.110.0.0/24 --network=web-network --region=us-central1

방화벽 생성

gcloud compute firewall-rules create web-allow-ssh --direction=INGRESS --priority=1000 --network=web-network --action=ALLOW --rules=tcp:22,icmp --source-ranges=0.0.0.0/0

 

 

공개 ip 주소가 없는 webserver-1 생성

Name : web-01(SaaS web)
Region : us-central1
Zone : us-central1-c
Machine type : 1vCPU (3.75 GB memory, n1-standard-1)

Network interfaces > 
Network : web-network
Subnetwork : web-netsub
External IP : None

[apache2 설치]
bastion ssh > 

gcloud compute ssh web-01 --zone=us-central1-c --internal-ip
sudo apt-get update
sudo apt-get install -y apache2
sudo service apache2 start
curl localhost
sudo update-rc.d apache2 enable
sudo service apache2 status

공개 ip 주소가 없는 webserver-2 생성


Name : web-02(NCU web)
Region : us-central1
Zone : us-central1-c
Machine type : 1vCPU (3.75 GB memory, n1-standard-1)

Network interfaces > 
Network : web-network
Subnetwork : web-netsub
External IP : None
network tags : http, https 체크  -> 의 문제가 아니었음 -> 그렇다면 프록시

gcloud compute ssh web-02 --zone=us-central1-c --internal-ip


[nginx 설치]

sudo apt-get update
sudo apt-get install nginx-light -y
sudo nano /var/www/html/index.nginx-debian.html

<h1>Welcome to nginx!</h1>
→ <h1>web-02(NCU web)</h1> 로 변경

service nginx starts

bastion 생성

- network interface 1. web-network / external : ephemeral
- network interface 2. defatul / external : none
- http, https 체크
-metadata : enable-oslogin / true

gcloud compute ssh web-01 --zone=us-central1-c --internal-ip


흑흑 하지만 여전히 bastion에서 web-01로 인터널 접속은 안돼..왜왜왜왜왜 안될까 왜 왜왜
이렇게 뜬다..▼

ERROR: (gcloud.compute.ssh) Could not fetch resource:
 - Request had insufficient authentication scopes.



▶ os 로그인 iam 역할을 부여한다 -> 서비스 계정에 ssh 액세스 권한 부여?? 

↓ 해결
- Identity and API access(bastion 생성할 때 권한 설정해야함 안그러면 설정불가)
   * service account : compute engine default service account
   * access scopes : set access for each API
     ** compute engine : read write
  *** 아니면 allow full access to all cloud apis로 설정

※ 참고 : https://cloud.google.com/sdk/gcloud/reference/compute/instances/set-service-account


cloud nat 생성

network service > cloud nat
- name : nat-config 
- router : nat-router
생성 후 web-01 ssh에서 www.google.com 하면 핑 나감

gcloud compute ssh web-01 --zone=us-central1-c --internal-ip


하면 접속 성공!!!!!!!!!!!!!!!!!!!!!


web-sub ↔ db-sub 간 비공개 ip 이용한 네트워크 피어링


참고 사이트 

[sql 인스턴스 생성]
name : sql-test2
pw : 이름이랑 똑같이
database version : mysql5.7
region : us-central1
zonal availabillity : multiple zone
 - pri : us-central-c
 - second : any
customize instance > connetion
- private ip 체크, public ip 해제
- network : db-network
   * db-network-api : 10.110.10.0/24)


비공개 서비스 액세스 연결 설정 > 누르면 오른쪽에 창이 떠..
1. network 간 peering 하고
2. private service access 설정
db-network : 10.110.0.0/24 니까 
-> 이걸 api로 일단 설정하는거지...
-> 지우고 싶으면 vpc network > db-network > private service connection에 들어가면 db-network-api가 더 있을 것임, 선택 후 > release 해주면 된다.

근데 다ㅏ시... 만들었어....하...


* 설정


sql-test 인스턴스 만들어서 sql 접속 테스트하기
-> 방화벽 같이 만들어놓을 것

gcloud compute firewall-rules create db-allow-ssh --direction=INGRESS --priority=1000 --network=db-network --action=ALLOW --rules=tcp:22,icmp --source-ranges=0.0.0.0/0




sql-test-1 ssh > 10.110.10.2

sudo apt-get update
sudo apt-get install mysql-client
mysql -h 10.110.10.2 -u root -p

는 중간중간 뭐가 안되는게 많아서

죄다 뿌수고 다시만듦

Comments