简体   繁体   English

如何获取正在访问 MongoDB 数据库的 IP 地址?

[英]how to get the the IP address that is accessing MongoDB database?

i need to secure the database to only access request from app server ( backend node.js and express.js)我需要保护数据库以仅访问来自应用服务器的请求(后端 node.js 和 express.js)

when whitelisting the ip address of app server(azure app service linux), it breaks and can not connect.将应用服务器(azure app service linux)的ip地址列入白名单时,它会中断并且无法连接。 i tried to whitelist the web server(frontend react azure app service windows) as well and its not working.我也尝试将 web 服务器(前端反应 azure 应用程序服务窗口)列入白名单,但它不起作用。 when whitelist 0.0.0.0 it works, so the question is what ip is making the request if it is not the app or the web is it the user?当白名单 0.0.0.0 有效时,问题是 ip 发出的请求是否不是应用程序或 web 是用户? and how to obtain that information?以及如何获取这些信息?

thanks谢谢

First, ensure that your firewall blocks all outside IPs except for the IP of your app server and allow access to your database server on port 27017 .首先,确保您的防火墙阻止除应用服务器的 IP 之外的所有外部 IP,并允许在端口27017上访问您的数据库服务器。

Edit your /etc/mongod.conf file.编辑您的/etc/mongod.conf文件。

Ensure these lines appear below # network interfaces确保这些行出现在# network interfaces下面

net: port: 27017 bindIp: 0.0.0.0

You can test your setup by downloading a MongoDB desktop client like Robo 3T and whitelisting your own home/office computer's IP address for your server's firewall on port 27017 .您可以通过下载 MongoDB 桌面客户端(如Robo 3T )并在端口27017上将您自己的家庭/办公室计算机的 IP 地址列入白名单来测试您的设置。

To access your log file to see which IPs are accessing your database, look again at your /etc/mongod.conf file and look for # where to write logging data .要访问您的日志文件以查看哪些 IP 正在访问您的数据库,请再次查看您的/etc/mongod.conf文件并查找# where to write logging data This will be something like /var/log/mongodb/mongod.log这将类似于/var/log/mongodb/mongod.log

You can dump your log file to the terminal with this command:您可以使用以下命令将日志文件转储到终端:

 sudo cat /var/log/mongodb/mongod.log

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM