Google Cloud

BigQuery 데이터 입출력 From Local TO BigQuery

개요

  • 서비스 계정 추가 후, 데이터 업로드

GCP 서비스 계정 추가

  • IAM 및 관리자 > 서비스 계정 > 서비스 계정 만들기 선택

image.png

  • 서비스 계정 이름은 각자 정한다. 필자는 lgu6th-bq-loader로 명명했다.
  • 서비스계정 ID는 이메일 주소 ID를 사용한다.
  • 만들고 계속하기 버튼을 클릭한다.

image.png

  • 권한을 부여한다. BigQuery 관리자를 선택한다.
  • 그 후 계속 버튼을 클릭한다.

image.png

  • 그 후 완료 버튼을 클릭한다.

image.png

서비스 키 다운로드

  • 다음과 같은 화면에서 키 관리 버튼을 클릭한다.

image.png

GCP VM Connect to BigQuery using Streamlit (ver. 2025, 06)

개요

  • VM 만들기 Web UI가 일부 변경됨 (추가 진행하기로 함)
  • VM 생성 및 VS Code 연결
  • VM과 BigQuery 연결

VM 머신 생성

머신 구성

  • 이름과 성능 체크
  • 월별 예상 가격을 체크한다.

Screenshot 2025-06-20 at 7.54.08 PM.png

OS 및 스토리지

  • Ubuntu - Ubuntu 24.04 LTS 방식으로 진행 (x86/64) 방식 선택
  • 디스크 사이즈 : 25GB

Screenshot 2025-06-20 at 8.00.50 PM.png

  • 암호화 : Google 관리 암호화 키 선택

Screenshot 2025-06-20 at 8.02.26 PM.png

gcloud installation on Mac, SSH Connection with VSCode

개요

Screenshot 2024-04-22 at 6.15.48 PM.png

설치파일 다운로드

  • 각 사용자 버전에 맞는 설치 파일을 다운로드 받는다.
    • 필자는 M1 silicon 버전을 사용하기로 하였다.
    • Desktop > gcloud_install 내부에 해당 파일을 다운로드 받았다.

Screenshot 2024-04-22 at 6.16.45 PM.png

  • 압축을 풀면 아래와 같이 google-cloud-sdk 폴더 안애 install.sh 파일이 있다.

Screenshot 2024-04-22 at 6.20.54 PM.png

설치파일 실행

  • 해당 폴더에 있는 파일에 접속해서 install.sh 파일을 실행한다.
$ {your_location}/google-cloud-sdk/install.sh
Welcome to the Google Cloud CLI!

To help improve the quality of this product, we collect anonymized usage data
and anonymized stacktraces when crashes are encountered; additional information
is available at <https://cloud.google.com/sdk/usage-statistics>. This data is
handled in accordance with our privacy policy
<https://cloud.google.com/terms/cloud-privacy-notice>. You may choose to opt in this
collection now (by choosing 'Y' at the below prompt), or at any time in the
future by running the following command:

    gcloud config set disable_usage_reporting false

Do you want to help improve the Google Cloud CLI (y/N)? y

Your current Google Cloud CLI version is: 471.0.0
The latest available version is: 472.0.0

