Mongo Shell from local is not getting connected to mongo server running in docker - mongodb

I ran mongo server in docker and the logs came up just fine.
2019-04-12T10:39:51.334+0000 I CONTROL [initandlisten] MongoDB starting : pid=1 port=27017 dbpath=/data/db 64-bit host=8a03346e57d7
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] db version v3.2.22
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] git version: 105acca0d443f9a47c1a5bd608fd7133840a58dd
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] allocator: tcmalloc
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] modules: none
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] build environment:
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distmod: rhel70
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] distarch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] target_arch: x86_64
2019-04-12T10:39:51.335+0000 I CONTROL [initandlisten] options: { net: { port: 27017 }, processManagement: { pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/data/db" } }
2019-04-12T10:39:51.339+0000 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),checkpoint=(wait=60,log_size=2GB),statistics_log=(wait=0),verbose=(recovery_progress),
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten] ** WARNING: You are running this process as the root user, which is not recommended.
2019-04-12T10:39:51.389+0000 I CONTROL [initandlisten]
2019-04-12T10:39:51.406+0000 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2019-04-12T10:39:51.406+0000 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/data/db/diagnostic.data'
2019-04-12T10:39:51.406+0000 I NETWORK [initandlisten] waiting for connections on port 27017
But, while connecting the mongodb server from local shell, the connection is getting timedout.
~/mongodb/bin/mongo --host 172.17.0.2
MongoDB shell version v3.6.11
connecting to: mongodb://172.17.0.2:27017/?gssapiServiceName=mongodb
2019-04-12T16:04:45.750+0530 W NETWORK [thread1] Failed to connect to 172.17.0.2:27017 after 5000ms milliseconds, giving up.
2019-04-12T16:04:45.753+0530 E QUERY [thread1] Error: couldn't connect to server 172.17.0.2:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:263:13
#(connect):1:6
exception: connect failed
where 172.17.0.2 is the IP obtained by running docker inspect <container-id
I was able to connect mongo shell with in the docker using the command docker exec --it <container-id> bash.
Here's the Docker file for refrence.
RUN echo -e "\
[mongodb]\n\
name=MongoDB Repository\n\
baseurl=https://repo.mongodb.org/yum/redhat/7Server/mongodb-org/3.2/x86_64/\n\
gpgcheck=0\n\
enabled=1\n" >> /etc/yum.repos.d/mongodb.repo
# Install mongodb
RUN yum update -y && yum install -y mongodb-org
# Set up directory requirements
RUN mkdir -p /data/db /var/log/mongodb /var/run/mongodb
VOLUME ["/data/db", "/var/log/mongodb"]
# Expose port 27017 from the container to the host
EXPOSE 27017
# Start mongodb
ENTRYPOINT ["/usr/bin/mongod"]
CMD ["--port", "27017", "--dbpath", "/data/db", "--pidfilepath", "/var/run/mongodb/mongod.pid"]
Let me know if I am missing something.
Using MacOS

Related

Problem running mongod with run-rs. Windows10

C:\Users\Ashwin Bordoloi> run-rs --mongod --keep --dbpath D:\MongoDB\Server\4.2\data
Skipping purge
Running 'mongod' [ 27017, 27018, 27019 ]
Restarting replica set...
Error: failed to start mongod with options [
'--port=27019',
'--dbpath=D:\\MongoDB\\Server\\4.2\\data\\27019',
'--bind_ip=ashwin1014',
'--replSet=rs'
]
2020-04-16T01:16:28.926+0530 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2020-04-16T01:16:28.929+0530 W ASIO [main] No TransportLayer configured during NetworkInterface startup
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] MongoDB starting : pid=21056 port=27019 dbpath=D:\MongoDB\Server\4.2\data\27019 64-bit host=ashwin1014
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] db version v4.2.5
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] git version: 2261279b51ea13df08ae708ff278f0679c59dc32
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] allocator: tcmalloc
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] modules: none
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] build environment:
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] distmod: 2012plus
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] distarch: x86_64
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] target_arch: x86_64
2020-04-16T01:16:28.930+0530 I CONTROL [initandlisten] options: { net: { bindIp: "ashwin1014", port: 27019 }, replication: { replSet: "rs" }, storage: { dbPath: "D:\MongoDB\Server\4.2\data\27019" } }
2020-04-16T01:16:28.935+0530 E STORAGE [initandlisten] Failed to set up listener: SocketException: An attempt was made to access a socket in a way forbidden by its access permissions.
2020-04-16T01:16:28.936+0530 I CONTROL [initandlisten] now exiting
2020-04-16T01:16:28.936+0530 I CONTROL [initandlisten] shutting down with code:48
at ChildProcess.<anonymous> (C:\Users\Ashwin Bordoloi\AppData\Roaming\npm\node_modules\run-rs\node_modules\mongodb-topology-manager\lib\server.js:404:15)
at ChildProcess.emit (events.js:321:20)
at maybeClose (internal/child_process.js:1026:16)
at Process.ChildProcess._handle.onexit (internal/child_process.js:286:5)
since MongoDb local environment does not allow transactions, i used run-rs to run a replicaSet. However if i use run-rs i get an error "Failed to start mongod wih options"
MongoDB is shutting down with error code 48, it seems like the resources are already consumed.
run
netstat -a -n | find "27019"
and check if port 27019 is already used
TCP 0.0.0.0:27019 0.0.0.0:0 LISTENING
Kill the process on that port and restart the mongo.

