I have to linux servers running on the same local network.
One of them is running mongoDB server.
I am trying to connect to the first server mongodb from the second server.
I have added port 27017 to the first server firewall rules.
I have modified the /etc/mongo.conf file as follows:
bind_ip=127.0.0.1,10.0.0.202
That did not work. I have also tried the next version:
bind_ip=[127.0.0.1,10.0.0.202]
That did not work as well.
After modifying the file I am trying to restart the mongod service but the service won't restart. It will only with the original line: bind_ip=127.0.0.1.
Here is the error once i restart the service and check the status:
mongod.service - SYSV: Mongo is a scalable, document-oriented database.
Loaded: loaded (/etc/rc.d/init.d/mongod)
Active: failed (Result: exit-code) since Sun 2016-11-13 11:32:15 IST; 4min 58s ago
Docs: man:systemd-sysv-generator(8)
Process: 37572 ExecStop=/etc/rc.d/init.d/mongod stop (code=exited, status=0/SUCCESS)
Process: 37546 ExecStart=/etc/rc.d/init.d/mongod start (code=exited, status=0/SUCCESS)
Main PID: 37559 (code=exited, status=48)
Nov 13 11:32:15 localhost.localdomain systemd[1]: Starting SYSV: Mongo is a scalable, document-oriented database....
Nov 13 11:32:15 localhost.localdomain runuser[37555]: pam_unix(runuser:session): session opened for user mongod...d=0)
Nov 13 11:32:15 localhost.localdomain mongod[37546]: Starting mongod: [ OK ]
Nov 13 11:32:15 localhost.localdomain systemd[1]: Started SYSV: Mongo is a scalable, document-oriented database..
Nov 13 11:32:15 localhost.localdomain systemd[1]: mongod.service: main process exited, code=exited, status=48/n/a
Nov 13 11:32:15 localhost.localdomain mongod[37572]: Stopping mongod: [FAILED]
Nov 13 11:32:15 localhost.localdomain systemd[1]: Unit mongod.service entered failed state.
Nov 13 11:32:15 localhost.localdomain systemd[1]: mongod.service failed.
What am i doing wrong? How do i fix it?
Any help would be appreciated. Thank you.
Problem solved.
Apparently when adding an IP to the bind_ip=127.0.0.1 line, the next IP should be the one of that same machine.
If the IP of the machine running the mongo server is 10.0.0.201, so we should change the line into bind_ip=127.0.0.1,10.0.0.201. This way other machines that are on the same network will be able to connect to its mongo server.
Set bindIp as 0.0.0.0 to let the mongo db served bind to all interfaces:
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
bindIp: 0.0.0.0
For someone who is using Amazon AWS for instance, bind local IP port and not public IP port. Than You allow port 27017 in your Security Group to allow it for incoming connections.
/etc/mongod.conf
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1,172.33.1.10
Do not forget to secure it by creating user:
> show dbs
admin 135 kB
config 111 kB
local 73.7 kB
> db.createUser({
user: "LetMeIn",
pwd: "MyStrongPsswd",
roles: [{role: "userAdminAnyDatabase" , db: "admin"}]
});
{ ok: 1 }
Related
I'm trying to use an external drive to store my mongo collections. As per this question, I changed dbPath in /etc/mongod.conf from /var/lib/mongodb to /media/user/drive/mongodb. I also chown'd the new path to the mongodb user.
However, when I sudo service start mongod, I cannot start the server:
mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2022-12-07 22:27:09 CET; 2s ago
Docs: https://docs.mongodb.org/manual
Process: 63819 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=100)
Main PID: 63819 (code=exited, status=100)
Dec 07 22:27:09 user-ThinkPad-T480s systemd[1]: Started MongoDB Database Server.
Dec 07 22:27:09 user-ThinkPad-T480s systemd[1]: mongod.service: Main process exited, code=exited, status=100/n/a
Dec 07 22:27:09 user-ThinkPad-T480s systemd[1]: mongod.service: Failed with result 'exit-code'.
When I change dbPath back to /var/lib/mongodb it starts again. How can I fix this such that I can use the path on my external drive?
Not sure which OS you run and which version of MongoDB.
On Amazon Linux 2 it's mongod user not mongodb for MongoDB-5.0
Make sure you ran chown with -R flag
-rw-r----- 1 mongod mongod 8.6M Dec 10 00:59 mongod.log
Also check logs for more hints, default location should be under
/var/log/mongodb/mongod.log
One day, My Postgresql server stopped working. Checked log. It was shutdown somehow.
root#ip_address:/# tail /var/log/postgresql/postgresql-10-main.log
2020-02-19 06:47:49.215 CET [23497] LOG: received smart shutdown request
2020-02-19 06:47:49.477 CET [23497] LOG: worker process: logical replication launcher (PID 23512) exited with exit code 1
2020-02-19 06:47:49.482 CET [23507] LOG: shutting down
2020-02-19 06:47:49.546 CET [23497] LOG: database system is shut down
When I run,
root#ip_address:/# psql
psql: could not connect to server: No such file or directory
Is the server running locally and accepting
connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
It complained that there are no files and directory. so I checked if my postgresql running.
root#ip_address:/# systemctl status postgresql
● postgresql.service - PostgreSQL RDBMS
Loaded: loaded (/lib/systemd/system/postgresql.service; enabled; vendor preset: enabled)
Active: active (exited) since Sun 2020-03-08 16:19:24 CET; 26min ago
Process: 30136 ExecStart=/bin/true (code=exited, status=0/SUCCESS)
Main PID: 30136 (code=exited, status=0/SUCCESS)
Mar 08 16:19:24 vps584959 systemd[1]: Starting PostgreSQL RDBMS...
Mar 08 16:19:24 vps584959 systemd[1]: Started PostgreSQL RDBMS.
It was running. but, if I check postgresql cluster.
root#ip_address:/# pg_lsclusters
Ver Cluster Port Status Owner Data directory Log file
10 main 5432 down postgres /var/lib/postgresql/10/main /var/log/postgresql/postgresql-10-main.log
It was DOWN
so I tried
root#ip_address:/# pg_ctlcluster 10 main start
Error: Config owner (deploy:1003) and data owner (postgres:114) do not match, and config owner is not root
I wasn't able to make it work. then I tried.
sudo chown -R deploy:postgres /var/lib/postgresql/10/ && sudo chmod -R u=rwX,go= /var/lib/postgresql/10/
try again.
root#ip_address:/# pg_ctlcluster 10 main start
Job for postgresql#10-main.service failed because the service did not take the steps required by its unit configuration.
See "systemctl status postgresql#10-main.service" and "journalctl -xe" for details.
root#ip_address:/# systemctl status postgresql#10-main.service
● postgresql#10-main.service - PostgreSQL Cluster 10-main
Loaded: loaded (/lib/systemd/system/postgresql#.service; indirect; vendor preset: enabled)
Active: failed (Result: protocol) since Sun 2020-03-08 16:59:53 CET; 2min 52s ago
Process: 31635 ExecStart=/usr/bin/pg_ctlcluster --skip-systemctl-redirect 10-main start (code=exited, status=1/FAILURE)
Main PID: 23497 (code=exited, status=0/SUCCESS)
Mar 08 16:59:53 vps584959 systemd[1]: Starting PostgreSQL Cluster 10-main...
Mar 08 16:59:53 vps584959 postgresql#10-main[31635]: Error: /usr/lib/postgresql/10/bin/pg_ctl /usr/lib/postgresql/10/bin/pg_ctl start -D /var/lib/postgresql/10/main -l /var/log/postgre
Mar 08 16:59:53 vps584959 systemd[1]: postgresql#10-main.service: Can't open PID file /var/run/postgresql/10-main.pid (yet?) after start: No such file or directory
Mar 08 16:59:53 vps584959 systemd[1]: postgresql#10-main.service: Failed with result 'protocol'.
Mar 08 16:59:53 vps584959 systemd[1]: Failed to start PostgreSQL Cluster 10-main.
Don't know what to do more. Is anybody had the same problem?
More infos.
root#ip_address:/var/run/postgresql# ls
total 0
drwxrwsr-x 3 postgres postgres 60 Feb 19 06:47 .
drwxr-xr-x 28 root root 1060 Mar 8 13:58 ..
drwxr-s--- 2 postgres postgres 40 Feb 19 06:47 10-main.pg_stat_tmp
pg_ctlcluster 10 main start
Error: Config owner (deploy:1003) and data owner (postgres:114) do not match, and config owner is not root
That's pretty clear, isn't it?
The Ubuntu PostgreSQL startup script wants that postgresql.conf and/or pg_hba.conf be owned by user postgres, else it refuses to proceed.
When I set bindIp of mongod.conf file as my wifi router's default gateway i.e bindIp:127.0.0.1,198.168.3.1. my MongoDB server stops and I get following error when I check its status.
● mongod.service - MongoDB Database Server
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset:
Active: failed (Result: exit-code) since Thu 2020-01-23 17:42:38 IST; 1s ago
Docs: https://docs.mongodb.org/manual
Process: 3046 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited
Main PID: 3046 (code=exited, status=48)
Jan 23 17:42:38 sarvahapc systemd[1]: Started MongoDB Database Server.
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Main process exited, code=
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Unit entered failed state.
Jan 23 17:42:38 sarvahapc systemd[1]: mongod.service: Failed with result 'exit-c
lines 1-11/11 (END)
But when I set bindIp: 0.0.0.0 in mongod.conf file my MongoDB server runs smoothly and it allows remote access to my MongoDB server for other systems which are in my wifi network.
I want to give remote access to my MongoDB server to other systems which are in my wifi network. Can anyone help me with this?
When I attempt to start the mongodb service using the command sudo service mongod start, it doesn't work. Upon closer inspection with 'sudo service mongod status` the following is found:
● mongod.service - High-performance, schema-free document-oriented database
Loaded: loaded (/lib/systemd/system/mongod.service; disabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Mon 2017-09-18 21:00:29 CEST; 7s ago
Docs: https://docs.mongodb.org/manual
Process: 21352 ExecStart=/usr/bin/mongod --config /etc/mongod.conf (code=exited, status=1/FAIL
Main PID: 21352 (code=exited, status=1/FAILURE)
Sep 18 21:00:29 zeus systemd[1]: Started High-performance, schema-free document-oriented databas
Sep 18 21:00:29 zeus systemd[1]: mongod.service: Main process exited, code=exited, status=1/FAIL
Sep 18 21:00:29 zeus systemd[1]: mongod.service: Unit entered failed state.
Sep 18 21:00:29 zeus systemd[1]: mongod.service: Failed with result 'exit-code'.
The configuration file has been changed to the following:
# Where and how to store data.
storage:
dbPath: /tank/mongo/mongodb
journal:
enabled: true
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /tank/mongo/log/mongodb/mongod.log
# network interfaces
net:
port: 27017
bindIp: 127.0.0.1
The mongodb user been given access to the \tank\mongodirectory using the command: sudo chown -R mongodb:users /tank/mongo.
It turns out that I was supposed to give permission to mongodb:mongodb, and not only that; the child folders didn't inherit the permissions, so I had to give the permissions at the folder levels specified in the config /tank/mongo/log/mongodb/, /tank/mongo/mongodb.
I leave the answer in case it might help someone who is in a similar situation.
I have installed with the help of following link: https://www.digitalocean.com/community/tutorials/how-to-install-mongodb-on-ubuntu-16-04
It was working fine by default. But when I change data directory in /etc/mongod.conf
#From
dbPath: /var/lib/mongodb
#To
dbPath: /media/user/'Mounted Volume'/mongodb_data
I am unable to start MongoDB. Following is the error message
$mongo
MongoDB shell version: 3.2.11
connecting to: test
2017-01-06T00:57:01.472+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2017-01-06T00:57:01.472+0530 E QUERY [thread1] Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed :
connect#src/mongo/shell/mongo.js:229:14
#(connect):1:6
exception: connect failed
Following is the status
$ sudo systemctl status mongodb
mongodb.service - High-performance, schema-free document-oriented database
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: failed (Result: exit-code) since Fri 2017-01-06 00:56:40 IST; 7s ago
Process: 5735 ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf (cod
Main PID: 5735 (code=exited, status=100)
Jan 06 00:56:40 GL552VW systemd[1]: Started High-performance, schema-free docume
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Main process exited, code=e
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Unit entered failed state.
Jan 06 00:56:40 GL552VW systemd[1]: mongodb.service: Failed with result 'exit-co
I am new to MongoDB. Maybe I am missing something very simple.
From the MongoDB config file documentation page
The Linux package init scripts included in the official MongoDB packages depend on specific values for systemLog.path, storage.dbpath, and processManagement.fork. If you modify these settings in the default configuration file, mongod may not start.
So if you modify these properties in the configuration file, you most probably have to write a new init script.