문제 설명
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 Sahli9876、Jose German Perez Sanchez)