Google Clound & WSL2 Ubuntu 20.04 개발환경 설정
Page content
개요
GCP
에서 개발환경을 설정하도록 한다.Local PC
에서GCP
로 접속을 하도록 한다.
사전준비
- WSL2 Ubuntu 설치 과정은 여기에서 다루지 않는다.
개발환경 설치
- Python3 설치한다. (본인에게 맞는 언어를 선택한다)
sudo apt update
sudo apt install -y python3 python3-pip
python3
최신 버전(417.0.1) gcloud CLI 설치
- 참고자료 : https://cloud.google.com/sdk/docs/install-sdk?hl=ko
- gcloud CLI를 설치하기 전 운영체제가 다음 요구사항을 충족하는지 확인합니다.
$ sudo apt-get install apt-transport-https ca-certificates gnupg
- 패키지 소스로 gcloud CLI 배포 URI를 추가합니다. 배포판에서 서명 옵션을 지원하는 경우 다음 명령어를 실행합니다.
$ echo "deb [signed-by=/usr/share/keyrings/cloud.google.gpg] https://packages.cloud.google.com/apt cloud-sdk main" | sudo tee -a /etc/apt/sources.list.d/google-cloud-sdk.list
- Google Cloud 공개 키를 가져옵니다. 배포판의
apt-key
명령어가--keyring
인수를 지원하는 경우 다음 명령어를 실행합니다.
$ curl https://packages.cloud.google.com/apt/doc/apt-key.gpg | sudo apt-key --keyring /usr/share/keyrings/cloud.google.gpg add -
- gcloud CLI를 업데이트하고 설치합니다.
$ sudo apt-get update && sudo apt-get install google-cloud-cli
Shell 재시작 후 설치 확인
- 다음 명령어를 통해 설치가 정상적으로 되었는지 확인한다.
$ exec -l $SHELL
$ gcloud version
Google Cloud SDK 419.0.0
alpha 2023.02.17
beta 2023.02.17
bq 2.0.85
bundled-python3-unix 3.9.16
core 2023.02.17
gcloud-crc32c 1.0.0
gsutil 5.20
시작하기
- 시작하려면
[gcloud init](https://cloud.google.com/sdk/gcloud/reference/init?hl=ko)
을 실행합니다.
$ 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
Go to the following link in your browser:
https://accounts.google.com/o/oauth2/auth?response_type=...
Enter authorization code: your_code
You are logged in as: [your_email@gmail.com].
Pick cloud project to use:
[1] Enter a project ID
...
[2] Create a new project
Please enter numeric choice or text value (must exactly match list item):
Your current project has been set to: [your_project_name].
...
Some things to try next:
* Run `gcloud --help` to see the Cloud Platform services you can interact with. And run `gcloud help COMMAND` to get help on any gcloud command.
* Run `gcloud topic --help` to learn about advanced features of the SDK like arg files and output formatting
* Run `gcloud cheat-sheet` to see a roster of go-to `gcloud` commands.
WM 설정
- 아래 화면에서 VM을 선택한다.
- 아래 화면에서
인스턴스 만들기
버튼을 클릭한다.
- 필자는 아래와 같이 생성했다.
- 부팅 디스크는 아래와 같다.
- 방화벽은 모두 허용한다.
Configure the public SSH key
- SSH 키 만들기
ssh-keygen -t rsa -f ~/.ssh/[키이름] -C [gmail계정] -b 2048
- 예시
$ ssh-keygen -t rsa -f ~/.ssh/GCPKEY -C abc@gmail.com -b 2048
Generating public/private rsa key pair.
Created directory '/home/human/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/human/.ssh/gcpkey
Your public key has been saved in /home/human/.ssh/gcpkey.pub
The key fingerprint is:
SHA256:JsI57rMNw0dPFrNKqO6WFODn5teFFMn5EoxEsBhpJ60 abc@gmail.com
The key's randomart image is:
+---[RSA 2048]----+
| .o.+o+ o |
.
.
.
| oo +o. |
+----[SHA256]-----+
- Public Key값 복사하기
$ cd ~/.ssh
~/.ssh$ ls
gcpkey gcpkey.pub
$ cat gcpkey.pub
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQD1ILHQ... abc@gmail.com
- GCP 플랫폼에서 아래와 같이 생성된 키를 붙여 넣는다
로컬 접속
- 이제 ssh 명령어를 통해 접속하도록 한다.
- 이때 첫번째 터미널 줄에 있는
evan~
과 마지막에username
달라진 것을 확인할 수 있다.달라지면 성공
evan@evan:~$ ssh -i ~/.ssh/rsa-gcp-key username@외부IP
The authenticity of host '35.196.103.123 (35.196.103.123)' can't be established.
ED25519 key fingerprint is SHA256:ZGRTENE9HsT1en/GecOuWEYyp9ujidQomjsAnhPCies.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '35.196.103.123' (ED25519) to the list of known hosts.
Welcome to Ubuntu 22.04.1 LTS (GNU/Linux 5.15.0-1029-gcp x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun Feb 26 03:46:18 UTC 2023
System load: 0.0 Processes: 101
Usage of /: 19.4% of 9.51GB Users logged in: 0
Memory usage: 23% IPv4 address for ens4: 10.142.0.2
Swap usage: 0%
* Introducing Expanded Security Maintenance for Applications.
Receive updates to over 25,000 software packages with your
Ubuntu Pro subscription. Free for personal use.
https://ubuntu.com/gcp/pro
Expanded Security Maintenance for Applications is not enabled.
0 updates can be applied immediately.
Enable ESM Apps to receive additional future security updates.
See https://ubuntu.com/esm or run: sudo pro status
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.
username@instance-1:~$
- 만약 접속을 중지하려면
exit
명령어를 추가하면 된다.
username@instance-1:~$ ls
username@instance-1:~$ exit
logout
Connection to 35.196.103.123 closed.
evan@evan:~$
테스트
- 간단하게 로컬 PC에서 생성한 폴더가 GCP 플랫폼에서 확인이 가능한지 테스트를 진행한다.