JINIers
[GCP] 기본 구성 aws → gcp 구성 변경_4(LB 구성) 본문
※ 수정
220930 : 내용 수정
220314 load balancer 만들기
아주 어려웠어... 순서 완전 뒤죽박죽
** 참고 사이트링크
load balancer 생성순서
1. vm 이미지 만들기
2. 인스턴스 템플릿 생성
3. 인스턴스 그룹생성 & 인스턴스 그룹에 이름이 지정된 포트 추가하기
4. 방화벽 규칙 구성
5. 외부 ip 주소 예약
6. 부하분산 설정
7. lb에 도메인 연결
8. test
* 순서 참조
https://cloud.google.com/load-balancing/docs/https/ext-https-lb-simple
내가 설정한 도메인↓
* http://ming406.duckdns.org
http://ming407.duckdns.org
*** 참조
https://cloud.google.com/load-balancing/docs/url-map-concepts
https://cloud.google.com/load-balancing/docs/https
https://cloud.google.com/dns/docs/overview
https://jiniers.tistory.com/11
https://www.youtube.com/watch?v=A5dnhLdYRQA
[1. vm 이미지 만들기]
* https://jiniers.tistory.com/11
** https://www.youtube.com/watch?v=A5dnhLdYRQA
ㅇ web-01
- disk : delete disk → keep disk로 변경
- stop!
- storage > images > create image >
* name : mysaasweb
* source : disk
* source disk : web-01
gcloud compute images create mysaasweb --project=folkloric-alpha-342423 --source-disk=web-01 --source-disk-zone=us-central1-c --storage-location=us
ㅇ web-02
- disk : delete disk → keep disk로 변경
- stop!
- storage > images > create image >
* name : myncuweb
* source : disk
* source disk : web-02
gcloud compute images create myncuweb --project=folkloric-alpha-342423 --source-disk=web-02 --source-disk-zone=us-central1-c --storage-location=us
[2. 인스턴스 템플릿 만들기]
2-1. SaaS web 인스턴스 템플릿 생성
- name : instance-template-saas
- machine type : n1-stanard-1
- boot disk : custom images
* image : mysaasweb 선택 후 select
- access scopes : allow full access to all cloud apis
- firewall : http-server, https-server
- network interfaces : web-network
gcloud compute instance-templates create instance-template-saas --project=folkloric-alpha-342423 --machine-type=n1-standard-1 --network-interface=subnet=web-sub,no-address --maintenance-policy=MIGRATE --service-account=195855246609-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --region=us-central1 --tags=http-server,https-server --create-disk=auto-delete=yes,boot=yes,device-name=instance-template-saas,image=projects/folkloric-alpha-342423/global/images/mysaasweb,mode=rw,size=10,type=pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
2-2. ncu web 인스턴스 템플릿 생성
- name : instance-template-ncu
- machine type : n1-stanard-1
- boot disk : custom images
* image : mysaasweb 선택 후 select
- access scopes : allow full access to all cloud apis
- firewall : http-server, https-server
- network interfaces : web-network
gcloud compute instance-templates create instance-template-ncu --project=folkloric-alpha-342423 --machine-type=n1-standard-1 --network-interface=subnet=web-sub,no-address --maintenance-policy=MIGRATE --service-account=195855246609-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/devstorage.read_only,https://www.googleapis.com/auth/logging.write,https://www.googleapis.com/auth/monitoring.write,https://www.googleapis.com/auth/servicecontrol,https://www.googleapis.com/auth/service.management.readonly,https://www.googleapis.com/auth/trace.append --region=us-central1 --tags=http-server,https-server --create-disk=auto-delete=yes,boot=yes,device-name=instance-template-ncu,image=projects/folkloric-alpha-342423/global/images/myncuweb,mode=rw,size=10,type=pd-balanced --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
[3. 인스턴스 그룹 만들기]
3-1. instance-group-saas 생성
- name : instance-group-saas
- instance tempalte : instance-template-saas
- location : multiple zones : us-central1
- autoscaling : min 1, max 5
- healthcheck
* name : saas-healthcheck
* tcp 80
gcloud beta compute health-checks create tcp saas-healthcheck --project=folkloric-alpha-342423 --port=80 --proxy-header=NONE --no-enable-logging --check-interval=5 --timeout=5 --unhealthy-threshold=2 --healthy-threshold=2
gcloud beta compute instance-groups managed create instance-group-saas --project=folkloric-alpha-342423 --base-instance-name=instance-group-saas --size=1 --template=instance-template-saas --zones=us-central1-c,us-central1-f,us-central1-b --target-distribution-shape=EVEN --health-check=saas-healthcheck --initial-delay=300
gcloud beta compute instance-groups managed set-autoscaling instance-group-saas --project=folkloric-alpha-342423 --region=us-central1 --cool-down-period=60 --max-num-replicas=5 --min-num-replicas=1 --mode=on --target-cpu-utilization=0.6
3-2. instance-group-ncu 생성
- name : instance-group-ncu
- instance tempalte : instance-template-ncu
- location : multiple zones : us-central1
- autoscaling : min 1, max 5
- healthcheck
* name : saas-healthcheck
* tcp 80
gcloud beta compute health-checks create tcp ncu-healthcheck --project=folkloric-alpha-342423 --port=80 --proxy-header=NONE --no-enable-logging --check-interval=5 --timeout=5 --unhealthy-threshold=2 --healthy-threshold=2
gcloud beta compute instance-groups managed create instance-group-ncu --project=folkloric-alpha-342423 --base-instance-name=instance-group-ncu --size=1 --template=instance-template-ncu --zones=us-central1-c,us-central1-f,us-central1-b --target-distribution-shape=EVEN --health-check=ncu-healthcheck --initial-delay=300
gcloud beta compute instance-groups managed set-autoscaling instance-group-ncu --project=folkloric-alpha-342423 --region=us-central1 --cool-down-period=60 --max-num-replicas=5 --min-num-replicas=1 --mode=on --target-cpu-utilization=0.6
4. 방화벽 규칙 구성
- name : fw-allow-health-check
gcloud compute firewall-rules create fw-allow-health-check --network=default --action=allow --direction=ingress --source-ranges=130.211.0.0/22,35.191.0.0/16 --rules=tcp:80
* 태그가 있다면 --target-tags=___ 추가
5. 외부 ip 주소 예약
gcloud compute addresses create network-lb-ip-1 --region=us-central1
[여기서부터 일단 해봐]
* 참고 사이트링크
- 기존 http 상태 확인 리소스 추가
gcloud compute http-health-checks create basic-check
- 대상 풀 추가 * SSH나 TCP instance를 지정할 때 pool 적용
gcloud compute target-pools create test-pool --region=us-central1 --http-health-check=basic-check
- 풀에 인스턴스 추가
gcloud compute target-pools add-instances test-pool --instances web-01,web-02
- 전달규칙(forwardiong-rules) 추가
gcloud compute forwarding-rules create test-pool-rule --region=us-central1 --ports 80 --address network-lb-ip-1 --target-pool test-pool
- 전달규칙의 외부ip주소 보기 : 34.136.201.127
gcloud compute forwarding-rules describe test-pool-rule --region us-central1
** gcloud compute forwarding-rules list 명령어로도 확인가능
[여기까지만]
ㅇ http lb 구성순서
internet → global forwarding rule → target proxy → url map → backend service → health check → instance group(backend)
5. 부하분산 설정(본격 http lb 구성하기)
ㅇ name : web-lb
ㅇ backend 구성1
- name : backend-saas
- backend type : instance group
- protocol : http
- named port : http
- timeout : 30
backends : instance-group-saas
- instance group : instance-group-ncu
- port num : 80
- cloud cdn : 체크안함
- health-check : health-check-saas -> basic-check
ㅇ backend 구성2(ncu)
- name : backend-ncu
- backend type : instance group
- protocol : http
- named port : http
- timeout : 30
backends : instance-group-ncu
- instance group : instance-group-ncu
- port num : 80
- cloud cdn : 체크안함
- health-check : health-check-saas
ㅇ host and path rules
- mode L simple host and path rule
** http://ming406.duckdns.org -> 203.231.98.170
- host2 : ming406.duckdns.org / path2 : /ncu / backend : backend-ncu
- host3 : ming406.duckdns.org / path3 : /saas / backend : backend-saas
ㅇ frontend configuration
- name : web-lb-frontend
- protocol : http
??? 뭔가 이상한데.....
34.149.100.236:80 접속 시 saas-server 뜸
근데 이제 ncu-server는 안뜨는...
LB ip 확인은 network service > Load balancing > fronteds 를 확인하면 된다.
6. LB에 도메인 연결(DNS 생성 과정)
1. 프라이빗 영역 생성
zone type : public
zone name : dns-test
dns name : ming406.duckdns.org
gcloud beta dns --project=folkloric-alpha-342423 managed-zones create dns-test --description="" --dns-name="ming406.duckdns.org." --visibility="public" --dnssec-state="off"
1-1. 레코드 추가
add record set >
type : A
ip : 확인한 ip 입력
add record set >
type : CNAME
canonical name : ming406.duckdns.org
까지 설정하고 나서 확인해보니 서버까지 붙긴 붙는데 404 not found가 조지게 뜨는 걸 확인함
이렇게 모니터링 탭을 통해 보면 백엔드 인스턴스가 어디로 붙는지 보임
근데 404가 뜨는거야.. 그래서 404 처리를 해보았다..
도메인 2개를 한개의 ip에 만들면 404는 뜨지 않지만
http:// ~ /***
/*** 부분에 경로를 넣어 서버로 넘어가게 하고 싶으면 경로 처리를 해줘야함
404가 뜰 때 조치법
1. instance 내 경로생성
https://jiniers.tistory.com/42?category=1269323
2. 도메인 연결
https://jiniers.tistory.com/48?category=1269323
'GCP > 구성연습' 카테고리의 다른 글
[GCP] 기본 구성 aws → gcp 구성 변경_6(ssh putty 접속) (0) | 2022.03.21 |
---|---|
[GCP] 기본 구성 aws → gcp 구성 변경_5(LB 404 not found) 문제 (0) | 2022.03.21 |
[GCP] 기본 구성 aws → gcp 구성 변경_3(220311)_성공 (0) | 2022.03.21 |
[GCP] 기본 구성 aws → gcp 구성 변경_2(220304)_실패 (0) | 2022.03.21 |
[GCP] 기본 구성 aws → gcp 구성 변경_1 (0) | 2022.03.21 |