Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't connect using mongo from vagrant instance. #109

Open
jondkelley opened this issue May 29, 2018 · 3 comments
Open

Can't connect using mongo from vagrant instance. #109

jondkelley opened this issue May 29, 2018 · 3 comments

Comments

@jondkelley
Copy link

I've validated I can telnet to the port I've forwarded from vagrant (localhost:27018) but the mongo client hangs trying to connect using mongo --host 127.0.0.1 --port 27018. This is also true using mongohub.

Vagrantfile port forward

config.vm.network "forwarded_port", guest: 27017, host: 27018

On parent host:

MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27018/

Inside vagrant vm:

[root@localhost vagrant]# mongo --host 127.0.0.1 --port 27017
MongoDB shell version v3.6.5
connecting to: mongodb://127.0.0.1:27017/
MongoDB server version: 3.6.5
Welcome to the MongoDB shell.
For interactive help, type "help".

Here's my vars, I'm assuming mongodb_security_authorization: "disabled" is the relevant bits to allow unauthorized remote access.

The vars, run against Centos6 vm:

vars:
  mongodb_package: mongodb-org
  mongodb_version: "3.6"
  mongodb_pymongo_from_pip: true
  mongodb_user_update_password: "on_create"
  mongodb_manage_service: true
  mongodb_net_bindip: 127.0.0.1
  mongodb_net_http_enabled: false
  mongodb_net_ipv6: false
  mongodb_net_maxconns: 65536
  mongodb_net_port: 27017
  mongodb_processmanagement_fork: false
  mongodb_security_authorization: "disabled"
  mongodb_storage_dbpath: /var/lib/mongo
  mongodb_storage_engine: mmapv1
  mongodb_storage_quota_enforced: false
  mongodb_storage_quota_maxfiles: 8
  mongodb_storage_smallfiles: true
  mongodb_storage_journal_enabled: true
  mongodb_storage_prealloc: true
  mongodb_systemlog_destination: "file"
  mongodb_systemlog_logappend: true
  mongodb_systemlog_path: /var/log/mongodb/{{ mongodb_daemon_name }}.log
  mongodb_replication_replset: xxx
  mongodb_replication_replindexprefetch: "all"
  mongodb_replication_oplogsize: 1024
  mongodb_set_parameters: { "enableLocalhostAuthBypass": "true", "authenticationMechanisms": "SCRAM-SHA-1,MONGODB-CR" }
  mongodb_mms_agent_pkg: https://cloud.mongodb.com/download/agent/automation/mongodb-mms-automation-agent-manager-latest.x86_64.rpm
  mongodb_mms_group_id: "xxx"
  mongodb_mms_api_key: "xxx"
  mongodb_mms_base_url: https://mms.mongodb.com
  mongodb_logrotate: true
  mongodb_logrotate_options:
    - compress
    - copytruncate
    - daily
    - dateext
    - rotate 7
    - size 10M
  mongodb_user_admin_name: useradmin
  mongodb_user_admin_password: "xxx"
  mongodb_root_admin_name: root
  mongodb_root_admin_password: "xxx"
@sivaprasad-ee
Copy link

I am also facing same issue. I provisioned MongoDB using this ansible role on an AWS EC2 instance, I can ssh into the EC2 instance and see that MongoDB is up and running. But when I try to remotely connect from my localhost using mongo mongodb://[ip-address]:27017 I am getting the follow error:

MongoDB shell version v4.2.6
connecting to: mongodb://[ip-address]:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-05-05T11:15:42.527+0530 E  QUERY    [js] Error: couldn't connect to server [ip-address]:27017, connection attempt failed: SocketException: Error connecting to [ip-address]:27017 :: caused by :: Connection refused :
connect@src/mongo/shell/mongo.js:341:17
@(connect):2:6
2020-05-05T11:15:42.530+0530 F  -        [main] exception: connect failed
2020-05-05T11:15:42.530+0530 E  -        [main] exiting with code 1

@sivaprasad-ee
Copy link

Just figured out the issue.

With mongodb_net_bindip=127.0.0.1 mongodb can be connected from same host only. To enable connecting from remote(any) host set mongodb_net_bindip=0.0.0.0.

@priyanka1628
Copy link

priyanka1628 commented Jan 22, 2021

hi, i have set mongodb_net_bindip=0.0.0.0, still it says

"module_stdout": "Traceback (most recent call last):\r\n File "/tmp/ansible_fUwl0K/ansible_module_mongodb_replication.py", line 466, in \r\n main()\r\n File "/tmp/ansible_fUwl0K/ansible_module_mongodb_replication.py", line 425, in main\r\n client['admin'].command('replSetInitiate', config)\r\n File "/home/ubuntu/.local/lib/python2.7/site-packages/pymongo/database.py", line 611, in command\r\n read_preference) as (sock_info, slave_ok):\r\n File "/usr/lib/python2.7/contextlib.py", line 17, in enter\r\n return self.gen.next()\r\n File "/home/ubuntu/.local/lib/python2.7/site-packages/pymongo/mongo_client.py", line 1099, in _socket_for_reads\r\n server = topology.select_server(read_preference)\r\n File "/home/ubuntu/.local/lib/python2.7/site-packages/pymongo/topology.py", line 224, in select_server\r\n address))\r\n File "/home/ubuntu/.local/lib/python2.7/site-packages/pymongo/topology.py", line 183, in select_servers\r\n selector, server_timeout, address)\r\n File "/home/ubuntu/.local/lib/python2.7/site-packages/pymongo/topology.py", line 199, in _select_servers_loop\r\n self._error_message(selector))\r\npymongo.errors.ServerSelectionTimeoutError: 0.0.0.0:27017: [Errno 111] Connection refused\r\n",
"msg": "MODULE FAILURE",
"rc": 1

can you please help with this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants