Installed Mongo using homebrew. If I type mongo on shell, it gets connected to test. But when I type the ip address of the local machine instead of 127.0.0.1
mongo --host 192.168.1.100 --verbose
It gives me error message
MongoDB shell version: 2.4.6
Fri Aug 23 15:18:27.552 versionArrayTest passed
connecting to: 192.168.1.100:27017/test
Fri Aug 23 15:18:27.579 creating new connection to:192.168.1.100:27017
Fri Aug 23 15:18:27.579 BackgroundJob starting: ConnectBG
Fri Aug 23 15:18:27.580 Error: couldn't connect to server 192.168.1.100:27017 at src/mongo/shell/mongo.js:147
Fri Aug 23 15:18:27.580 User Assertion: 12513:connect failed
Have tried modifying the mongo.conf by commenting bind_ip or by changing the ip address from 127.0.0.1 to 0.0.0.0 but no luck. This should be simple but have no clue now. Using mac.
Thanks
Update: As requested. This works after I have made the changes as you suggested.
ifconfig output
lo0: flags=8049<UP,LOOPBACK,RUNNING,MULTICAST> mtu 16384
options=3<RXCSUM,TXCSUM>
inet6 fe80::1%lo0 prefixlen 64 scopeid 0x1
inet 127.0.0.1 netmask 0xff000000
inet6 ::1 prefixlen 128
gif0: flags=8010<POINTOPOINT,MULTICAST> mtu 1280
stf0: flags=0<> mtu 1280
en0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=b<RXCSUM,TXCSUM,VLAN_HWTAGGING>
ether XX:XX:XX:
media: autoselect (none)
status: inactive
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
ether XX:XX:XX:XX:01
inet6 XXXX:XXXX:XXXX: %en1 prefixlen 64 scopeid 0x5
inet 192.168.1.100 netmask 0xffffff00 broadcast 192.168.1.255
media: autoselect
status: active
p2p0: flags=8843<UP,BROADCAST,RUNNING,SIMPLEX,MULTICAST> mtu 2304
ether XX:XX:XX:XX:XX
media: autoselect
status: inactive
fw0: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 4078
lladdr XX:XX:XX:XX
media: autoselect <full-duplex>
status: inactive
Output when executing command mongo --host 192.168.1.100 --verbose
MongoDB shell version: 2.4.5
Fri Aug 23 16:42:09.806 versionArrayTest passed
connecting to: 192.168.1.100:27017/test
Fri Aug 23 16:42:09.837 creating new connection to:192.168.1.100:27017
Fri Aug 23 16:42:09.837 BackgroundJob starting: ConnectBG
Fri Aug 23 16:42:10.129 connected connection!
Server has startup warnings:
Fri Aug 23 16:41:59.025 [initandlisten]
Fri Aug 23 16:41:59.025 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
File mongod.conf
# Store data in /usr/local/var/mongodb instead of the default /data/db
dbpath = /usr/local/var/mongodb
# Append logs to /usr/local/var/log/mongodb/mongo.log
logpath = /usr/local/var/log/mongodb/mongo.log
logappend = true
# Only accept local connections
bind_ip = 0.0.0.0`
I just tested this on my Mac with Homebrew, works fine if you change the bind address. I suspect you probably just didn't get the config for bind correct?
Just so we have all the information, can you paste the output of ifconfig please?
By default, MongoDB should listen on all interfaces, you shouldn't need to change the configuration, however, the Homebrew setup seems to override this (/usr/local/etc/mongod.conf):
# Only accept local connections
bind_ip = 127.0.0.1
Please kill MongoDB and run this (note the -v):
$ mongod --bind_ip 0.0.0.0 -v
warning: bind_ip of 0.0.0.0 is unnecessary; listens on all ips by default
all output going to: /usr/local/var/log/mongodb/mongo.log
Just paste your output for that please?
And then just try:
$ mongo --host 192.168.43.2 --verbose
MongoDB shell version: 2.4.6
Sat Aug 24 09:07:14.556 versionArrayTest passed
connecting to: 192.168.43.2:27017/test
Sat Aug 24 09:07:14.657 creating new connection to:192.168.43.2:27017
Sat Aug 24 09:07:14.657 BackgroundJob starting: ConnectBG
Sat Aug 24 09:07:14.657 connected connection!
Server has startup warnings:
Sat Aug 24 09:06:44.360 [initandlisten]
Sat Aug 24 09:06:44.360 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
>
Obviously replace it with your IP address. Let us know how that goes.
success:
change service config file C:\Program Files\MongoDB\Server\4.0\bin\mongod.cfg
# network interfaces (wjp: comment bindIp listening on all IPs)
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
restart mongodb service (or restart computer);
make sure machine level firewall open port 27017
connect ok.
No
In fact, if you want to access the rest interface from any ip, you needn't set bind_ip to 0.0.0.0 in the mongod.conf, you only comment or remove the configuration item from it, as similar as
#bind_ip=127.0.0.1
And then, restart your service, you can find that you can access the rest service from the 28017 port from your machine
For me I replaced the bindIp with bindIpAll: true (see http://docs.mongodb.org/manual/reference/configuration-options/ for details).
This is the content of 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
bindIpAll: true
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
#security:
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
Note: Below configuration is for windows 10 & MongoDB 4.0
There are two ways to configure this.
Using shell commands.
Or through mongod.cfg.
Using shell commands
First open the cmd as administrator and go to --YourPath--\MongoDB\Server\4.0\bin
If you already running the MongoDB service then run this command or else, go to second point.mongod --remove
Then set the path for data folder, log file and ip bind using the below command
mongod --dbpath "C:\Program Files\MongoDB\Server\4.0\data" --logpath "C:\Program Files\MongoDB\Server\4.0\log\mongod.log" --bind_ip "0.0.0.0" --install --serviceName "MongoDB"
caution: This ip configuration gives access to your DB throughout the network.
Now go to services.msc and find the MongoDB, then Right click -> Start the service.
Through mongod.cfg
MongoDB has a very good documentation for Configuration here.
Just change the bindIp: 127.0.0.1 to bindIp: 0.0.0.0. Then restart the service using the #3 point from the above topic.
Related
I reproduce MongoDB Cluster replica-set and added user like admin with Non-SSL following below link.
Link : https://github.com/arun2pratap/mongodbClusterForWindowsOneClick
Environment :
OS : Windows 2019 server ( set all instance in one windows server)
1 mongos ( port : 26000 )
2 shards ( port : sh01 : 27011 ~ 27013 / sh02 : 27021 ~ 27023 )
1 conf servers ( port : csrs : 26001 ~ 26003 )
After reproduce Cluster with Non-SSL, I tried to upgrade Cluster to use SSL following MongoDB Manual for 4.5 and other links but I couldn't found clear answer or guide.
Below are my refer links.
https://www.mongodb.com/docs/v4.4/tutorial/upgrade-cluster-to-ssl/
https://www.mongodb.com/docs/v4.4/tutorial/deploy-replica-set-with-keyfile-access-control/
https://www.mongodb.com/community/forums/t/cannot-start-mongodb-service-after-configuring-tls/2802
MongoDB Shell connection errors using test self signed certificates
https://www.mongodb.com/community/forums/t/creating-openssl-server-certificates-for-testing-failed/109058
I just configured conf files like sh011.conf following manuals, guides and started. but server seems only started csrs instances. because, I couldn't found other instance's port numbers.
1. sh011.conf
sharding:
clusterRole: shardsvr
replication:
replSetName: sh01
net:
bindIpAll: true
port: 27011
tls:
mode: requireTLS
certificateKeyFile: C:\database\MongoDB\Server\4.4\bin\certifications\test-server1.pem
CAFile: C:\database\MongoDB\Server\4.4\bin\certifications\test-ca.pem
systemLog:
destination: file
path: sh01/sh011/log/sh011.log
logAppend: true
storage:
dbPath: sh01/sh011/db/
2. mongos.conf
sharding:
configDB: csrs/WIN-BKEV4AO0KED:26001,WIN-BKEV4AO0KED:26002,WIN-BKEV4AO0KED:26003
net:
bindIpAll: true
port: 26000
tls:
mode: requireTLS
certificateKeyFile: C:\database\MongoDB\Server\4.4\bin\certifications\test-server1.pem
CAFile: C:\database\MongoDB\Server\4.4\bin\certifications\test-ca.pem
systemLog:
destination: file
path: router/log/mongos.log
logAppend: true
security:
authorization: enabled
clusterAuthMode: x509
3. "netstat -an" output
C:\database\MongoDB\Server\4.4\bin>netstat -an
Active Connections
Proto Local Address Foreign Address State
TCP 0.0.0.0:22 0.0.0.0:0 LISTENING
TCP 0.0.0.0:135 0.0.0.0:0 LISTENING
TCP 0.0.0.0:445 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5357 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5432 0.0.0.0:0 LISTENING
TCP 0.0.0.0:5985 0.0.0.0:0 LISTENING
TCP 0.0.0.0:26001 0.0.0.0:0 LISTENING
TCP 0.0.0.0:26002 0.0.0.0:0 LISTENING
TCP 0.0.0.0:26003 0.0.0.0:0 LISTENING
TCP 0.0.0.0:47001 0.0.0.0:0 LISTENING
When I checked log files, each shard nodes occurred SSL error like below
{"t":{"$date":"2022-05-09T14:34:54.933+09:00"},"s":"I", "c":"NETWORK", "id":4712102, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"Host failed in replica set","attr":{"replicaSet":"csrs","host":"WIN-BKEV4AO0KED:26001","error":{"code":6,"codeName":"HostUnreachable","errmsg":"Error connecting to WIN-BKEV4AO0KED:26001 (192.168.100.202:26001) :: caused by :: SSL peer certificate validation failed: (80096004)The signature of the certificate cannot be verified."},"action":{"dropConnections":true,"requestImmediateCheck":false,"outcome":{"host":":26001","success":false}}}}
{"t":{"$date":"2022-05-09T14:34:55.164+09:00"},"s":"I", "c":"-", "id":4333222, "ctx":"ReplicaSetMonitor-TaskExecutor","msg":"RSM received failed isMaster","attr":{"host":"WIN-BKEV4AO0KED:26003","error":"HostUnreachable: Error connecting to WIN-BKEV4AO0KED:26003 (192.168.100.202:26003) :: caused by :: SSL peer certificate validation failed: (80096004)The signature of the certificate cannot be verified.","replicaSet":"csrs","isMasterReply":"{}"}}
I thought, that issues cause is relate host names so, I configured hosts file.
Then, re-created certification files for CA, Server, Client following manual.
1. openssl-test-server.conf
[ alt_names ]
DNS.1 = WIN-BKEV4AO0KED
IP.1 = 192.168.100.202
[ req_dn ]
countryName = Country Name (2 letter code)
countryName_default = AA
countryName_min = 2
countryName_max = 2
stateOrProvinceName = State or Province Name (full name)
stateOrProvinceName_default = City
stateOrProvinceName_max = 64
localityName = Locality Name (eg, city)
localityName_default = City
localityName_max = 64
organizationName = Organization Name (eg, company)
organizationName_default = DevCompany
organizationName_max = 64
organizationalUnitName = Organizational Unit Name (eg, section)
organizationalUnitName_default = Dev
organizationalUnitName_max = 64
commonName = Common Name (eg, YOUR name)
commonName_default = WIN-BKEV4AO0KED
commonName_max = 64
But, still mongos and other instances are not started.
Finally, I think some configuration is wrong. I want know what I missed or wrong for SSL.
Finally, I found what is cause of issue and How to start MongoDB Cluster with SSL Myself.
1st, Root cause is that I couldn't start MongoDB instances like mongos, mongod with SSL enable and missed some parameters while starting like below :
before start command
$ mongod -f csrs1.conf
modified start command
$ mongod -f csrs1.conf --tlsMode requireTLS --tlsCertificateKeyFile test-server1.pem --tlsCAFile test-ca.pem
Note : I was not set MongoDB as service and just control through prompt
When I generated certification base on default setting and start each MongoDB with new command, that was working fine.
And I tried modify START.bat file for convenience like above new command.
But, that was not working. So, I opened prompt for each nodes and executed start command manually.
I hope this information will help.
Running Fedora-27, I am trying to change the default directory of mongodb to a subdirectory of my home directory.
sudo dnf install mongodb-server
The version
[idf#localhost mongodb]$ mongod --version
db version v3.4.6
git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
allocator: tcmalloc
modules: none
build environment:
distarch: x86_64
target_arch: x86_64
[idf#localhost mongodb]$
I added myself to the mongodb group
[idf#localhost mongodb]$ sudo usermod -g mongodb idf
usermod: no changes
[idf#localhost mongodb]$
Without changing anything else, I change the file /etc/mongodb.conf so that dbPath points to the directory I created:
[idf#localhost mongodb]$ more /etc/mongod.conf
##
## For list of options visit:
## https://docs.mongodb.org/manual/reference/configuration-options/
##
# systemLog Options - How to do logging
systemLog:
# The default log message verbosity level for components (0-5)
verbosity: 0
# The destination to which MongoDB sends all log output (file|syslog, if not specifed to STDOUT)
destination: file
# Log file to send write to instead of stdout - has to be a file, not directory
path: /var/log/mongodb/mongod.log
# Append to logpath instead of over-writing (false by default)
logAppend: true
# Set the log rotation behavior (rename|reopen, rename by default)
logRotate: reopen
# processManagement Options - How the process runs
processManagement:
# Fork server process (false by default)
fork: true
# Full path to pidfile (if not set, no pidfile is created)
pidFilePath: /var/run/mongodb/mongod.pid
# net Options - Network interfaces settings
net:
# Specify port number (27017 by default)
port: 27017
# Comma separated list of ip addresses to listen on (all local ips by default)
bindIp: 127.0.0.1,::1
# Enable IPv6 support (disabled by default)
ipv6: true
unixDomainSocket:
# Enable/disable listening on the UNIX domain socket (true by default)
enabled: true
# Alternative directory for UNIX domain sockets (defaults to /tmp)
pathPrefix: /var/run/mongodb
#ssl:
# Set the SSL operation mode (disabled|allowSSL|preferSSL|requireSSL)
#mode: <string>
# PEM file for ssl
#PEMKeyFile: <string>
# Certificate Authority file for SSL
#CAFile: <string>
# storage Options - How and Where to store data
storage:
# Directory for datafiles (defaults to /data/db/)
#dbPath: /var/lib/mongodb
dbPath: /home/idf/mongodb
#journal:
# Enable/Disable journaling (journaling is on by default for 64 bit)
#enabled: true
# The storage engine for the mongod database (mmapv1|wiredTiger, wiredTiger by default
# - works for 64 bit only)
# Also possible to use unstable engines: devnull|ephemeralForTest
engine: wiredTiger
#mmapv1:
# Enable or disable the preallocation of data files (true by default)
#preallocDataFiles: <boolean>
# Use a smaller default file size (false by default)
#smallFiles: <boolean>
#wiredTiger:
#engineConfig:
# The maximum size of the cache that WiredTiger will use for all data
# (max(60% of RAM - 1GB, 1GB) by default)
#cacheSizeGB: 5
# The type of compression to use to compress WiredTiger journal data
# (none|snappy|zlib, snappy by default)
#journalCompressor: <string>
#collectionConfig:
# The default type of compression to use to compress collection data
# (none|snappy|zlib, snappy by default)
#blockCompressor: <string>
# secutiry Options - Authorization and other security settings
#security:
# Private key for cluster authentication
#keyFile: <string>
# Run with/without security (enabled|disabled, disabled by default)
#authorization
# setParameter Options - Set MongoDB server parameters
# setParameter:
# opratrionProfiling Options - Profiling settings
#operationProfiling:
# replication Options - ReplSet settings
#replication:
# sharding Options - Shard settings
#sharding:
I copy the contents of /var/lib/mongodb to my home directory and change the owner.
[idf#localhost mongodb]$ pwd
/home/idf/mongodb
[idf#localhost mongodb]$
Proof:
[idf#localhost mongodb]$ ls -la
total 252
drwxr-xr-x. 4 mongodb root 4096 Dec 22 19:27 .
drwx------. 44 idf idf 4096 Dec 22 19:27 ..
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 collection-0--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 collection-2--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 diagnostic.data
-rw-r--r--. 1 mongodb mongodb 32768 Dec 22 19:27 index-1--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-3--6927808756336873775.wt
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 index-4--6927808756336873775.wt
drwxr-xr-x. 2 mongodb mongodb 4096 Dec 22 19:27 journal
-rw-r--r--. 1 mongodb mongodb 16384 Dec 22 19:27 _mdb_catalog.wt
-rw-r--r--. 1 mongodb mongodb 0 Dec 22 19:27 mongod.lock
-rw-r--r--. 1 mongodb mongodb 36864 Dec 22 19:27 sizeStorer.wt
-rw-r--r--. 1 mongodb mongodb 95 Dec 22 19:27 storage.bson
-rw-r--r--. 1 mongodb mongodb 49 Dec 22 19:27 WiredTiger
-rw-r--r--. 1 mongodb mongodb 4096 Dec 22 19:27 WiredTigerLAS.wt
-rw-r--r--. 1 mongodb mongodb 21 Dec 22 19:27 WiredTiger.lock
-rw-r--r--. 1 mongodb mongodb 993 Dec 22 19:27 WiredTiger.turtle
-rw-r--r--. 1 mongodb mongodb 53248 Dec 22 19:27 WiredTiger.wt
[idf#localhost mongodb]$ sudo systemctl start mongod
While I can start mongodb if the mongodb.conf file dbpath entry points to /var/lib, if I change dbpath to the directory that I duplicated on my home directory I get an error:
[idf#localhost mongodb]$ sudo systemctl start mongod
[sudo] password for idf:
Job for mongod.service failed because the control process exited with error code.
See "systemctl status mongod.service" and "journalctl -xe" for details.
[idf#localhost mongodb]$
status gives more information, but I don't know what it means:
[idf#localhost mongodb]$ sudo systemctl status mongod
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/usr/lib/systemd/system/mongod.service; disabled; vendor preset: disabled)
Active: failed (Result: exit-code) since Fri 2017-12-22 20:21:33 EST; 5s ago
Process: 9081 ExecStart=/usr/bin/mongod $OPTIONS run (code=exited, status=100)
Dec 22 20:21:33 localhost.localdomain systemd[1]: Starting High-performance, schema-free document-oriented database...
Dec 22 20:21:33 localhost.localdomain mongod[9081]: about to fork child process, waiting until server is ready for connections.
Dec 22 20:21:33 localhost.localdomain mongod[9081]: forked process: 9083
Dec 22 20:21:33 localhost.localdomain mongod[9081]: ERROR: child process failed, exited with error number 100
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Control process exited, code=exited status=100
Dec 22 20:21:33 localhost.localdomain systemd[1]: Failed to start High-performance, schema-free document-oriented database.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Unit entered failed state.
Dec 22 20:21:33 localhost.localdomain systemd[1]: mongod.service: Failed with result 'exit-code'.
[idf#localhost mongodb]$
The log file give interesting information [the line Unable to determine status of lock file in the data directory], but I don't know how to resolve it to, since I duplicated the permissions and ownership from /var/lib/mongod directory:
2017-12-22T20:30:16.716-0500 I CONTROL [main] ***** SERVER RESTARTED *****
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] MongoDB starting : pid=9483 port=27017 dbpath=/home/idf/mongodb 64-bit host=localhost.localdomain
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] db version v3.4.6
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] git version: c55eb86ef46ee7aede3b1e2a5d184a7df4bfb5b5
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.1.0g-fips 2 Nov 2017
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] allocator: tcmalloc
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] modules: none
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] build environment:
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] distarch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] target_arch: x86_64
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] options: { command: [ "run" ], config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1,::1", ipv6: true, port: 27017, unixDomainSocket: { enabled: true, pathPrefix: "/var/run/mongodb" } }, processManagement: { fork: true, pidFilePath: "/var/run/mongodb/mongod.pid" }, storage: { dbPath: "/home/idf/mongodb", engine: "wiredTiger" }, systemLog: { destination: "file", logAppend: true, logRotate: "reopen", path: "/var/log/mongodb/mongod.log", verbosity: 0 } }
2017-12-22T20:30:16.722-0500 I STORAGE [initandlisten] exception in initAndListen: 28596 Unable to determine status of lock file in the data directory /home/idf/mongodb: boost::filesystem::status: Permission denied: "/home/idf/mongodb/mongod.lock", terminating
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to close listening sockets...
2017-12-22T20:30:16.722-0500 I NETWORK [initandlisten] shutdown: going to flush diaglog...
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] now exiting
2017-12-22T20:30:16.722-0500 I CONTROL [initandlisten] shutting down with code:100
EDIT 1
If I run mongod "by hand" [not using service ...], it works in my data directory. Bizarre...
[idf#localhost mongodb]$ sudo mongod --dbpath /home/idf/mongodb/
Can you check how SELinux is configured on your system?
sestatus
SELinux status: enabled
SELinuxfs mount: /sys/fs/selinux
SELinux root directory: /etc/selinux
Loaded policy name: targeted
Current mode: permissive
Mode from config file: permissive
Policy MLS status: enabled
Policy deny_unknown status: allowed
Max kernel policy version: 28
If SELinux is in enforcing mode, enable access to the relevant port:
sudo semanage port -a -t mongod_port_t -p tcp 27017
Try to set it to permissive:
setenforce permissive
this will survive until the next reboot, to make it permanent, edit /etc/selinux/config
I am trying to start mongod as a service on CentOS:
mongod --version
db version v3.2.9
git version: 22ec9e93b40c85fc7cae7d56e7d6a02fd811088c
OpenSSL version: OpenSSL 1.0.1e-fips 11 Feb 2013
allocator: tcmalloc
modules: none
build environment:
distmod: rhel70
distarch: x86_64
target_arch: x86_64
CentOS Linux release 7.2.1511 (Core)
/etc/selinux/config:
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
mongod.conf:
systemLog:
destination: file
path: "/mnt/log/mongod.log"
logAppend: true
storage:
dbPath: "/mnt/data"
engine: wiredTiger
journal:
enabled: true
processManagement:
fork: true
pidFilePath: "/var/run/mongodb/mongod.pid"
net:
# bindIp: 127.0.0.1
port: 27017
replication:
replSetName: XXXX
security:
keyFile: "/usr/mongodb/mongodb-keyfile"
The issue states:
Starting mongod (via systemctl): Job for mongod.service failed because the control process exited with error code. See "systemctl status mongod.service" and "journalctl -xe" for details.
[FAILED]
journalctl -xe
...
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: Unit mongod.service entered failed state.
Sep 20 13:10:55 ip-10-0-231-19.localdomain systemd[1]: mongod.service failed.
Sep 20 13:10:55 ip-10-0-231-19.localdomain polkitd[9717]: Unregistered Authentication Agent for unix-process:26567:1630816 (system bus name :1.27, object path /org/freedesktop/PolicyKit1/AuthenticationAgent, locale en_US.UTF-8) (disconnected from bus)
Sep 20 13:11:04 ip-10-0-231-19.localdomain sudo[26587]: centos : TTY=pts/1 ; PWD=/home/centos ; USER=root ; COMMAND=/bin/vi /etc/mongod.conf
The server starts using:
sudo mongod -f /etc/mongod.conf
I know that there was a bug opened regarding similar issue but the fix might be available in 3.2.7 already and besides it was related to the scenario when SELINUX=enforcing...
Please support.
Recently encountered a similar problem, but on FC26; here, the problem could be traced back to SELINUX and specifically the permissions on the custom dbPath directory.
After trying many things, I found that the following sequence helped resolve my problem:
MONGODB_DATADIR=/mnt/data
sudo chown -R mongodb:mongodb $MONGODB_DATADIR
sudo chmod -R 700 $MONGODB_DATADIR
SELinux settings:
sudo semanage port -a -t mongod_port_t -p tcp 27017
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}
sudo semanage fcontext -a -t mongod_var_lib_t ${MONGODB_DATADIR}/mongod.lock
sudo restorecon -v ${MONGODB_DATADIR}
You probably also have to add mongod_log_t to the custom log file location, /mnt/log/mongod.log, I did not modify that one on my end.
Actually, for me the fix was:
sudo chown -R mongod:mongod $MONGODB_DATADIR
I have installed mongo on machine1(Ubuntu 14.04.3 LTS server) in my local network. I have also opened the port 27017 as mentioned in this guide using following commands:
sudo iptables -A INPUT -p tcp --destination-port 27017 -m state --state NEW,ESTABLISHED -j ACCEPT
sudo iptables -A OUTPUT -p tcp --source-port 27017 -m state --state ESTABLISHED -j ACCEPT
Current rules are (iptables -L):
Chain INPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp dpt:27017 state NEW,ESTABLISHED
Chain FORWARD (policy ACCEPT)
target prot opt source destination
Chain OUTPUT (policy ACCEPT)
target prot opt source destination
ACCEPT tcp -- anywhere anywhere tcp spt:27017 state ESTABLISHED
But I am not able to connect to this port from machine2 (in the same network):
$ mongo --host 192.168.0.108
MongoDB shell version: 3.0.4
connecting to: 192.168.0.108:27017/test
2016-01-23T18:02:14.848+0530 W NETWORK Failed to connect to 192.168.0.108:27017, reason: errno:61 Connection refused
2016-01-23T18:02:14.850+0530 E QUERY Error: couldn't connect to server 192.168.0.108:27017 (192.168.0.108), connection attempt failed
at connect (src/mongo/shell/mongo.js:181:14)
at (connect):1:6 at src/mongo/shell/mongo.js:181
exception: connect failed
I also tried checking if port is opened or not:
$ nc -v 192.168.0.108 27017
nc: connectx to 192.168.0.108 port 27017 (tcp) failed: Connection refused
I am not sure what I am missing. Must be some silly mistake as I am setting up mongo for the first time. Pls help.
Update (for the doubts raised in current answers)
Yeah its running. I am able to connect to mongo form the same machine but not from the other machine. The daemon is running: $ service mongod status mongod start/running, process 31205 and the port is 27017 $ sudo netstat -tulpn |grep 27017 tcp 0 0 127.0.0.1:27017 0.0.0.0:* LISTEN 31205/mongod
I changed the bind_ip to 0.0.0.0 and restarted mongo. Still the same error is coming.
Mongo logs:
$ cat /var/log/mongodb/mongod.log
2016-01-23T16:28:13.155+0530 I CONTROL [initandlisten] MongoDB starting : pid=31205 port=27017 dbpath=/var/lib/mongodb 64-bit host=dexter
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] db version v3.2.1
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] git version: a14d55980c2cdc565d4704a7e3ad37e4e535c1b2
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.1f 6 Jan 2014
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] allocator: tcmalloc
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] modules: none
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] build environment:
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] distmod: ubuntu1404
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] distarch: x86_64
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] target_arch: x86_64
2016-01-23T16:28:13.156+0530 I CONTROL [initandlisten] options: { config: "/etc/mongod.conf", net: { bindIp: "127.0.0.1", port: 27017 }, storage: { dbPath: "/var/lib/mongodb", journal: { enabled: true } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log" } }
2016-01-23T16:28:13.173+0530 I STORAGE [initandlisten] wiredtiger_open config: create,cache_size=1G,session_max=20000,eviction=(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),
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten]
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten]
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten] ** We suggest setting it to 'never'
2016-01-23T16:28:14.444+0530 I CONTROL [initandlisten]
2016-01-23T16:28:14.444+0530 I FTDC [initandlisten] Initializing full-time diagnostic data capture with directory '/var/lib/mongodb/diagnostic.data'
2016-01-23T16:28:14.444+0530 I NETWORK [HostnameCanonicalizationWorker] Starting hostname canonicalization worker
2016-01-23T16:28:14.949+0530 I NETWORK [initandlisten] waiting for connections on port 27017
2016-01-23T16:38:37.046+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37032 #1 (1 connection now open)
2016-01-23T16:39:31.447+0530 I NETWORK [conn1] end connection 127.0.0.1:37032 (0 connections now open)
2016-01-23T16:49:24.240+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37033 #2 (1 connection now open)
2016-01-23T16:49:38.249+0530 I NETWORK [conn2] end connection 127.0.0.1:37033 (0 connections now open)
2016-01-23T16:51:51.707+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37034 #3 (1 connection now open)
2016-01-23T16:51:55.785+0530 I NETWORK [conn3] end connection 127.0.0.1:37034 (0 connections now open)
2016-01-23T17:32:15.546+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37036 #4 (1 connection now open)
2016-01-23T17:32:21.180+0530 I NETWORK [conn4] end connection 127.0.0.1:37036 (0 connections now open)
2016-01-23T18:11:57.885+0530 I NETWORK [initandlisten] connection accepted from 127.0.0.1:37037 #5 (1 connection now open)
2016-01-23T18:29:55.365+0530 I NETWORK [conn5] end connection 127.0.0.1:37037 (0 connections now open)
make sure that mongodb daemon is running, and listening on 0.0.0.0, but not 127.0.0.1 port
for example, for my local mongodb, it has this config:
[vodolaz095#steel ~]$ cat /etc/mongod.conf
##
### Basic Defaults
##
# Comma separated list of ip addresses to listen on (all local ips by default)
bind_ip = 127.0.0.1
# Specify port number (27017 by default)
#port = 27017
for mongodb server to listen for remote connections, you can change
# Comma separated list of ip addresses to listen on (all local ips by default)
bind_ip = 0.0.0.0
With mongoDB server version 3.6.4, Ubuntu 16.4.4 I solved this by setting the net section in /etc/mongod.conf like this:
net:
port: 27017
bindIpAll: true
# bindIp: 127.0.0.1
The issue was bindIp didn't change. There was some issue in restarting mongo from my side.
The habit should be to verify if the bindIp actually changed or not. (using sudo netstat -tulpn | grep 27017)
I have tried a different way to solve this issue. I have changed the config file from
bind_ip = 127.0.0.1
#port = 27017
to
bind_ip = 0.0.0.0
#port = 27017
Hope it helps. Happy coding ;)
Make sure you have a daemon running on your machine1 which listen to port 27017. We were getting the same error and found that daemon was not running.
if Mongo server run on port 65500.
Now on which port, I can access simple HTTP rest ?
Let a case,
MongoDB provides a simple http interface listing information of interest to administrators. This interface may be accessed at the port with numeric value 1000 more than the configured mongod port.
if MongoDB runs on localhost with port number 65500.
Then which port does Mongo rest interface run?
Port no. 66500 is not possible value for port
Port numbers are only 16 bits, so mongod will fail to even start on that port (greater than 65535)
> mongod --port 65555 --dbpath .
Sat Mar 29 13:00:31.488 bad --port number
Sat Mar 29 13:00:31.488 dbexit:
Sat Mar 29 13:00:31.488 shutdown: going to close listening sockets...
If you really mean an allowed port that would just make the web port go above 65536, it will wrap around to 0 (which would mean 65535+1000 would wrap to 999, or your new sample port 65500 would wrap to 964);
Sat Mar 29 13:01:53.448 [initandlisten] waiting for connections on port 65500
Sat Mar 29 13:01:53.448 [websvr] ERROR: listen(): bind() failed errno:13
Permission denied for socket: 0.0.0.0:964