ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • gcloud-sdk
    공부합시다!/GCP 2023. 1. 11. 14:27
    728x90

    gcloud 명령어 학습내용!

    하나하나 차분히 따라해 보세요!

     

    1. gloud 초기 설정
      1.1. ID접속 
    gcloud auth login
      1.2. 프로젝트 접속
    gcloud config set project 프로젝트ID
      1.3. 리전 접속
    gcloud config set compute/region 리전명
      1.4. 영역
    gcloud config set compute/zone 존명
      1.5. 삭제
    gcloud config unset
    
    2. component
     2.1. 설치된 component 확인
    gcloud components list
     2.2. componenet update
    gcloud components update
    
    3. 인스턴스
     3.1. 인스턴스 생성
    gcloud compute instances create web-1 --machine-type=n1-standard-1 --zone=asia-northeast3-a --image-project=centos-cloud --image=centos-7-v20210817 --subnet=pub-s1 --tags=http --boot-disk-type=pd-standard --boot-disk-size=20GB
    
    gcloud compute instances create web-2 --machine-type=n1-standard-1 --zone=asia-northeast3-c --image-project=centos-cloud --image=centos-7-v20210817 --subnet=pri-s1 --tags=http --boot-disk-type=pd-standard --boot-disk-size=20GB
    
    gcloud compute instances create web-3 --machine-type=n1-standard-1 --zone=us-central1-a --image-project=centos-cloud --image=centos-7-v20210817 --subnet=pub-u1 --tags=http --boot-disk-type=pd-standard --boot-disk-size=20GB
    
      3.2. 인스턴스 확인
    gcloud compute instances list
      3.3. 인스턴스 삭제
    gcloud compute instances delete web-1
    
    4. ssh 접속
     4.1. ssh 접속
    gcloud compute ssh web-5
    
    5. VPC
     5.1. 네트워크 생성
    gcloud compute networks create myvpc1 --subnet-mode=custom --bgp-routing-mode=regional --mtu=1460
     5.2. 네트워크 확인r
    gcloud compute networks list
    gcloud compute networks describe myvpc1
    gcloud compute networks subnets list --network=myvpc1
     5.3. 서브넷 생성
    gcloud compute networks subnets create pub-a --network=myvpc1 --range=10.0.0.0/24 --region=asia-northeast3
    gcloud compute networks subnets create pri-a --network=myvpc1 --range=10.0.1.0/24 --region=asia-northeast3
    
    gcloud compute networks subnets delete pub-a --region=asia-northeast3
    gcloud compute networks subnets delete pri-a --region=asia-northeast3
    gcloud compute networks delete myvpc1
    
    6. 방화벽
     6.1. 방화벽 rules 설정
    gcloud compute firewall-rules create net4-ssh --network net-4 --allow tcp:22,tcp:3389,icmp --source-ranges 0.0.0.0/0
     6.2. 방화벽 rules 예제
    gcloud compute firewall-rules create <FIREWALL_NAME> --network myvpc1 --allow tcp:22,tcp:3389,icmp
     6.3. 방화벽 rules 확인
    gcloud compute firewall-rules list
    gcloud compute firewall-rules list --filter myvpc2
    gcloud compute firewall-rules list --filter myvpc2 --format=json
     6.4. 방화벽 rules 삭제
    gcloud compute firewall-rules delete myvpc2-ssh
    
    7. Cloud Storage 
     7.1. cloud storage는 gsutil 이라는 component를 사용합니다.
     7.2. 버킷 생성
    gsutil mb -b on -l asia-northeast3 gs://sdkim-1234
     7.3. 버킷에 파일 업로드
    gsutil cp ../../../users/user/Desktop/1.png gs://sdkim-1234
     7.4. 버킷의 파일 폴더로 복사(폴더는 자동적으로 생성됩니다.)
    gsutil cp gs://sdkim-1234/1.png gs://sdkim-1234/test/1.png
     7.5. 버킷 확인
    gsutil ls gs://sdkim-1234
     7.6. 버킷 내용 자세히 확인
    gsutil ls -l gs://sdkim-1234
     7.7. 버킷 권한 변경(모든 사용자 접근가능)
    gsutil iam ch allUsers:objectViewer gs://sdkim-1234
     7.8. 특정 사용자에게 버킷 권한 부여(ba044@bespin.email)
    gsutil iam ch user:ba044@bespin.email:objectCreator,objectViewer gs://sdkim-1234
     7.9. 특정 사용자에게 부여된 권한 삭제
    gsutil iam ch -d user:ba044@bespin.email:objectCreator,objectViewer gs://sdkim-1234
     7.10. 객체삭제
    gsutil rm gs://sdkim-1234/1.png
     7.11. 폴더 삭제 (폴더나 버키 삭제시에는 반드시 -r 옵션이 필요합니다.)
    gsutil rm -r gs://sdkim-1234/test
     7.12. 버킷 삭제
    gsutil rm -r gs://sdkim-1234
    
    https://storage.googleapis.com/sdkim-1234/1.png
    https://storage.cloud.google.com/sdkim-1234/1.png
    
    ===========================================================================================
    
    gcloud beta compute --project=team00-sdkim-01 instances create web-bastion --zone=asia-northeast3-a --machine-type=n1-standard-1 --subnet=pub-a --network-tier=PREMIUM --metadata=startup-script=\#\!\ /bin/bash$'\n'yum\ install\ -y\ httpd$'\n'cat\ \>\ /var/www/html/index.html\ \ \<\<\ END$'\n'\<html\>\<body\>\<h1\>Web-Server-1\</h1\>\<img\ src=\"https://storage.googleapis.com/sdkim-1234567/test/1.PNG\"\>\</body\>\</html\>$'\n'END$'\n'systemctl\ start\ httpd$'\n'systemctl\ enable\ httpd --maintenance-policy=MIGRATE --service-account=773103301240-compute@developer.gserviceaccount.com --scopes=https://www.googleapis.com/auth/cloud-platform --image=centos-7-v20210817 --image-project=centos-cloud --boot-disk-size=20GB --boot-disk-type=pd-balanced --boot-disk-device-name=web-bastion --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
    
    gcloud compute instances create web-test1 --project=team00-sdkim-01 --zone=asia-northeast3-a --machine-type=n1-standard-1 --network-interface=network-tier=PREMIUM,subnet=pub-s1 --metadata-from-file startup-script=install.sh --tags=http --create-disk=auto-delete=yes,boot=yes,device-name=web-1,image=projects/centos-cloud/global/images/centos-7-v20210916,mode=rw,size=20,type=projects/team00-sdkim-01/zones/asia-northeast3-a/diskTypes/pd-standard --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
    
    gcloud compute instances create web-2 --project=team00-sdkim-01 --zone=asia-northeast3-c --machine-type=n1-standard-1 --network-interface=network-tier=PREMIUM,subnet=pub-s1 --metadata-from-file startup-script=install1.sh --tags=http --create-disk=auto-delete=yes,boot=yes,device-name=web-2,image=projects/centos-cloud/global/images/centos-7-v20210916,mode=rw,size=20,type=projects/team00-sdkim-01/zones/asia-northeast3-a/diskTypes/pd-standard --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any
    
    gcloud compute instances create web-1 --project=team00-sdkim-01 --zone=asia-northeast3-a --machine-type=n1-standard-1 --network-interface=network-tier=PREMIUM,subnet=pub-s1 --metadata-from-file startup-script=install1.sh --tags=http --create-disk=auto-delete=yes,boot=yes,device-name=web-1,image=projects/centos-cloud/global/images/centos-7-v20210916,mode=rw,size=20,type=projects/team00-sdkim-01/zones/asia-northeast3-a/diskTypes/pd-standard --no-shielded-secure-boot --shielded-vtpm --shielded-integrity-monitoring --reservation-affinity=any

     




    728x90

    '공부합시다! > GCP' 카테고리의 다른 글

    userdata : wordpress + rds  (0) 2022.06.29
    Cloud SDK(gcloud) Install  (0) 2022.01.27
    Project Create  (0) 2022.01.27
    Account Create  (0) 2022.01.27
Designed by Tistory.