[Error]MongoDB not starting

Im trying to start mongodb it returns me this error, i already tried to repair mongo reinstall using brew uninstalling and installing again and nothing happens.
This problem occurred after Mac OS High Sierra Update.
Here's the error:
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] MongoDB starting : pid=11915 port=27017 dbpath=/data/db 64-bit host=Luizs-MacBook-Pro.local
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] db version v3.4.9
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] git version: 876ebee8c7dd0e2d992f36a848ff4dc50ee6603e
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2l 25 May 2017
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] allocator: system
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] modules: none
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] build environment:
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] distarch: x86_64
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] target_arch: x86_64
2017-09-27T20:55:54.834-0300 I CONTROL [initandlisten] options: {}
2017-09-27T20:55:54.835-0300 E NETWORK [initandlisten] listen(): bind() failed No such file or directory for socket: /tmp/mongodb-27017.sock
2017-09-27T20:55:54.836-0300 E NETWORK [initandlisten] Failed to set up sockets during startup.
2017-09-27T20:55:54.836-0300 E STORAGE [initandlisten] Failed to set up listener: InternalError: Failed to set up sockets
2017-09-27T20:55:54.836-0300 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-09-27T20:55:54.836-0300 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-09-27T20:55:54.836-0300 I CONTROL [initandlisten] now exiting
2017-09-27T20:55:54.836-0300 I CONTROL [initandlisten] shutting down with code:48
What i already tried:
mongod --dbpath /data/db --repair
rm -rf /tmp/mongodb-27017.sock
rm -rf /data/db
Try :
1: sudo mongod --dbpath /data/db
Replace /data/db by your mongodb location same as :
sudo mongod --dbpath /var/lib/mongodb
2: Check Port Status
sudo netstat -tlnp | grep 27017
netstat -an |grep 27017
3: Kill ID
sudo killall mongod
sudo killall -15 mongod
sudo kill < Process ID >

MongoDB: Failed to set up sockets during startup

I have Windows 8.1 Enterprise 64 bit machine. I have installed mongodb msi for windows with SSL support. I created all the perquisites required for environment setup. Now using command prompt I navigated to the bin directory present into the mongodb installation folder and executed the following command:
mongod.exe --dbpath "c:\data"
And I see the following response:
C:\mongodb\bin>mongod.exe --dbpath "c:\data"
2016-05-27T17:09:43.362+0530 I CONTROL [initandlisten] MongoDB starting : pid=2
108 port=27017 dbpath=C:\data\db\ 64-bit host=TestServer
2016-05-27T17:09:43.363+0530 I CONTROL [initandlisten] targetMinOS: Windows 7/W
indows Server 2008 R2
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] db version v3.2.6
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] git version: 05552b562c7
a0b3143a729aaa0838e558dc49b25
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL
1.0.1p-fips 9 Jul 2015
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] modules: none
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] build environment:
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] distmod: 2008plus-ss
l
2016-05-27T17:09:43.364+0530 I CONTROL [initandlisten] distarch: x86_64
2016-05-27T17:09:43.365+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-05-27T17:09:43.365+0530 I CONTROL [initandlisten] options: {}
2016-05-27T17:09:43.365+0530 E NETWORK [initandlisten] listen(): bind() failed
errno:10048 Only one usage of each socket address (protocol/network address/port
) is normally permitted. for socket: 0.0.0.0:27017
2016-05-27T17:09:43.366+0530 E STORAGE [initandlisten] Failed to set up sockets
during startup.
2016-05-27T17:09:43.366+0530 I CONTROL [initandlisten] dbexit: rc: 48
Can anyone please help me to how to fix this issue.
run
netstat -a -n | find "27017"
and chek if port 27017 is already used
F:\data\bin> netstat -a -n | find "27017"
TCP 0.0.0.0:27017 0.0.0.0:0 LISTENING
or run taskmgr and find and kill all mongod processes

Fatal Assertion in MongoDB

I have been uninstalling and reinstalling Mongodb on Ubuntu 14.04 following the official documentation for few times now. However, I keep getting this:
2015-12-22T12:46:32.091+0000 I CONTROL ***** SERVER RESTARTED *****
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] MongoDB starting : pid=7039 port=27017 dbpath=/var/lib/mongodb 64-bit host=server-04
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] db version v3.0.8
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] git version: 83d8cc25e00e42856924d84e220fbe4a839e605d
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] build info: Linux ip-10-187-89-126 3.13.0-24-generic #46-Ubuntu SMP Thu Apr 10 19:11:08 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] allocator: tcmalloc
2015-12-22T12:46:32.096+0000 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, syste$
2015-12-22T12:46:32.120+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock errno:1 Operation not permitted
2015-12-22T12:46:32.120+0000 I - [initandlisten] Fatal Assertion 28578
2015-12-22T12:46:32.120+0000 I - [initandlisten]
***aborting after fassert() failure
I am expecting to see: [initandlisten] waiting for connections on port <port> but can't see it. What can cause it?
remove everything from /tmp directory
sudo rm -rf /tmp/mongod*.sock
change the ownership of the db path and log path
chown -R mongodb:mongodb /var/lib/mongodb/
chown -R mongodb:mongodb /var/log/monogdb/
restart your mongo
sudo service mongod start

MongoDB centos7 unable to run with a non standard port as a service

I installed mongodb on a fresh centos 7
I run sudo service mongod start without any problem
When I change the port in /etc/mongod.conf and I restart the mongod service I get the following error
From /var/log/mongodb/mongod.log
2014-11-11T07:38:29.495+0000 [initandlisten] MongoDB starting : pid=12401 port=27022 dbpath=/var/lib/mongo 64-bit host=awscm001
2014-11-11T07:38:29.495+0000 [initandlisten] db version v2.6.5
2014-11-11T07:38:29.495+0000 [initandlisten] git version: e99d4fcb4279c0279796f237aa92fe3b64560bf6
2014-11-11T07:38:29.495+0000 [initandlisten] build info: Linux build8.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-11-11T07:38:29.495+0000 [initandlisten] allocator: tcmalloc
2014-11-11T07:38:29.495+0000 [initandlisten] options: { config: "/etc/mongod.conf", net: { port: 27021 }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/var/lib/mongo" }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2014-11-11T07:38:29.497+0000 [initandlisten] journal dir=/var/lib/mongo/journal
2014-11-11T07:38:29.497+0000 [initandlisten] recover : no journal files present, no recovery needed
2014-11-11T07:38:29.679+0000 [initandlisten] ERROR: listen(): bind() failed errno:13 Permission denied for socket: 0.0.0.0:27022
2014-11-11T07:38:29.680+0000 [initandlisten] now exiting
2014-11-11T07:38:29.680+0000 [initandlisten] dbexit:
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to close listening sockets...
2014-11-11T07:38:29.680+0000 [initandlisten] shutdown: going to flush diaglog...
I am able though to run with a different port with the following command
sudo mongod -f /etc/mongod.conf
When I run as a service user mongod runs mongodb
When I run from command line root runs mongodb
How can run the mongodb service with a different port?
By the way I succeeded on centos 6.5
Thanks
for those people having problem like me.. my fix is allow mongodb custom port on semanage
semanage port --list | grep mongo
mongod_port_t tcp 27017-27019, 28017-28019
as you can see, only 27017-27019, 28017-28019 is allowed.
in order to add a custom port for mongodb
semanage port -a -t mongod_port_t -p tcp 21010
you now have added the custom port
semanage port --list | grep mongo
mongod_port_t tcp 21010, 27017-27019, 28017-28019
make sure to restart mongodb