简体   繁体   English

Web服务器实例无法使用AWS EC2 Linux连接到mongodb实例:连接被拒绝

[英]Webserver instance cant connect to mongodb instance using aws ec2 linux: Connection refused

This is the first time using aws and linux. 这是第一次使用aws和linux。

I have setup a webserver with export MONGO_URL=mongodb://localhost:27017/app and its works but when I separate my mongodb into another aws instance and changed the localhost to my mongodb instance private ip address its doesnt works anymore. 我已经设置了带有export MONGO_URL=mongodb://localhost:27017/app的网络服务器及其工作,但是当我将mongodb分离到另一个AWS实例并将localhost更改为我的mongodb实例的私有IP地址时,它不再起作用。

I use telnet private-ip-add 27017 from webserver and it shows Connection refused 我从网络服务器使用telnet private-ip-add 27017 ,它显示Connection refused

I have also set security group inbound on mongodb instance 我还在mongodb实例上设置了安全组入站

Custom TCP Rule TCP 27017 webserver-private-ip-add/31 自定义TCP规则TCP 27017 webserver-private-ip-add / 31

Can anyone help me? 谁能帮我? Thanks! 谢谢!

  1. Double-check the Security Group: Like you said, the EC2 instance must allow incoming TCP connections on port 27017 from either 仔细检查安全组:就像您说的那样,EC2实例必须允许从任一端口27017进入TCP连接

    • the private IP network address other EC2 instance (eg 10.0.0.90/32 ), 其他EC2实例的私有IP网络地址(例如10.0.0.90/32 ),
    • or better, the ID of the Security Group, that belongs to the other (accessing) EC2 instance (eg sg-0d91740cb ). 或更好的是,属于另一个EC2实例(例如sg-0d91740cb )的安全组的ID。
  2. Double-check the MongoDB config file: Option net.bindIp must not be set to 127.0.0.1 but the local IP of your MongoDB EC2 instance. 仔细检查MongoDB配置文件:不得将选项net.bindIp设置为127.0.0.1net.bindIp MongoDB EC2实例的本地IP设置为。 You could also bind to "everything" ( 0.0.0.0 ), but this might be slightly less secure (eg if Security Groups are not set up properly). 您还可以绑定到“所有内容”( 0.0.0.0 ),但这可能会稍微不安全(例如,如果安全组设置不正确)。

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

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