You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:Windows10通过MongoDB Compass连接Ubuntu14 EC2实例失败

Hey there, let's troubleshoot this MongoDB connection issue together—since you can SSH into your EC2 Ubuntu 14 instance without problems, we know the basic network path is working. Let's go through the key checks step by step:

1. Verify MongoDB's Bound IP Address

By default, MongoDB is configured to only listen on 127.0.0.1 (localhost), which means it won't accept connections from outside the instance—even if your security group allows port 27017. Here's how to fix that:

  • SSH into your EC2 instance and open the MongoDB config file. On Ubuntu 14, this is usually either /etc/mongodb.conf or /etc/mongod.conf (depending on how you installed MongoDB).
  • Look for the bind_ip line. Change its value to 0.0.0.0 (to allow connections from any IP) or your Windows 10 machine's public IP (more secure).
  • Restart the MongoDB service to apply changes:
    sudo service mongodb restart
    # Or use this if you're using systemd:
    sudo systemctl restart mongod
    
  • Confirm the binding worked by running:
    netstat -plntu | grep mongod
    
    You should see 0.0.0.0:27017 or your specified IP next to the port.
2. Check EC2 Instance's Local Firewall (iptables)

Ubuntu 14 might have iptables rules blocking incoming traffic on port 27017, even if your AWS security group allows it:

  • List current iptables rules:
    sudo iptables -L -n
    
  • If there's no rule allowing port 27017, add one:
    sudo iptables -A INPUT -p tcp --dport 27017 -j ACCEPT
    
  • Save the rules to make them persistent after reboot:
    sudo mkdir -p /etc/iptables
    sudo iptables-save > /etc/iptables/rules.v4
    
3. Confirm MongoDB is Actually Listening on Port 27017

Sometimes the service shows as "running" but isn't listening correctly. Let's verify:

  • On the EC2 instance, test local connectivity first:
    nc -zv localhost 27017
    # Or use telnet if nc isn't installed:
    telnet localhost 27017
    
    If this fails, check MongoDB's logs for startup errors:
    sudo tail -f /var/log/mongodb/mongodb.log
    
  • Next, test connectivity from the instance to its own public IP:
    nc -zv <your-ec2-public-ip> 27017
    
    If this fails, go back to step 1—your bind IP configuration is still incorrect.
4. Troubleshoot Your Windows 10 Local Machine

Don't rule out issues on your end:

  • Temporarily disable Windows Defender Firewall (just for testing) to see if it's blocking outgoing traffic to port 27017. If that works, add a permanent rule allowing connections to your EC2 instance's IP on port 27017.
  • Test the connection using a tool like MongoDB Compass or the command line:
    mongo "<your-ec2-public-ip>:27017"
    # Add authentication details if enabled:
    mongo "<your-ec2-public-ip>:27017" -u <username> -p <password> --authenticationDatabase admin
    
5. Check for MongoDB Authentication Issues

If you've enabled authentication on MongoDB, some clients might show "MongoDB not running" as a generic error when authentication fails, rather than a specific auth error. To check:

  • SSH into your EC2 instance and open the MongoDB shell:
    mongo
    
  • Switch to the admin database:
    use admin
    
  • List existing users:
    db.getUsers()
    
    If you have users set up, make sure you're including the correct credentials in your connection string from Windows.

内容的提问来源于stack exchange,提问作者Alon

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.20 10:08:00