Google云功能/MongoDB虚拟机实例通信

2024-09-30 18:24:03 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个云功能,可以刮去德国房地产网站immobilienscout24.de。此操作的结果应保存在托管在google cloud VM实例上的mongoDB数据库中。 目前,我通过GET请求响应发送结果,这当然不是最优的。如何使用python云函数将数据远程插入mongoDB VM实例?如何让不同的虚拟机彼此远程通信? 我还想将scraper函数拆分为多个较小的函数,因此我需要一种云函数相互通信的方式。我在Web开发、API、TCP/IP等方面的经验很少,所以请在回答中详细说明。我在云虚拟机上使用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()

Tags: andtheto实例函数远程mongodbvm
1条回答
网友
1楼 · 发布于 2024-09-30 18:24:03

FIR响应:

以下是MongoDBPython文档,可以帮助您插入数据: https://www.mongodb.com/developer/quickstart/python-quickstart-crud/

按照文档步骤为代码使用cloud firestorehttps://firebase.google.com/docs/firestore/quickstart

要连接数据库,下面是一个代码示例,可以帮助您:

import db from ‘./firebase/config’;

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

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

之后,用户应该在您的数据库中,为每个数据库添加一个ID

关于如何相互通信VM实例的第二个问题,这里的文档也可以帮助您: https://cloud.google.com/vpc/docs/special-configurations

Install Squid上的gateway-instance,并将其配置为允许从VPC网络上的任何计算机进行访问(有效子网IP地址)。这假设网关实例和隐藏实例都连接到同一VPC网络,这使它们能够相互连接。 user@gateway-实例:~$sudo apt get install squid3

允许本地网络上的任何计算机使用Squid3服务器。以下sed命令取消注释并启用本地网络和计算机的Squid配置文件中的acl localnet src条目。 Squid链接:http://www.squid-cache.org/

相关问题 更多 >