MonogDB 3.4 in Ubuntu 20.04 - mongodb

In the production application, we are using MongoDB 3.4 version.I have installed ubuntu 20.04 LTS on my local machine and tried to install Mongo 3.4 and bang my head against the wall. Please let me know your thoughts. Here are my steps:
apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
echo "deb http://repo.mongodb.com/apt/ubuntu "$(lsb_release -sc)"/mongodb-enterprise/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-enterprise-3.4.list
sudo apt-get update
sudo apt-get install -y mongodb-org

Well I just did this in a more "handmade way" perhaps...
Downloaded the application from here: https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-3.4.24.tgz
(it is the, let's call vanila version from the mongodb page)
Uncompressed it on /opt:
tar zxf mongodb-linux-x86_64-3.4.24.tgz -C /opt/
Symlink for shorter name:
ln -s /opt/mongodb-linux-x86_64-3.4.24 /opt/mongo
Created the user for mongo:
useradd -r mongod
then added the systemctl command:
echo "[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongod
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/mongod.service
Reloaded systemctl:
systemctl daemon-reload
Then created the /etc/mongod.conf with the following content:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# Where and how to store data.
storage:
dbPath: /opt/mongo/database/
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongod.log
# network interfaces
net:
port: 27017
# bindIp: 127.0.0.1
#processManagement:
#security:
#operationProfiling:
#replication:
# replSetName: "mongodb-keys-replica-set"
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp:
then start the service:
systemctl start mongod
Adjust the configurations and directory path as needed.
It works, is a somehow handmade solution for a legacy version for that ubuntu version. Won't update with apt-get or related... but just works as it should.
If in local, for testing purposes, maybe it's not a bad idea go with a docker image... but just a suggestion, not the answer to your question.

The above answer is correct however don't forget to:
create directories and files, change owner
mkdir /opt/mongo/database
touch /var/log/mongod.log
chown mongod:mongod /var/log/mongod.log
chown -R mongod:mongod /opt/mongodb-linux-x86_64-3.4.24
chown mongod:mongod /opt/mongo
execute as root this part, link to mongo was wrong and should be as below:
echo "[Unit]
Description=High-performance, schema-free document-oriented database
After=network.target
[Service]
User=mongod
ExecStart=/opt/mongo/bin/mongod --quiet --config /etc/mongod.conf
[Install]
WantedBy=multi-user.target" > /etc/systemd/system/mongod.service

There is no easy way for this it seems because the official documentation itself says that for version 3.4, the only supported ubuntu versions are 16.04 and 14.04 (https://docs.mongodb.com/v3.4/tutorial/install-mongodb-on-ubuntu/).
I tried following the above steps by ignivs but encountered this error everytime:
Failed to start mongod.service: Unit mongod.service not found.

Related

Can't start mongodb through systemctl, error logs won't show up

I cannot boot MongoDB via systemctl.
When I try, I get an error, but nothing comes through the log.
When I try and run it manually via $ /usr/bin/mongod --config /etc/mongod.conf no error message comes through the log.
When I turn off logging in mongod.conf, an error message comes out that I don't have rights to the directory with the data (which is to be expected).
However, I can boot the process with sudo such as:
$ sudo /usr/bin/mongod --config /etc/mongod.conf, the process runs but it is tied to my terminal so if my session closes so does MongoDB. Hence why I am trying to run it with systemctl.
Then when I try and run with sudo in my service such as:
ExecStart=/usr/bin/sudo /usr/bin/mongod --config /etc/mongod.conf
Then it doesn't start and no error log comes through.
My conf file:
# mongod.conf
# for documentation of all options, see:
# Where and how to store data.
storage:
dbPath: /var/lib/mongodb
journal:
enabled: true
# 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
# how the process runs
processManagement:
timeZoneInfo: /usr/share/zoneinfo
My service:
[Unit]
Description=MongoDB Database Server
Documentation=https://docs.mongodb.org/manual
After=network.target
[Service]
Restart=always
User=mongodb
Group=mongodb
EnvironmentFile=-/etc/default/mongod
ExecStart=/usr/bin/sudo /usr/bin/mongod --config /etc/mongod.conf
PIDFile=/var/run/mongodb/mongod.pid
# file size
LimitFSIZE=infinity
# cpu time
LimitCPU=infinity
# virtual memory size
LimitAS=infinity
# open files
LimitNOFILE=64000
# processes/threads
LimitNPROC=64000
# locked memory
LimitMEMLOCK=infinity
# total threads (user+kernel)
TasksMax=infinity
TasksAccounting=false
# Recommended limits for mongod as specified in
# https://docs.mongodb.com/manual/reference/ulimit/#recommended-ulimit-settings
So it becomes an impossible question. When I try and boot it through systemctl no error log comes through /var/log/mongodb/mongod.log. If I run it manually I get an error saying that I don't have access to the data folder since the data folder is owned by the mongodb user, which is expected.
What can I do to see what is causing my service above to fail? I don't want to use sudo in my ExecStart command but whether I do or I don't I get the same problem: the service fails to start and no logs come through my Mongo log file.
Check of your service is failed
systemctl is-failed mongodb.service
Get failure logs
Journalctl is a utility for querying and displaying logs from journald, systemd's logging service.
get latest 20 lines of logs which will you failure details
journalctl | grep mongod | tail -n20
Use journalctl -u service and tail to get top 20 logs
journalctl -u mongodb.service | tail -n20
Get list of all failed services
systemctl list-units --failed
Read - https://www.cyberciti.biz/faq/systemd-systemctl-list-all-failed-units-services-on-linux/

installing and running mongodb in codeanywhere

i used this code:
$ mkdir data
$ echo 'mongod --bind_ip=$0.0.0.0 --dbpath=data --nojournal "$#"' > mongod
$ chmod a+x mongod
i have made a file called mongodb that contains this:
​ mongod --bind_ip=$0.0.0.0 --dbpath=data --nojournal "$#"
but when i run
./mongod
i get this and it doesn't work:
https://i.stack.imgur.com/L9224.png
Assuming you are using one of the recent versions of Mongo.
Try this:
Step1- Make a directory, say database, its path being /home/cabox/database
Step2- In the same level as the directory database, create a file named mongod.log, by using touch /home/cabox/mongod.log
Step3- Create a configuration file for our database, mongod.conf using
touch /home/cabox/mongod.conf
Step4- Now open this file using vi and put following lines in it
systemLog:
destination: file
path: "/home/cabox/mongod.log"
logAppend: true
processManagement:
fork: true
storage:
dbPath: "/home/cabox/database"
journal:
enabled: true
engine: "mmapv1"
mmapv1:
smallFiles: true
net:
bindIp: 0.0.0.0
Step5- Save this file and start mongod by running:
mongod --config /home/cabox/mongod.conf
Step6- Start the shell: mongo
Hopefully everything should be working fine by now. The problem with your method was that mongod was using wired Tiger storage engine by default, which causes space related problems in containers like codeanywhere which have a small disk size.
P.S - In the conf file, make sure you indent using spaces and not tabs.
You can shutdown the server by using:
mongo --eval "db.getSiblingDB('admin').shutdownServer()"
To check whether it has been successfully started or shutdown:
netstat -ntulp|grep 27017

Mongodb 3.4 on 64bit Ubuntu 16.04 mongodb-27017.sock ERROR

There are a few posts related Mongodb 3.2, but when I attempted to install 3.4 the startup does not occur. Instead an unusual error appears in the log file (shown at the very end of the listing).
Is this perhaps because of an older version that was installed?
I did do an apt-get remove and purge.
Can anybody suggest why the error appears?
I followed the steps below, as outlined here,
$ sudo apt-get remove mongodb*
$ sudo apt-get purge mongodb*
$ sudo rm -rf /usr/lib/mongodb
$ sudo rm -rf /usr/log/mongodb
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
$ echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
$ sudo apt-get update
$ sudo apt-get install -y mongodb-org
..
..
E: There were unauthenticated packages and -y was used without --allow-unauthenticated
$ sudo apt-get install mongodb-org # removed -y to get it going
..
..
Setting up mongodb-org (3.4.2) ...
$ sudo chown -R mongodb:mongodb /var/log/mongodb
$ sudo chown -R mongodb:mongodb /var/lib/mongodb # modified ownership in view of what is stated on the mongodb installation note
$ # created the following file
$ cat /etc/systemd/system/mongod.service
[Unit]
Description=MongoDB Database Service 3.4
Wants=network.target
After=network.target
[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongod --quiet --config /etc/mongod.conf
StandardOutput=syslog
StandardError=syslog
[Install]
WantedBy=multi-user.target
# startup
$ sudo systemctl daemon-reload
$ sudo service mongod start
# nothing happens, I then viewed the log file and the following error appears:
$ cat /var/log/mongodb/mongod.log
2017-02-08T22:08:26.155+0000 I CONTROL [main] ***** SERVER RESTARTED *****
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] MongoDB starting : pid=11384 port=27017 dbpath=/var/lib/mongodb 64-bit host=12g
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] db version v3.4.2
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] OpenSSL version: OpenSSL 1.0.2g 1 Mar 2016
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] allocator: tcmalloc
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] modules: none
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] build environment:
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distmod: ubuntu1604
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] distarch: x86_64
2017-02-08T22:08:26.159+0000 I CONTROL [initandlisten] target_arch: x86_64
2017-02-08T22:08:26.159+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 } }, systemLog: { destination: "file", logAppend: true, path: "/var/log/mongodb/mongod.log", quiet: true } }
2017-02-08T22:08:26.178+0000 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
Failed to unlink socket file /tmp/mongodb-27017.sock Operation not permitted
That means the mongod process was started by root user.So you can just remove the sock file or run this command to fix this issue :
sudo chown `whoami` /tmp/mongodb-*.sock
Make sure that the port you assign needs to be accessible and not blocked by your firewall and then just restart the mongod process.
The waiting for connections message in the console output indicates
that the mongod.exe process is running successfully.
You can check out Install MongoDB Community Edition on Ubuntu.
Hope this helps.
#mcgraddy, thanks, that was helpful indeed. Creating the directory and copying the service file was the answer.
$ sudo cp /etc/systemd/system/mongod.service /etc/systemd/system/mongodb.service
$ sudo mkdir -p /data/db
$ sudo chown -R $USER:$USER /data
I had to change ownership for /data.
Starting the service and viewing status shows everything is running as expected:
$ sudo service mongod start
$ sudo systemctl status mongodb
● mongodb.service - MongoDB Database Service
Loaded: loaded (/etc/systemd/system/mongodb.service; enabled; vendor preset:
Active: active (running) since Thu 2017-02-09 13:26:07 GMT; 9min ago
Main PID: 1184 (mongod)
CGroup: /system.slice/mongodb.service
└─1184 /usr/bin/mongod --quiet --config /etc/mongod.conf
Feb 09 13:26:07 systemd[1]: Started MongoDB Database Service.

MongoDB 3.2.9 fails to start as a service on CentOS

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

Enabling mongodb auth

I have an install of ubuntu 14.04 x64 The only thing I have done to it is fresh update and install mongodb and pritunl. Here is how I installed both
$ nano /etc/apt/sources.list.d/mongodb-org-3.0.list
deb http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.0 multiverse
$ nano /etc/apt/sources.list.d/pritunl.list
deb http://repo.pritunl.com/stable/apt trusty main
$ apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv 7F0CEB10
$ apt-key adv --keyserver hkp://keyserver.ubuntu.com --recv CF8E292A
$ apt-get update
$ apt-get install pritunl mongodb-org
$ service pritunl start
Now I would like to enable auth on mongodb 3.0.9 for this I have used guide here
https://medium.com/#matteocontrini/how-to-setup-auth-in-mongodb-3-0-properly-86b60aeef7e8#.a1nfxsy3a
After I create the first user and I
security:
authorization: enabled
I run into problems I cant make any connection from the locahost here is the error I receive
~# mongo pritunl --port 27017 -u admin -p passwordhere --authe nticationDatabase admin
MongoDB shell version: 3.0.9
connecting to: 127.0.0.1:27017/pritunl
2016-02-08T00:18:54.096-0500 W NETWORK Failed to connect to 127.0.0.1:27017, re ason: errno:111 Connection refused
2016-02-08T00:18:54.098-0500 E QUERY Error: couldn't connect to server 127.0. 0.1:27017 (127.0.0.1), 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
Or attempting to connect to admin
~# mongo admin — port 27017 -u admin -p password — authenticationDatabase admin
MongoDB shell version: 3.0.9
connecting to: 127.0.0.1:27017/admin
2016–02–07T09:54:09.436–0500 W NETWORK Failed to connect to 127.0.0.1:27017, reason: errno:111 Connection refused
2016–02–07T09:54:09.438–0500 E QUERY Error: couldn’t connect to server 127.0.0.1:27017 (127.0.0.1), 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
Or any other way I try and make a connection. I feel like I am missing something simple. I thought maybe I was screwing up the user creation so I have used tried using http://3t.io/mongochef/ gui to take my potential typing errors out of the user creation.
I have been fighting this for a few days and wearing google out but not getting traction. At this point I am will to pay for some help in figuring out what Im messing up but I would like to know how to fix it so I have the knowledge of how to implement basic security. I can pay with bitcoin
# 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
#processManagement:
security:
authorization: enabled
#operationProfiling:
#replication:
#sharding:
## Enterprise-Only Options:
#auditLog:
#snmp: