0
votes

I did install mongodb(3.2.18) on my ubuntu server ( 16.04 ) named automationTaskV3 . It work when i'm working on my server, but when i try to connect from my computer it failed only when mongodb is start as a service.

For example if i start mongod this way :

sudo mongod

it will work i can access my dbs But if i do :

sudo service mongod start

it will be impossible for me to connect from my computer. Otherwise the mongod service status seems ok :

sudo service mongod status

● mongod.service - High-performance, schema-free document-oriented database
   Loaded: loaded (/lib/systemd/system/mongod.service; enabled; vendor preset: enabled)
   Active: active (running) since Thu 2017-11-30 17:34:46 UTC; 8min ago
     Docs: https://docs.mongodb.org/manual
 Main PID: 17712 (mongod)
   CGroup: /system.slice/mongod.service
           └─17712 /usr/bin/mongod --quiet --auth --config /etc/mongod.conf

Nov 30 17:34:46 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database. Nov 30 17:38:09 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database. Nov 30 17:39:29 automationTaskV3 systemd[1]: Started High-performance, schema-free document-oriented database.

For the moment i'm trying to access without credentials. Here my mongod.service file :

[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet  --config /etc/mongod.conf
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false

# Recommended limits for for mongod as specified in
# http://docs.mongodb.org/manual/reference/ulimit/#recommended-settings

[Install]
WantedBy=multi-user.target

and here my mongod.conf file

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
storage:
  dbPath: /var/lib/mongodb
  journal:
    enabled: true
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /var/log/mongodb/mongod.log

# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1


#processManagement:

Is it possible that's a user right problem ? It seems strange as i follow the steps from thoses tutorials : https://www.linode.com/docs/databases/mongodb/install-mongodb-on-ubuntu-16-04 https://docs.mongodb.com/manual/tutorial/install-mongodb-on-ubuntu/

1
binding ip might be the problem, since mongodb conf says binding only to 127.0.0.1 so its is not accessable from outside world i.e. from your local machineAnand Siddharth
Yep thank you so much that was my problem ! And by running the server with " sudo mongod start " i was skipping the conf file so off course this param ! So now i just delete this line and manage the IP access from my firewall !Lowteast

1 Answers

1
votes

As I said in the comment that its the IP binding issue. So you can even try this solution.

You can access the 27017 port of your remote machine by using ssh tunnelling as it is most the easiest way and it's also a secure way.

ssh -L 27017:localhost:27017 [email protected]

This command says forward 27017 port of your local machine to address localhost:27017 of your remote machine. You will be prompted for the password (of remote machine) if you don't have ssh keys set up. Now you might get prompt for ssh of your remote machine don't close it unless you want to close port forwarding, open a new tab of your terminal or Robomongo you can now connect to localhost:27017. So it's like MongoDB is installed on your local machine but actually, it is serving from the remote machine using ssh.

To know more about ssh tunneling read here : https://www.ssh.com/ssh/tunneling