Cannot (remote) connect Mac mongo client to Raspberry pi mongod - mongodb

I am running the "default" mongodb on the Rasp Pi. I cannot connect to mongod running on my Raspberry Pi from my Mac running a mongo client. I can connect to the web page (my ip:28017...http://192.168.86.20:28017/). I made all the tweeks on the Raspberry pi I needed to make (opening the ports (results below), modification to mongodb.conf bind_ip parameter (see below).
Why am I not able to connect from my Mac client? Thank you.
The error I get through the mongo client on the Mac is:
$ mongo --host 192.168.86.20
MongoDB shell version v4.2.3
connecting to: mongodb://192.168.86.20:27017/?compressors=disabled&gssapiServiceName=mongodb
2020-02-09T03:56:39.564-0800 E QUERY [js] Error: couldn't connect to server 192.168.86.20:27017, connection attempt failed: SocketException: Error connecting to 192.168.86.20:27017 :: caused by :: Operation timed out :
connect#src/mongo/shell/mongo.js:341:17
#(connect):2:6
2020-02-09T03:56:39.568-0800 F - [main] exception: connect failed
2020-02-09T03:56:39.568-0800 E - [main] exiting with code 1
Version of mongod on Raspberry pi:
> db.version()
2.4.14
version of mongo client on mac:
$ mongo
MongoDB shell version v4.2.0
Raspberry Pi:
$ cat /proc/cpuinfo | grep 'Model'
Model : Raspberry Pi 3 Model B Rev 1.2
Version of Raspbian:
$ cat /etc/os-release
PRETTY_NAME="Raspbian GNU/Linux 10 (buster)"
NAME="Raspbian GNU/Linux"
VERSION_ID="10"
VERSION="10 (buster)"
VERSION_CODENAME=buster
ID=raspbian
ID_LIKE=debian
HOME_URL="http://www.raspbian.org/"
SUPPORT_URL="http://www.raspbian.org/RaspbianForums"
BUG_REPORT_URL="http://www.raspbian.org/RaspbianBugs"
The ports are available:
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:28017 0.0.0.0:* LISTEN -
tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN -
The mongodb.conf bind_ip has been set:
#bind_ip = 127.0.0.1
bind_ip = 0.0.0.0
#port = 27017

Related

Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27

I want to change the default port of mongodb so I did :
sudo nano /etc/mongod.conf
# network interfaces
net:
port: 27042
bindIp: 127.0.0.1
and
sudo service mongod start
But now when I want to run "mongo" I got this error:
MongoDB shell version v4.0.24
connecting to: mongodb://127.0.0.1:27017/?gssapiServiceName=mongodb
2021-05-18T12:44:36.436+0200 E QUERY [js] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
connect#src/mongo/shell/mongo.js:356:17
#(connect):2:6
exception: connect failed
The message says " couldn't connect to server 127.0.0.1:27017" despite I changed the port in mongod.conf. I even tried to reboot my computer but it still not working.
UFW is not active si I don't think it's a firewall problem.
Based on your mongod.conf file, MongoDB will run on port 27042. When you run the command mongo without parameter --port, it will connect to the default port 27017 then you have the error.
I think this command mongo --port 27042 will work.

Unable to start MongoDB shell for mongos daemon

I am trying to setup a sharded mongodb cluster using 4 solaris-11 servers which are on the same rack. The following sharded config is being attempted:
Server A : Replica set 1(rs1)
Server B : Replica Set 2(rs2)
Server C : Configuration Server
Server D : Sharding Router
#
On Server A, rs1 has been set up as follows:
mongod --port 27017 --replSet rs1 --dbpath "/mongo/datadb"
Now the rs1 configuration in mongo shell:
config =
{
_id:"rs1",
members:
[
{ _id:0, host:"Server A IP:27017" },
]
}
rs.initiate( config )
rs.conf()
rs.status()
On Server B , rs2 has been similarly configured.
#
On Server C, the config server has been configured as follows:
mongod --configsvr --port 37017 --dbpath "/rpool/mongo/datadb"
#
Now on Server D, I am running mongos using the following :
mongos --port 27017 --configdb rs1/'Server C IP':37017
When I am trying to open mongo Shell on server D to add the shards using the mongos port and connect to mongos, I am unable to do so. The following error is thrown :
**./mongo --port 27017 --host 'Server C '
MongoDB shell version v3.4.1
connecting to: mongodb://'Server C ip':27017/
2017-11-09T11:21:51.666+0000 W NETWORK [main] Failed to connect to :27017, in(checking socket for error after poll), reason: Connection refused
2017-11-09T11:21:51.686+0000 E QUERY [main] Error: couldn't connect to server 'Server C ip':27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:234:13
#(connect):1:6
exception: connect failed**
When I tried to debug, I found the port 27017 on Server C to be in 'BOUND' state:
netstat -an |grep 27017
*.27017 . 0 0 128000 0 BOUND
'Server ip' stream-ord server ip' 0000000000000000 /tmp/mongodb-27017.sock
Shouldn't mongos occupy this port in Listening mode? Can someone help me in solving this?
Is there any issue with the configuration?

connecting to mongodb with ipv6 via mongo shell

I was able to enable ipv6 on mongodb.
/etc/mongod.conf file has net.ipv6 set to true.
I can see that mongodb is listening on ipv6:
# netstat -anp | grep 27017
tcp 0 0 0.0.0.0:27017 0.0.0.0:* LISTEN 17967/mongod
tcp6 0 0 :::27017 :::* LISTEN 17967/mongod
unix 2 [ ACC ] STREAM LISTENING 19750206 17967/mongod /tmp/mongodb-27017.sock
#
ping6 to the IPv6 address is fine.
[root#tesla05 log]# ping6 -I eno33554952 tesla05-2-ipv6.ulticom.com
PING tesla05-2-ipv6.ulticom.com(tesla05) from fe80::250:56ff:feb4:7c43 eno33554952: 56 data bytes
64 bytes from tesla05: icmp_seq=1 ttl=64 time=0.101 ms
64 bytes from tesla05: icmp_seq=2 ttl=64 time=0.093 ms
64 bytes from tesla05: icmp_seq=3 ttl=64 time=0.091 ms
however, mongo shell doesn't seem to understand ipv6 address.
[root#tesla05 log]# mongo --ipv6 [fe80::250:56ff:feb4:7c43]:27017/admin
MongoDB shell version: 3.2.4
connecting to: [fe80::250:56ff:feb4:7c43]:27017/admin
2016-10-25T12:04:50.401-0400 W NETWORK [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:04:50.402-0400 E QUERY [thread1] Error: couldn't connect to server [fe80::250:56ff:feb4:7c43]:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
[root#tesla05 log]# mongo --ipv6 tesla05-2-ipv6.ulticom.com:27017/admin
MongoDB shell version: 3.2.4
connecting to: tesla05-2-ipv6.ulticom.com:27017/admin
2016-10-25T12:15:17.861-0400 W NETWORK [thread1] Failed to connect to fe80::250:56ff:feb4:7c43:27017, reason: errno:22 Invalid argument
2016-10-25T12:15:17.861-0400 E QUERY [thread1] Error: couldn't connect to server tesla05-2-ipv6.ulticom.com:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:226:14
#(connect):1:6
exception: connect failed
You are trying to use a link-local IPv6 address. These are not valid without a scope, but you haven't provided one. Thus you get the error Invalid argument. For this reason, putting a link-local address in the DNS makes no sense, because the address is only valid on a particular LAN, and the scope may be different for every host on that LAN.
To use the address, append the scope to it, e.g. fe80::250:56ff:feb4:7c43%eno33554952

Mongo can't connect to remote instance

I installed mongodb on remote server via vagrant. I can access postgres from my local system but mongo is not available. When I login via ssh and check mongo status it says that mongo running, I can make queries too. When I try to connect from my local system using this command:
mongo 192.168.192.168:27017
I get an error
MongoDB shell version: 2.6.5
connecting to: 192.168.192.168:27017/test
2014-12-27T22:19:19.417+0100 warning: Failed to connect to 192.168.192.168:27017, reason: errno:111 Connection refused
2014-12-27T22:19:19.418+0100 Error: couldn't connect to server 192.168.192.168:27017 (192.168.192.168), connection attempt failed at src/mongo/shell/mongo.js:148
exception: connect failed
looks like mongo not listen to connection from other ips? I commented bind_ip in mongo settings but it doesn't help.
services for 192.168.192.168 via nmap command:
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
111/tcp open rpcbind
5432/tcp open postgresql
9000/tcp open cslistener
Looks like mongd listen
sudo lsof -iTCP -sTCP:LISTEN | grep mongo
mongod 1988 mongodb 6u IPv4 5407 0t0 TCP *:27017 (LISTEN)
mongod 1988 mongodb 8u IPv4 5411 0t0 TCP *:28017 (LISTEN)
Firewall rules
sudo iptables -L -n
Chain INPUT (policy ACCEPT)
target prot opt source destination
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
Update
My mongo config
dbpath=/var/lib/mongodb
#where to log
logpath=/var/log/mongodb/mongodb.log
logappend=true
#bind_ip = 127.0.0.1
#port = 27017
# Enable journaling, http://www.mongodb.org/display/DOCS/Journaling
journal=true
# Enables periodic logging of CPU utilization and I/O wait
#cpu = true
# Turn on/off security. Off is currently the default
#noauth = true
#auth = true
Solution is to change mongo configuration
bind_ip = 0.0.0.0

mongo displays error on MAMP

I have followed this after installing Mongo on Mac.
On php.ini shows mongo details.
mongo
MongoDB Support enabled
Version 1.0.11
Directive Local Value Master Value
mongo.allow_empty_keys 0 0
mongo.allow_persistent 1 1
mongo.auto_reconnect 1 1
mongo.chunk_size 262144 262144
mongo.cmd $ $
mongo.default_host localhost localhost
mongo.default_port 27017 27017
mongo.long_as_object 0 0
mongo.native_long 0 0
mongo.utf8 1 1
But when I type mongo on a terminal it displays the following error.
sokada-macbook:bin sokada$ mongo
MongoDB shell version: 2.0.6
connecting to: test
Thu Jun 14 21:54:47 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
exception: connect failed
I thank you in advance to solve this problem.
I needed to run the following in the terminal.
sudo mkdir -p /data/db
sudo chown `id -u` /data/db
Then I run mongo and give the following.
sokada-macbook:~ sokada$ mongo
MongoDB shell version: 2.0.6
connecting to: test
>
It looks like you have successfully installed the Mongo support for PHP, but haven't started the actual mongod server yet.
In the tutorial you followed, that would be Step 4. Create Startup Routines for MAMP.