┌────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐
│                                                     Components                                                     │
├──────────────────┬──────────────────────────────────────────────────────┬──────────────────────────────┬───────────┤
│      Status      │                         Name                         │              ID              │    Size   │
├──────────────────┼──────────────────────────────────────────────────────┼──────────────────────────────┼───────────┤
│ Update Available │ BigQuery Command Line Tool                           │ bq                           │   1.7 MiB │
│ Update Available │ Google Cloud CLI Core Libraries                      │ core                         │  18.4 MiB │
│ Not Installed    │ App Engine Go Extensions                             │ app-engine-go                │   4.5 MiB │
│ Not Installed    │ Appctl                                               │ appctl                       │  18.5 MiB │
│ Not Installed    │ Artifact Registry Go Module Package Helper           │ package-go-module            │   < 1 MiB │
│ Not Installed    │ Cloud Bigtable Command Line Tool                     │ cbt                          │  16.7 MiB │
│ Not Installed    │ Cloud Bigtable Emulator                              │ bigtable                     │   7.0 MiB │
│ Not Installed    │ Cloud Datastore Emulator                             │ cloud-datastore-emulator     │  36.2 MiB │
│ Not Installed    │ Cloud Firestore Emulator                             │ cloud-firestore-emulator     │  44.8 MiB │
│ Not Installed    │ Cloud Pub/Sub Emulator                               │ pubsub-emulator              │  63.3 MiB │
│ Not Installed    │ Cloud Run Proxy                                      │ cloud-run-proxy              │  11.3 MiB │
│ Not Installed    │ Cloud SQL Proxy v2                                   │ cloud-sql-proxy              │  13.2 MiB │
│ Not Installed    │ Google Container Registry's Docker credential helper │ docker-credential-gcr        │           │
│ Not Installed    │ Kustomize                                            │ kustomize                    │   7.4 MiB │
│ Not Installed    │ Log Streaming                                        │ log-streaming                │  11.9 MiB │
│ Not Installed    │ Minikube                                             │ minikube                     │  33.6 MiB │
│ Not Installed    │ Nomos CLI                                            │ nomos                        │  28.6 MiB │
│ Not Installed    │ On-Demand Scanning API extraction helper             │ local-extract                │  13.7 MiB │
│ Not Installed    │ Skaffold                                             │ skaffold                     │  22.8 MiB │
│ Not Installed    │ Terraform Tools                                      │ terraform-tools              │  63.6 MiB │
│ Not Installed    │ anthos-auth                                          │ anthos-auth                  │  20.7 MiB │
│ Not Installed    │ config-connector                                     │ config-connector             │  55.6 MiB │
│ Not Installed    │ enterprise-certificate-proxy                         │ enterprise-certificate-proxy │   8.3 MiB │
│ Not Installed    │ gcloud Alpha Commands                                │ alpha                        │   < 1 MiB │
│ Not Installed    │ gcloud Beta Commands                                 │ beta                         │   < 1 MiB │
│ Not Installed    │ gcloud app Java Extensions                           │ app-engine-java              │ 126.2 MiB │
│ Not Installed    │ gcloud app PHP Extensions                            │ app-engine-php               │  21.9 MiB │
│ Not Installed    │ gcloud app Python Extensions                         │ app-engine-python            │   5.0 MiB │
│ Not Installed    │ gcloud app Python Extensions (Extra Libraries)       │ app-engine-python-extras     │   < 1 MiB │
│ Not Installed    │ gke-gcloud-auth-plugin                               │ gke-gcloud-auth-plugin       │   7.4 MiB │
│ Not Installed    │ kpt                                                  │ kpt                          │  14.4 MiB │
│ Not Installed    │ kubectl                                              │ kubectl                      │   < 1 MiB │
│ Not Installed    │ kubectl-oidc                                         │ kubectl-oidc                 │  20.7 MiB │
│ Not Installed    │ pkg                                                  │ pkg                          │           │
│ Installed        │ Cloud Storage Command Line Tool                      │ gsutil                       │  11.3 MiB │
│ Installed        │ Google Cloud CRC32C Hash Tool                        │ gcloud-crc32c                │   1.2 MiB │
└──────────────────┴──────────────────────────────────────────────────────┴──────────────────────────────┴───────────┘
To install or remove components at your current SDK version [471.0.0], run:
  $ gcloud components install COMPONENT_ID
  $ gcloud components remove COMPONENT_ID

To update your SDK installation to the latest version [472.0.0], run:
  $ gcloud components update

Modify profile to update your $PATH and enable shell command completion?

Do you want to continue (Y/n)?  y

The Google Cloud SDK installer will now prompt you to update an rc file to bring
 the Google Cloud CLIs into your environment.

Enter a path to an rc file to update, or leave blank to use 
[/Users/evan/.bash_profile]:  
Backing up [/Users/evan/.bash_profile] to [/Users/evan/.bash_profile.backup].
[/Users/evan/.bash_profile] has been updated.

==> Start a new shell for the changes to take effect.

Google Cloud CLI works best with Python 3.11 and certain modules.

Download and run Python 3.11 installer? (Y/n)?  Y
Running Python 3.11 installer, you may be prompted for sudo password...
Password: # your_password
installer: Package name is Python
installer: Upgrading at base path /
installer: The upgrade was successful.
Setting up virtual environment
Creating virtualenv...
Installing modules...
     ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 89.7/89.7 kB 4.6 MB/s eta 0:00:00
  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 59.0/59.0 kB 5.9 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.0/10.0 MB 33.9 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 163.8/163.8 kB 16.1 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 5.3/5.3 MB 42.0 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 176.7/176.7 kB 15.4 MB/s eta 0:00:00
   ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 117.6/117.6 kB 10.4 MB/s eta 0:00:00
  Building wheel for crcmod (pyproject.toml) ... done

Updates are available for some Google Cloud CLI components.  To install them,
please run:
  $ gcloud components update

Virtual env enabled.

For more information on how to get started, please visit:
  https://cloud.google.com/sdk/docs/quickstarts
  • gcloud CLI를 초기화하려면 gcloud init 을 실행한다.
$ ./google-cloud-sdk/bin/gcloud init
Welcome! This command will take you through the configuration of gcloud.

Your current configuration has been set to: [default]

You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.                                            
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

You must log in to continue. Would you like to log in (Y/n)?  Y

Your browser has been opened to visit:

    https://accounts.google.com/o/oauth2/....S256

You are logged in as: [your_email@gmail.com].

Pick cloud project to use: 
 [1] chickenbot-a185e
 [2] encoded-phalanx-420600
 [3] streamlit-gitaction-403105
 [4] streamlit-project-416601
 [5] Enter a project ID
 [6] Create a new project
Please enter numeric choice or text value (must exactly match list item):  2

Screenshot 2024-04-22 at 6.34.04 PM.png

gcloud Installation on Windows 11 - New Configuration

개요

재설치

  • 재설치의 마지막 화면은 다음과 같다.
  • Pick configuration to use, Section에서 2번을 선택한다.

Untitled

  • 이후 CMD 화면이 팝업화가 된다.
Welcome to the Google Cloud CLI! Run "gcloud -h" to get the list of available commands.
---
Welcome! This command will take you through the configuration of gcloud.

Settings from your current configuration [default] are:
accessibility:
  screen_reader: 'True'
compute:
  region: asia-northeast3
  zone: asia-northeast3-a
core:
  account: your_existing@gmail.com
  disable_usage_reporting: 'False'
  project: mulcampfp

Pick configuration to use:
 [1] Re-initialize this configuration [default] with new settings
 [2] Create a new configuration
Please enter your numeric choice:  2
  • 이번에는 Enter configuration name이 있다. 이 때, 접속하고자 하는 [mulcamp-project-abc] 프로젝트를 입력한다.
  • 이 때, 참고하고자 하는 프로젝트 정보에서 Project ID와 매칭되는 것을 선택한다.
Enter configuration name. Names start with a lower case letter and contain only lower case letters a-z, digits 0-9, and
hyphens '-':  mulcamp-project-abc
Your current configuration has been set to: [mulcamp-project-abc]
  • 기존 이메일 주소를 선택하거나 또는 다른 이메일을 선택한다. 필자는 1번으로 선택하였다.
You can skip diagnostics next time by using the following flag:
  gcloud init --skip-diagnostics

Network diagnostic detects and fixes local network connection issues.
Checking network connection...done.
Reachability Check passed.
Network diagnostic passed (1/1 checks passed).

Choose the account you would like to use to perform operations for this configuration:
 [1] your_email@gmail.com
 [2] Log in with a new account
Please enter your numeric choice: 1
  • 로그인 이후에는 기존 이메일 계정에 있는 프로젝트 목록이 활성화 될 것이다.

Untitled

Github Actions with GCE, SSH-Key 값 등록

개요

  • Github Actions 강의 중, 애매한 부분을 정리하였다.
  • Github Actions에 대한 전체 코드는 여기에서 다루지는 않는다.

SSH-Key 값 설정

  • GCE에서 Github와 연동을 위해서는 Key값을 생성해야 한다.
  • 본인의 구글클라우드 이메일을 추가하여 아래와 같이 코드를 실행한다.
  • GCP의 ID와 Github의 이메일 주소가 다른 분들이 있다. 이럴 경우 문제가 발생할 수 있다.
    • 주의 : Github 이메일 주소가 아님
$ ssh-keygen -t rsa -b 4096 -C "your@gmail.com"

Github SSH Key값 생성

  • ssh의 public 키값을 복사한다.
$ cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3...Q== your@gmail.com

Github SSH 등록

  • public key값을 복사하여 아래 SSH and GPG keys 값에 복사한다.

Untitled

BigQuery Connect to Google Analytics

개요

  • BigQuery에서 Google Adwords 데이터와 Google Analytics를 불러올 수 있다.

전제조건

  • 구글 클라우드 사용법은 어느정도 알고 있는 상태를 전제로 한다.
  • Google Analytics를 이미 활용하고 있다는 것을 전제로 한다.

Google Analytics

  • 왼쪽 메뉴에서 관리 > 제품 링크를 확인한다.

Untitled

Untitled

  • BigQuery 링크 클릭 > 연결 버튼을 클릭한다.

Untitled

  • BigQuery 프로젝트를 선택한다.

Untitled

  • 활성화중인 프로젝트를 선택한다.

Untitled

  • 데이터 위치를 지정한다. 본 프로젝트에서는 서울로 명명한다.

Untitled

  • 내보내기 유형은 매일로 선택한다.

Untitled

  • 사용자 데이터는 일별로 선택한다.

Untitled

Streamlit App Deployment Compute Engine with Github Action in GCP

개요

  • Google Compute Engine에서 Gihub Action을 구현하도록 한다.

프로젝트 생성

  • 새 프로젝트 버튼을 클릭 후 프로젝트 명을 streamlit-gitaction으로 명명한다.

Untitled

Instance 생성

  • Compute Engine > VM Instance 선택 후, 새로운 인스턴스를 생성한다.

Untitled

  • 처음 사용하는 경우 사용 버튼을 클릭한다.

Untitled

  • 최초 작업에는 결제 필요 버튼이 나올 수 있다. 결제 사용 설정을 눌러 결제를 추가한다.

Untitled

Untitled

  • 필자는 회사 계정을 사용한 것이므로 이렇게 나오지만, 일반 사용자는 화면이 다를 수 있다.
  • VM 인스턴스를 생성한다.

Untitled

Streamlit App Deployment with nohup in Google Compute Engine

개요

개요

  • Streamlit Sample 코드를 작성한 후 배포를 진행한다.
  • VS Code 접속 시 고정 IP를 할당한다.
  • 이 때 터미널이 종료되거나 사용자가 로그아웃해도 계속 실행되도록 nohup을 사용한다.

Nohup의 기본 개념

  • nohup은 “no hang up"의 약자로, 백그라운드에서 다른 명령을 실행하는 데 사용되는 UNIX 명령으로, 로그아웃한 후에도 계속 실행됨.
  • 원격 서버에서 장기간 실행되는 프로세스를 시작하려는 경우 세션 연결이 끊어지거나 터미널이 닫힐 때 프로세스가 종료되지 않도록 하려는 경우에 특히 유용함.
  • foreground에서 명령이나 프로세스를 실행할 때 터미널이나 셸 세션이 종료되면 해당 명령이나 프로세스가 종료될 수 있다.
  • nohup을 사용하면 기본적으로 터미널에서 프로세스를 분리하고 종료(HUP) 신호를 수신하지 못하도록 하여 로그아웃하거나 연결을 끊어도 프로세스가 완료될 때까지 실행할 수 있다.
  • Python에서 nohup을 실행할 때는 다음과 같다.
    • 출력(로그 및 오류)을 특정 파일로 리디렉션하려면 다음 명령을 사용할 수 있다.
    • 이렇게 하면 Streamlit 앱의 표준 출력과 표준 오류가 모두 streamlit.log라는 파일로 리디렉션 된다.
nohup streamlit run my_app.py > streamlit.log 2>&1 &
  • Streamlit 앱을 중지해야 하는 경우 ps 명령을 사용하여 프로세스 ID를 찾은 다음 종료 명령을 사용하면 된다.
ps aux | grep "streamlit run"
  • 그러면 Streamlit과 관련된 프로세스 목록이 표시된다. 삭제하고자 하는 프로세스 ID를 찾아서 종료한다.
kill -9 PROCESS_ID

고정 IP 할당

  • 왼쪽 사이드바 메뉴 > VPC 네트워크 > IP 주소 클릭한다.

Untitled

Streamlit with Bigquery On Compute Engine

개요

인스턴스 시작

  • 인스턴스가 중지가 되어 있다면 다시 시작을 한다.

Untitled

BigQuery Client 라이브러리 설치

  • 클라이언트 라이브러리를 설치한다.
pip install --upgrade google-cloud-bigquery

Untitled

gcloud Installation on Windows 11

개요

gcloud CLI 최신 버전(445.0.0) 설치

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

Untitled

  • Finish 버튼을 클릭하면 설치는 완료가 된 것이다.

gcloud 연동

  • 위 Finish 버튼과 함께 로그인을 진행한다.

Untitled

  • 인증절차가 시작완료되면 웹 페이지가 변경되고 터미널 환경도 변경된다.

Untitled

  • 현재 필자의 프로젝트는 3번에 해당되기 때문에 3번을 클릭한다.

Untitled