Google Cloud Function / MongoDB VM 인스턴스 통신 (Google Cloud Function / MongoDB VM instance communication)


문제 설명

Google Cloud Function / MongoDB VM 인스턴스 통신 (Google Cloud Function / MongoDB VM instance communication)

독일 부동산 사이트 immobilienscout24.de를 스크랩하는 클라우드 기능이 있습니다. 이 결과는 Google 클라우드 VM 인스턴스에서 호스팅되는 mongoDB 데이터베이스에 저장되어야 합니다. 현재로서는 GET 요청 응답을 통해 결과를 보내고 있는데, 물론 최적은 아닙니다. Python 클라우드 기능을 사용하여 원격으로 mongoDB VM 인스턴스에 데이터를 삽입하려면 어떻게 해야 합니까? 서로 다른 VM이 서로 원격으로 통신하도록 하려면 어떻게 해야 합니까? 또한 스크레이퍼 기능을 여러 개의 작은 기능으로 분할하고 싶기 때문에 클라우드 기능도 서로 통신할 수 있는 방법이 필요합니다. 저는 웹 개발, API, TCP/IP 등에 대한 경험이 거의 없으므로 귀하의 답변에 매우 자세히 설명해 주십시오. 클라우드 VM에서 PyMongo와 Python3.5를 사용합니다. 요약하자면 클라우드 기능이 VM 인스턴스(MongoDB, 다른 python 스크립트) 및 다른 클라우드 기능 및 VM과도 함께 사용할 수 있습니다. 감사합니다!

mygoogleusername@mongodb‑1‑servers‑vm‑0:~$ ip a | grep net
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
inet 10.156.0.5/32 brd 10.156.0.5 scope global eth0
inet6 fe80::4001:aff:fe9c:5/64 scope link 
mygoogleusername@mongodb‑1‑servers‑vm‑0:~$ id
uid=1000(mygoogleusername) gid=1001(mygoogleusername) groups=1001(mygoogleusername),4(adm),30(dip),44(video),46(plugdev),1000(google‑sudoers)
mygoogleusername@mongodb‑1‑servers‑vm‑0:~$ mongo
MongoDB shell version v4.0.27
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("d0d59151‑aea7‑4392‑8d81‑b00387876908") }
MongoDB server version: 4.0.23
Server has startup warnings: 
2021‑10‑01T17:41:56.763+0000 I CONTROL  [initandlisten] 
2021‑10‑01T17:41:56.763+0000 I CONTROL  [initandlisten] ** WARNING: Access control is not enabled for the database.
2021‑10‑01T17:41:56.763+0000 I CONTROL  [initandlisten] **          Read and write access to data and configuration is unrestricted.
2021‑10‑01T17:41:56.763+0000 I CONTROL  [initandlisten] 
‑‑‑
Enable MongoDB's free cloud‑based monitoring service, which will then receive and display
metrics about your deployment (disk utilization, CPU, operation statistics, etc).

The monitoring data will be available on a MongoDB website with a unique URL accessible to you
and anyone you share the URL with. MongoDB may use this information to make product
improvements and to suggest MongoDB products and deployment options to you.

To enable free monitoring, run the following command: db.enableFreeMonitoring()
To permanently disable this reminder, run the following command: db.disableFreeMonitoring()

참조 솔루션

방법 1:

FIR Response:

Here is MongoDB with Python documentation that could help you on how to insert data: https://www.mongodb.com/developer/quickstart/python‑quickstart‑crud/

Follow the documentation steps to use cloud firestore for your code: https://firebase.google.com/docs/firestore/quickstart

To connect the DB here is a code example that could help you:

import db from ‘./firebase/config’;

const usuario = {
     name: ‘name’,
     active: true or false,
     id : 1
    }
//insert into usuarios …

db.collection(`users`)
    .add( user )

After that, the user should be on your database, adding an ID for each one.

The second question on how to communicate VM instances with each other, here is a documentation that could also help you: https://cloud.google.com/vpc/docs/special‑configurations

Install Squid on gateway‑instance, and configure it to allow access from any machines on the VPC network (valid subnet IP addresses). This assumes that gateway‑instance and hidden‑instance are both connected to the same VPC network, which enables them to connect to each other. user@gateway‑instance:~$ sudo apt‑get install squid3

Enable any machine on the local network to use the Squid3 server. The following sed commands uncomment and enable the acl localnet src entries in the Squid config files for local networks and machines. Squid link: http://www.squid‑cache.org/

(by Sahli9876Jose German Perez Sanchez)

참조 문서

  1. Google Cloud Function / MongoDB VM instance communication (CC BY‑SA 2.5/3.0/4.0)

#google-cloud-platform #Python #google-cloud-functions #mongoDB






관련 질문

Google API용 Android 키 사용 제한 (Restricting usage for an Android key for a Google API)

GCS 버킷에서 큰 폴더를 삭제하는 빠른 방법 (Fast way to delete big folder on GCS bucket)

Terraform 코드와 충돌하는 "소유자"에 의한 GCP 콘솔/클라우드 셸 변경을 어떻게 방지할 수 있습니까? (How can you prevent GCP console/cloud shell changes by "Owners" conflicting with the terraform code?)

서비스 계정으로 인증할 때 project_id를 명시적으로 설정하는 것을 피할 수 있습니까? (Is it possible to avoid setting project_id explicitly when authing with service account?)

Wordpress가 새 PHP 버전을 감지하지 못합니다 (Wordpress doesn't detect new php version)

카운터를 사용하여 테이블에 삽입된 레코드 수를 계산하고 python 스크립트를 사용하여 실행되는 각 작업에서 삽입된 레코드 수를 인쇄하는 방법 (How to count number of inserted records in table using counter and print the count of inserted record in each job run using python script)

Google Cloud 자연어 가져오기 오류 (Google Cloud Natural Language Import Error)

gcloud는 전체 컨테이너를 다시 빌드하지만 Dockerfile은 동일하고 스크립트만 변경됨 (gcloud rebuilds complete container but Dockerfile is the same, only the script has changed)

GCP를 통한 Kubernetes 대시보드 (Kubernetes dashboard via GCP)

Firebase 실시간 데이터베이스 키 없이 하위 레코드를 얻는 방법 (Firebase realtime database how to get a child record without the key)

Google Cloud Function / MongoDB VM 인스턴스 통신 (Google Cloud Function / MongoDB VM instance communication)

Google Artifact Registry에서 도커 풀 수를 추적할 수 있습니까? (Is it possible track the number of docker pulls in Google Artifact Registry?)







코멘트