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 구성 변경_3(220311)_성공 본문

GCP/구성연습

[GCP] 기본 구성 aws → gcp 구성 변경_3(220311)_성공

JINIers 2022. 3. 21. 10:30

은 이제 이 방법으로 통신에 성공했단 이야기

얘들아(0명) 언니가 성공했다(??

원래 sql 있는 부분은 서브넷이 달라 피어링 통신이 되어야하는데 sql을 만들다보니 private 구성이 있엇다

public으로 했으면 다른 서브넷이 필요했겠지만 private 구성으로 만들다보니 서브넷처럼 ip를 다르게 구성할 수 있엇음

피어링도 자동으로 되고 편했다. 그래서 그냥 그렇게 구성함

 


ㅇ 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 생성
name : db-network
subnet name : db-sub
10.110.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.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
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

 

/var/www/html/index.html 수정


공개 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

 

/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 생성할 때 권한 설정해야함 안그러면 설정불가 -> 인스턴스 stop 시킨 뒤 api 수정가능)
   * 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 → create instance → mysql 선택

[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-client 로 설치시 

E: Package 'mysql-client' has no installation candidate 라는 에러가 뜰 수 있음

그럴 땐 apt-get install default-mysql-client로 설치해주자

 

 

mysql -h 10.110.10.2 -u root -p



왜 시발..
왜 안돼!! 왜!!!!!!!!!


후핳......다시... 다시해보자..


[My SQL 생성]
ㅇ db-network, db-sub, db관련 peering 삭제
서브넷 생성 없이 web-sub만 있는 채로 만들어보자


ㅇ sql 생성

name : sql-test8
pw : sql-test8
private ip : web-private-db / 10.110.0.0/24
 * 만들면 network peering이 같이 생김
create

bastion ssh 에서 sql 로그인 시도 > 

gcloud compute ssh web-01 --zone=us-central1-c --internal-ip
sudo apt-get update
sudo apt-get install default-mysql-client

mysql -h 10.110.0.2 -u root -p


** pw : sql id와 같음

sql > 

show databases;
select Host, User from mysql.user;
exit



bastion ssh > 

gcloud compute ssh web-02 --zone=us-central1-c --internal-ip
sudo apt-get update
sudo apt-get install default-mysql-client
mysql -h 10.110.0.2 -u root -p





외부에서 bastion host로 연결 시도
* 참조 https://ahniverson.tistory.com/46

ping : 나감
putty ssh : 인증키가 없어 실패

 

 

은 여기까지 하니까 잘댐!!

 

잏힣ㅎ히 씐나 근데 아직 고비가 남음 lb lb lb lb lb !!

 

 


 

 

LB를 구성해보러 가보도록 하자.

* 이때는 몰랐찌 LB 구성이 지옥이 될 거라고는...

https://jiniers.tistory.com/41?category=1269323 

 

[GCP] 기본 구성 aws → gcp 구성 변경_4(LB 구성)

220314 load balancer 만들기 아주 어려웠어... 순서 완전 뒤죽박죽 ** 참고 https://medium.com/@jwlee98/gcp-dns-%EB%B6%80%ED%84%B0-%ED%95%98%EB%82%98%EC%94%A9-google-cloud-%EB%A1%9C-%EC%84%9C%EB%B9%..

jiniers.tistory.com

 

Comments