Remotely connecting to MongoDB http interface on EC2 server

后端 未结 4 612
一个人的身影
一个人的身影 2020-12-15 10:46

I cannot connect remotely to my mongodb http interface on my AWS ec2 server.

I\'ve checked the log and verified that it\'s listening on port 28017. I\'ve verified w

相关标签:
4条回答
  • 2020-12-15 11:20

    Sounds like there's something wrong with your security group settings. You could try accessing the admin interface from the box itself:

    curl http://localhost:28017/
    

    If you get content back, then you've probably got a problem with your security group settings (or the firewall on the box itself).

    0 讨论(0)
  • 2020-12-15 11:29

    For you EC2 instance, add two inbound custom TCP rules to allow inbound traffic on ports 27017 and 28017.

    Make sure to comment out the “bind_ip = 127.0.0.1” in the /etc/mongod.conf file

    restart mongod server: $sudo service mongod restart

    0 讨论(0)
  • 2020-12-15 11:30

    Did you check it's listening on a public IP as well as that port? It may be listening on localhost.

    0 讨论(0)
  • 2020-12-15 11:34

    I had a similar problem trying to access the mongo shell remotely, and several of these answers helped with parts of the solution. To summarize:

    • Public IP/DNS: Select your instance on the EC2 Management Console and make sure it has a Public IP or Public DNS. AWS is moving more of the defaults to live within a Virtual Private Cloud (VPC), and it's possible to launch into one with only a Private IP address (internal to the VPC). If you don't have a Public DNS or IP, you need to allocate an Elastic IP.

    • Security Group ports: Again looking at instance details on the EC2 Console, find the Security Groups and select "View Rules". Assuming you're using default Mongo ports, you should have 27017 and 28017 open for TCP from 0.0.0.0/0 or (more secure) from your IP address. If not, select a Security Group for your instance and from the console go to Inbound > Edit > Add Rule > Custom TCP Rule, Port Range: 27017, and an appropriate IP Source. For http interface, add another rule for Port Range: 28017.

    • /etc/mongod.conf:

      • Uncomment port=27017 to make sure you have the default port (I don't think this is actually necessary, but it made me feel better and it's good to know where to change the default port...)
      • Comment out bind_ip=127.0.0.1 in order to listen to external interfaces (e.g. remote connections)
      • Uncomment httpinterface=true if you want to use the http interface
    • Create User: You need to create an admin and/or user to access the database remotely.

    0 讨论(0)
提交回复
热议问题