How can we setup multiple versions of MongoDB on Ubuntu 16.04?
MongoDB 3.4.1 is already up and running on my system and wanted to setup MongoDB 2.6 for other application. Because our Application running on MongoDB 2.6 is having DB driver which is not compatible with MongoDB 3.4 hence wanted run both MongoDB version on same linux server.
Tried to follow below link but couldn't succeed.
How can I install two versions of mongodb parallely in Ubuntu 12.04
?
multiple versions of Mongo
multiple instances of Mongo DB on same server
To do that, you must have both versions of MongoDB available on your system.
For instance, let's say you have downloaded the 2.6 version binaries to /opt/mongo/26/ and the other version's at /opt/mongo/34/, you could run both versions of the database daemon on different ports:
/opt/mongo/26/mongod --dbpath /data/26/ --port 27017
/opt/mongo/34/mongod --dbpath /data/34/ --port 28018
This is what I do.
1. Choose version:
Community: https://www.mongodb.com/download-center/community/releases/archive
Enterprise: https://www.mongodb.com/download-center/enterprise/releases/archive
2. Install and Configuration
I use Ubuntu 20.04 and I want to install mongodb Community ver 2.6.12
Installing:
$ cd ~/Downloads
$ curl -O http://downloads.mongodb.org/linux/mongodb-linux-x86_64-2.6.12.tgz
$ tar -zxvf mongodb-linux-x86_64-2.6.12.tgz
$ mv mongodb-linux-x86_64-2.6.12 2.6.12
$ cd /opt && mkdir -p mongodb
$ cd ~/Downloads
$ cp -R 2.6.12 /opt/mongodb
$ cp /mongod.conf /opt/mongodb/2.6.12/
Configuration:
Configuration options on version <3.0 is different with version >3.0 so I googled it. This is what I had.
systemLog:
destination: file
path: "/var/log/mongodb/mongodb.log"
logAppend: true
storage:
journal:
enabled: true
processManagement:
fork: true
net:
bindIp: 127.0.0.1
port: 27018
setParameter:
enableLocalhostAuthBypass: false
On this file, you need change systemLog.path, net.port and net.bindIp to your own. One important thing is we cannot run 2 versions at same time with same port. So here I set 27018 for older version.
Put it wherever you want, I did:
$ cp ~/mongod.conf /opt/mongodb/2.6.12/
DON'T RUN THIS because it will overwrite current mongodb version commands
$ export PATH=/opt/mongodb/2.6.12/bin:$PATH
Create data and log directories and set permission.
$ mkdir -p /data/db
$ mkdir -p /var/log/mongodb
Running:
Now you can start 2.6 version with command.
$ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf
It is too long, isn't it? So make it shorter with alias.
$ sudo nano ~/.bash_profile
or
$ sudo nano ~/.bashrc
and add this to file
alias mongo26="/opt/mongodb/2.6.12/bin/mongo --port 27018"
alias mongoRestore26="/opt/mongodb/2.6.12/bin/mongorestore --port 27018"
alias mongoDump26="/opt/mongodb/2.6.12/bin/mongodump --port 27018"
alias startMongo26="/opt/mongodb/2.6.12/bin/mongod --fork --dbpath /data/db --config /opt/mongodb/2.6.12/mongod.conf"
alias stopMongo26="/opt/mongodb/2.6.12/bin/mongod --dbpath /data/db --shutdown"
alias nanoMongo="nano /opt/mongodb/2.6.12/mongod.conf"
alias tailMongo="tail -f /var/log/mongodb/mongod.log"
alias tailMongo26="tail -f /var/log/mongodb/mongodb.log"
Apply these alias
$ source ~/.bash_profile
or
$ source ~/.bashrc
Now we can simply start mongodb version 2.6 by
$ startMongo26
about to fork child process, waiting until server is ready for connections.
forked process: 1049481
child process started successfully, parent exiting
Run shell version 2.6
$ mongo26
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27018/test
>
Run shell current version
$ mongo
MongoDB shell version v4.4.3
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
Implicit session: session { "id" : UUID("3ae6094f-86dc-4741-aa72-1e48efc5273a") }
MongoDB server version: 4.4.3
>
3.Troubleshooting
Cannot start by startMongo26 please check log at /var/log/mongodb/mongod.log
about to fork child process, waiting until server is ready for connections.
forked process: 1049890
ERROR: child process failed, exited with error number 100
Check log at /var/log/mongodb/mongod.log
If log has this line:
2021-02-26T15:51:13.493-0700 [initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /data/db/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
This is because your current user doesn't have permission to run and write into this directory. You can set permission to /data/db or change directory. I changed to ~/datamongo
$ /opt/mongodb/2.6.12/bin/mongod --fork --dbpath ~/datamongo --config /opt/mongodb/2.6.12/mongod.conf
Do the same with error on /var/log/mongodb/mongodb.log
Cannot shutdown by stopMongo26
There doesn't seem to be a server running with dbpath: /data/db
Do this:
$ mongo26
MongoDB shell version: 2.6.12
connecting to: 127.0.0.1:27018/test
> use admin
switched to db admin
> db.shutdownServer()
2021-02-26T15:45:19.738-0700 DBClientCursor::init call() failed
server should be down...
2021-02-26T15:45:19.742-0700 trying reconnect to 127.0.0.1:27018 (127.0.0.1) failed
2021-02-26T15:45:19.742-0700 warning: Failed to connect to 127.0.0.1:27018, reason: errno:111 Connection refused
2021-02-26T15:45:19.742-0700 reconnect 127.0.0.1:27018 (127.0.0.1) failed failed couldn't connect to server 127.0.0.1:27018 (127.0.0.1), connection attempt failed
Do step by step with my instruction you gonna be ok. Good luck and enjoy!!!
Related
I am trying to run MongoDB server forever locally on Windows 10. And for that I'm using forever server.js which throws an error i.e, Forever is not installed.
I did npm install. But then too showing the same error.
I have followed this guide, but it's for Ubuntu. I am using Windows 10.
I need something like if I close the server cmd also, it should keep running.
In Windows, you can use the mongod command to register Mongo as a service
mongod --directoryperdb --dbpath "C:\Program Files\MongoDB\Server\3.4\data\db" --logpath "C:\Program Files\MongoDB\Server\3.4\log\mongo.log" --logappend --rest --install
Open the cmd(command prompt) as administrator
run the above command
open services and search for mongo service
If it is not running already, click start to start the service
You need to install mongo as a service.
To do so,
Open cmd in administrator mode.
Create two directories to store data and logs
mkdir c:\data\db
mkdir c:\data\log
Create a configuration file. The file must set systemLog.path. Include additional configuration options as appropriate.For example, create a file at C:\Program Files\MongoDB\Server\3.6\mongod.cfg that specifies both systemLog.path and storage.dbPath like this:
systemLog:
destination: file
path: c:\data\log\mongod.log
storage:
dbPath: c:\data\db
install mongo service, run the following command:
mongod.exe --config "C:\Program Files\MongoDB\Server\3.4\mongod.cfg" --install
Start service using: >net start mongodb
To stop service use : >net stop mongodb
You can refer official documents here
1. mongod --install --dbpath D:\data\db --logpath D:\log\mlog.txt
2. net start MongoDB
All above command should be run as administrator and you can change dbPatha and logpath with your path
How to start & stop a mongo DB server from the command line
This question already has answers here:
MongoDB Failing to Start - ***aborting after fassert() failure
(8 answers)
Closed 5 years ago.
Having some trouble configuring mongodb to Linux ec2 after following these directions https://docs.mongodb.com/ecosystem/platforms/amazon-ec2/
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod start
Error starting mongod. /var/run/mongodb/mongod.pid exists.
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod restart
Stopping mongod: [ OK ]
Starting mongod: [FAILED]
I also tried rm -f /var/run/mongodb/mongod.pid which now instantly fails.
[root#ip-xxx-xx-xx-xxx /]# sudo service mongod start
Starting mongod: [FAILED]
I have a feeling it may be my mongod.conf and tried editing the dbPath and sysLogPath according to the docs.
# mongod.conf
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: "log/mongod.log"
# Where and how to store data.
storage:
dbPath: "/data"
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod.pid # location of pidfile
I am new to both AWS and deploying a db, and would appreciate suggestions!
After checking to log/mongod.log as #hjpotter92 suggested I found it was ***aborting after fassert() failure
From the link below I ran the commands, which was successful.
sudo rm /tmp/mongodb-27017.sock
rm -f /var/run/mongodb/mongod.pid
sudo service mongod start
MongoDB Failing to Start - ***aborting after fassert() failure
you are using sudo while logged in as root .
Please recheck if this is is causing the issue .
I am using CentOS 7.3 as a guest VM from Oracle VirtualBox. The host is Windows 7 and I have a physical USB stick (aka flash drive) to house the data directory for Postgres. I can use a USB stick as a mounted directory in Linux. I can read and write files to it.
I expect to be able to have Postgres databases on my USB stick. But I cannot get Postgres databases on my USB stick. I installed Postgres on the Linux VM.
To change the default data directory of Postgres, I followed these directions.
If you do not have time to go to the link, I simply installed Postgres with these two commands:
yum -y install postgresql-server postgresql-contrib
postgresql-setup initdb
then I ran these two commands:
mv /var/lib/pgsql/data/* /mnt/windows-share/data
ln -s /mnt/windows-share /var/lib/pgsql/data
Afterward I try to start the Postgres service, I get an error.
Here is the command that I try (as root):
systemctl start postgresql
Here is the error:
Job for postgresql.service failed because the control process exited
with error code. See "systemctl status postgresql.service" and
"journalctl -xe" for detail.
I tried systemctl status postgresql.service and I found this:
Loaded: loaded (/usr/lib/systemd/system/postgresql.service; disabled
vendorpreset: disabled)
Active: failed (Result exit-code)... Process ...
ExecStartPre=/usr/bin/postgresql-check-db-dir ${PGDATA} (code=exited,
status=1/FAILURE)
... failed to start PostgreSQL... ...Unit postgresql.service...
...postgresql.service failed
I used journalctl -xe but that did not tell me anything meaningful.
To change the default data directory of Postgres, I tried this:
postgresql-setup initdb --pgdata=/mnt/windows-share/
But I got
failed to find PGDATA setting in --pgdata=/mnt/mar/data.service
How do I get Postgres installed with a customized data directory? I need it to be in a the "/mnt/" directory. I want to create all my databases on a USB stick.
To install Postgres on a customized location (e.g. home/postgres directory) follow these steps
install the required version of Postgres e.g. 13
create postgres directory in Home. and grant its access to posgres user
mkdir postgres
chown postgres:postgres postgres
usermod -m -d /home/postgres postgres
Move data directory to the new location as:
rsync -av /var/lib/pgsql/ /home/postgres/
update the location in postgres server as:
find / -name postgresql-9.5.service
vi /usr/lib/systemd/system/postgresql-9.5.service
update the data location in the file:
from the old location, e.g.
# Location of database directory
Environment=PGDATA=/var/lib/pgsql/13/data/
to the new location, e.g.
# Location of database directory
Environment=PGDATA=/home/postgres/13/data/"
Stop postgres, reload deamon and start postgres
stop postgres
systemctl daemon-reload
start postgres
Done...
I' ve solved the same problem on CentOS 6
Maybe u can try it.
Add your disk
Check your disk is existing (in my case new disk is /dev/sdb1/)
# fdisk -l
Mount new disk
# mkdir /hdd2
# mount -t ext3 /dev/sdb1 /hdd2/
Auto mount hard disk by add new line:
# vi /etc/fstab
Add line: /dev/sdb1 /hdd2 ext3 defaults 0 0
Config postgres
# service postgresql stop
# vi /etc/sysconfig/pgsql/postgresql
Add line: PGDATA=/hdd2/data
# service postgresql start
Hope it useful to you!!
I'm getting the following error when I try to run "mongod" in the terminal. I've tried uninstalling, reinstalling, and restarting the machine. Any suggestions on how to get it working would be amazing.
ERROR:
dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
See http://dochub.mongodb.org/core/startingandstoppingmongo
Side note:
Node also stopped working on my machine around the same time that I got this error.
events.js:72
throw er; // Unhandled 'error' event
^
Error: failed to connect to [localhost:27017]
Any help would be much appreciated!
This should work to ensure that the directory is set up in the right place so that Mongo can find it:
sudo mkdir -p /data/db/
sudo chown `id -u` /data/db
You need to create the directory on root /data/db or set any other path with the following command :
mongod --dbpath /srv/mongodb/
See the example link
I solved the problem with :
sudo mongod --dbpath=/var/lib/mongodb and then mongo to access the mongodb Shell.
Change the user of the new data directory:
chown mongodb [rute_directory]
And try another time to start the mongo service
service mongod start
I solve the same problem with this.
Daemons (usually ending with d) are normally started as services. Starting the service (daemon) will allow mongodb to work as designed (without permission changes if integrates well with your distro). I start it using the service named mongodb instead of starting mongod directly--on distro with systemd enable on startup then run like:
sudo systemctl enable mongodb
sudo systemctl start mongodb
or, on distro with upstart (if you have /etc/init) or init (if you have /etc/init.d) ( https://www.tecmint.com/systemd-replaces-init-in-linux/ ) instead run:
sudo service mongodb enable
sudo service mongodb start
If you have a distro with rc ("run commands") such as Gentoo (settings in /etc/init.d) (https://forums.gentoo.org/viewtopic-t-854138-start-0.html) run:
rc-update add mongodb default
/etc/init.d/mongodb start
In a distro/version of FreeBSD which still has rc (check whether your version switched to systemd, otherwise see below):
add the following line to /etc/rc.conf:
mongod_enable="YES"
then:
sudo service mongod start
After starting the service, an unpriveleged user can use mongo, and each user will have separate data.
I also got the error that "The file /data/db doesn't exist" when I tried to save my file using the "mkdir -p /data/db" command(using both with and without sudo command). But later on one site, a person named Emil answered that the path "/data/db" no longer works on Mac, so use "~/data/db" instead
i.e., use the command
mkdir -p ~/data/db
instead of previous command.
Moreover, use
mongod --dbpath ~/data/db
to run mongod
It worked for me, hope it work for others too facing the same problem
I am running Fedora 20 and installed MongoDB per the Red Hat installation guide on the official documentation. I was able to run the mongod daemon as a service without error the very first time but when I shut down my machine and came back, the service refused to start due to some failure.
In my log, listed after the successful run, I see this:
***** SERVER RESTARTED *****
ERROR: Cannot write pid file to /var/run/mongodb/mongod.pid: No such file or directory
If I try starting mongod or running mongod --repair manually, I get this message in a start up failure:
ERROR: dbpath (/data/db) does not exist.
Create this directory or give existing directory in --dbpath.
This is odd considering that in my config file in /etc/mongod.conf, the settings for the database path are as follows:
dbpath=/var/lib/mongo
Finally, if I run this command:
mongod --dbpath /var/lib/mongo
The daemon starts up just fine. However, I am unable to replicate that error free behavior for starting a service.
Can anyone tell me what exactly is wrong and how I can begin running mongod as a service?
EDIT
I get this message if I run mongod --config /etc/mongod.conf:
about to fork child process, waiting until server is ready for connections. forked process: 2702 ERROR: child process failed, exited with error number 1
The /var/run/mongodb directory did not exist, so I created and assigned it to the mongod user. That did not make much of a difference, unfortunately.
My /var/log/mongodb/mongod.log shows this message:
[initandlisten] exception in initAndListen: 10309 Unable to create/open lock file: /var/lib/mongo/mongod.lock errno:13 Permission denied Is a mongod instance already running?, terminating
What worked for me on Fedora 20: we need to create the temp dir on every boot, and that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf and put one line in it:
d /var/run/mongodb 0755 mongod mongod
That seems to handle it on restarts; if you don't want to restart right away, you can execute that with:
sudo systemd-tmpfiles --create mongodb.conf
(See the man pages for systemd-tmpfiles)
I have the same problem, I solved it temporarily, disabling SELinux, rebooted the machine, eliminated mongod.lock:
#rm /var/lib/mongo/mongod.lock
By creating the file /var/run/mongodb/mongo.pid (as mentioned in the configuration file /etc/mongod.conf):
#mkdir /var/run/mongodb
#touch /var/run/mongodb/mongod.pid
and giving 777 permissions:
#chmod 777 /var/run/mongodb/mongod.pid
and starting mongo:
#service mongod start
But the problem persists after restarting the machine. The folder and file disappear.
I've spent a while looking into this, and it appears as if the pid folder and file permissions don't work with the default daemon.
The simplest solution I've come across is disable the pid file by just putting a # in front of the line in the config file.
vi /etc/mongod.conf
find the line that says pidfilepath=/var/run/mongodb/mongod.pid and change it accordingly.
# pidfilepath=/var/run/mongodb/mongod.pid
For information on what commenting it out does check here.
http://docs.mongodb.org/manual/reference/configuration-options/#processManagement.pidFilePath
If you’re starting mongod as a service using:
sudo service mongod start
Make sure the directories defined for logpath, dbpath, and pidfilepath in your mongod.conf exist and are owned by mongod:mongod.
I was having the same problem running mongodb 3.0.4 on OpenSuse 13.2, and I found that the mongod directory under /var/run was missing. If I created the directory manually it would disappear after a reboot.
I solved it by adding the following lines to my /etc/init.d/mongod startup script:
mkdir -p /var/run/mongod
chown $MONGO_USER:$MONGO_GROUP /var/run/mongod
This worked for me in Ubuntu:
sudo kill $(sudo lsof -t -i:27017)
sudo rm -rf /tmp/mongodb-27017.sock
sudo rm -f /var/lib/mongo/mongod.lock
sudo rm -f /var/run/mongodb/mongod.pid
sudo mkdir -p /var/run/mongodb/
sudo touch /var/run/mongodb/mongod.pid
sudo chown -R mongodb:mongodb /var/run/mongodb/
sudo chown mongodb:mongodb /var/run/mongodb/mongod.pid
sudo service mongod start
i met the same issue,when i modify my mongod.conf as follow and problem resolved~
port=27017
dbpath=/usr/local/mongodb/data/db/
logpath=/usr/local/mongodb/logs
fork = true
tips: logpath is the logfile not a folder.
I just experience a similar problem on ubuntu. Encountered nearly every ERROR tips, like
child process failed, exited with error number 1
orchild process failed, exited with error number 100
or [signalProcessingThread] got signal 2 (Interrupt: 2), will terminate after current cmd ends
For many times I remove the Mongodb and try to install again, but the problem remains....
Finally I came to this way:
Backup your data first, then remove Mongodb with
#sudo apk-get autoremove mongodb-org
Find out all the files related with mongodb:
/#find -name mongo*
Delete them all with "rm" or "rmdir", including the packages in the /var/cache/... and everthing.
Then repeat the installation as the first time you did :
#echo "deb http://repo.mongodb.org/apt/ubuntu "$(lsb_release -sc)"/mongodb-org/3.0 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.0.list
#sudo apt-get update
#sudo apt-get install -y mongodb-org
It will run again.
Comment below the line from your "mongo.conf" file.
pidfilepath=/var/run/mongodb/mongod.pid
Following commands solved for cent os
ERROR:
service mongod status
Error starting mongod. /var/run/mongodb/mongod.pid exists
FIXED BY:
rm /var/lib/mongo/mongod.lock
chown -R mongod:mongod /var/log/mongodb/
chown -R mongod:mongod /var/run/mongodb/
chown -R mongod:mongod /var/lib/mongo/
chmod 777 /var/run/mongodb/mongod.pid
mongod --dbpath /var/lib/mongo
We need to create the temp dir location of pidfile /var/run/mongodb that's handled by systemd-tmpfiles. So, create a file /lib/tmpfiles.d/mongodb.conf as root:
lnx#> sudo su
lnx#> cd /lib/tmpfiles.d
lnx#> echo “d /var/run/mongodb 0755 mongod mongod” > mongodb.conf
Then reboot or run this command to activate that temp directory:
lnx#>sudo systemd-tmpfiles --create mongodb.conf
Start mongod service:
lnx#> sudo systemctl start mongod.service
Bibliography: Fedora And Mongodb · l33tsource