Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.

04
English| Deutsch LoginorSignup

Tutorials Tags Forums LinuxCommands Subscribe ISPConfig News

Tutorialsearch

Tutorials HowtoInstallandConfigureMongoDBonUbuntu16.04

HowtoInstallandConfigureMongoDBonUbuntu16.04

MongoDBisaNoSQLdatabasethatoffersahighperformance,high
ThistutorialexistsfortheseOSversions
availability,andautomaticscalingenterprisedatabase.MongoDBisaNoSQL
database,soyoucan'tuseSQL(StructuredQueryLanguage)toinsertand
Ubuntu16.04(XenialXerus)
retrievedata,anditdoesnotstoredataintableslikeMySQLorPostgres.
Ubuntu14.04LTS(TrustyTahr)
Dataisstoredina"document"structureinJSONformat(inMongoDBcalled
BSON).MongoDBwasfirstintroducedin2009andiscurrentlydevelopedby
Onthispage
thecompanyMongoDBInc.
Prerequisites
"MongoDBonly InstallMongoDBonUbuntu16.04
providespackagesfor Step1ImportingthePublicKey
64bitLTS(longterm Step2CreatesourcelistfileMongoDB
support)Ubuntu Step3Updatetherepository
releases.Forexample, Step4InstallMongoDB
12.04LTS(precise), ConfigureMongoDBusernameandpassword
14.04LTS(trusty), Step1Openmongoshell
16.04LTS(xenial), Step2Switchtothedatabaseadmin
andsoon." Step3Createtherootuser
mongodbsite. Step4Enablemongodbauthentication
Step5RestartMongoDBandtrytoconnect
Conclusion

Prerequisite
s
UbuntuServer16.0464bit
Rootprivileges

Whatwewilldointhistutorial:

InstallMongoDB
ConfigureMongoDB
Conclusion

InstallMongoDBonUbuntu16.04

Step1ImportingthePublicKey

GPGkeysofthesoftwaredistributorarerequiredbytheUbuntupackagemanagerapt(AdvancedPackageTool)toensurepackageconsistencyand
authenticity.RunthiscommandtoimportMongoDBkeystoyourserver.

sudoaptkeyadvkeyserverhkp://keyserver.ubuntu.com:80recvEA312927

Step2CreatesourcelistfileMongoDB

CreateaMongoDBlistfilein/etc/apt/sources.list.d/withthiscommand:

echo"debhttp://repo.mongodb.org/apt/ubuntu"$(lsb_releasesc)"/mongodborg/3.2multiverse"|sudotee
/etc/apt/sources.list.d/mongodborg3.2.list

Step3Updatetherepository

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 1/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04

updatetherepositorywiththeaptcommand:

sudoaptgetupdate

Step4InstallMongoDB

NowyoucaninstallMongoDBbytypingthiscommand:

sudoaptgetinstallymongodborg

Wehavetocreateanewmongodbsystemdservicefileinthe'/lib/systemd/system'directory.Gotothatdirectoryandcreatethenewmongodb
servicefile'mongod.service'withvim.

cd/lib/systemd/system/
vimmongod.service

Pastescriptbelow:

[Unit]
Description=Highperformance,schemafreedocumentorienteddatabase
After=network.target
Documentation=https://docs.mongodb.org/manual

[Service]
User=mongodb
Group=mongodb
ExecStart=/usr/bin/mongodquietconfig/etc/mongod.conf

[Install]
WantedBy=multiuser.target

Savethefileandexit.

Nowupdatethesystemdservicewithcommandbelow:

systemctldaemonreload

Startmongodbandadditasservicetobestartedatboottime:

systemctlstartmongod
systemctlenablemongod

Nowcheckthatmongodbhasbeenstartedonport27017withthenetstatcommand.

netstatplntu

ConfigureMongoDBusernameandpassword

WhentheMongoDBpackagesareinstalledyoucanconfigureusernameandpasswordforthedatabaseserver:

Step1Openmongoshell

BeforeyousetupausernameandpasswordforMongoDB,youneedtoopenthemongodbshellonyourserver.Youcanloginbytyping:

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 2/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04

mongo

IfyougeterrorFailedglobalinitialization:BadValueInvalidornouserlocaleset.PleaseensureLANGand/orLC_*
environmentvariablesaresetcorrectly,trythecommand:

exportLC_ALL=C
mongo

Step2Switchtothedatabaseadmin

Onceyou`reintheMongoDBshell,switchtothedatabasenamedadmin:

useadmin

Step3Createtherootuser

Createtherootuserwiththiscommand:

db.createUser({user:"admin",pwd:"admin123",roles:[{role:"root",db:"admin"}]})

Desc:Createuseradminwithpasswordadmin123andhavethepermission/roleasrootandthedatabaseisadmin.

NowtypeexittoexitfromMongoDBshell.

Step4Enablemongodbauthentication

Editthemongodbservicefile'/lib/systemd/system/mongod.service'withyoureditor.

vim/lib/systemd/system/mongod.service

Onthe'ExecStart'line9,addthenewoption'auth'.

ExecStart=/usr/bin/mongodquietauthconfig/etc/mongod.conf

Saveandexit.

Reloadthesystemdservice:

systemddaemonreload

Step5RestartMongoDBandtrytoconnect

NowrestartMongoDBandconnectwiththeusercreated.

sudoservicemongodrestart

andconnecttothemongodbshellwiththiscommand:

mongouadminpadmin123authenticationDatabaseadmin

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 3/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04

andyouwillseetheoutputlikethis:

Conclusion

AwellknownNoSQLdatabasethatoffershighperformance,highavailability,andautomaticscalingisMongoDB.ItisdifferentfromtheRDBMS
suchasMySQL,PostgreSQL,andSQLiteasitdoesnotuseSQLtosetandretrievedata.MongoDBstoresdatain`documents`calledBSON
(binaryrepresentationofJSONwithadditionaltypesofinformation).MongoDBisonlyavailablefor64bitLongTermSupportUbuntuRelease.

viewaspdf| print

Sharethispage: Tweet
Follow@howtoforgecom 28.1Kfollowers Recommend 29 7

Suggestedarticles

CalaJeansLevi&aposs Servermonitoringwith VoosdeSalvadoraBelo ThePerfectServer


505Regular... MuninandMoniton... Horizonte Debian8.4Jessie...
R$149.99 ApartirdeR$210
Ad Submarino howtoforge.com Ad SubmarinoViagens howtoforge.com

VocMereceViajarMais HowtoInstalland HowtoInstallNagioson ThePerfectServer


ConfigureMongoDBon... Ubuntu16.04 Ubuntu16.04(Xenial...
Ad MaxMilhas howtoforge.com howtoforge.com howtoforge.com

18Comment(s)
Addcomment
Name* Email*

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 4/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04

p

Submitcomment
I'm not a robot
reCAPTCHA
Privacy - Terms

Comments

From:Mr.Geek Reply

Seemstobeinterestingfortheresearchingtasksofourinstitute!Whataboutthestabilityofthisrelease?

From:EndUser Reply

Thankyoufortheinstructions,workedlikeacharmnoteinstep4toreloaditshouldbe"systemctldaemonreload"ratherthan"systemddaemon
reload"

From:JessireeDeVera Reply

Thankyou!

From:Antonio Reply

bestguide!

From:lumazi Reply

IranthroughtheinstallbutIamexpernecinganissueatstep#3.IrunthecreateUsercommandbutIreceivethefollowingerror:
Error:couldn'tadduser:notauthorizedonadmintoexecutecommand
Iamconnectedtotheadmindatabasebutcannotexecutethecommand.Idonotseetheauthflaginthemongod.servicefilesoIdon'tthinkI'm
connectingwithauthenabled.

From:PeterCarter Reply

Ifanyonehasproblemsgettingsystemddaemonreloadtowork,youcanprobablyusesystemctldaemonreload.Workedforme,anyway.

From:Oliver Reply

CouldyoualsomakeaHowToForgeonhowtocompilethec++drivereasily?Todaythisisamessandapain.Thanks

From:swapnaja Reply

ThankYouforInstructionsThisisworkforme.

From:rajuprasad Reply

thanksforthistutorial.

From:GuyHoltzman Reply

Thanks,
IamgettingExcessargumentsasoutputjustbeforestep5.
Icontinuedanditseemstowork,butIdonotknowwhatistheaffectofthiserrorandhowtosolveit,anyideas?
Guy

From:BrucklynBoy Reply

Chapter'ConfigureMongoDBusernameandpassword','Step4Enablemongodbauthentication':
Reloadthesystemdservicesays'systemddaemonreload',butshouldinsteadbe'systemctldaemonreload'

From:matt Reply

thanks!

From:invaliduser Reply

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 5/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04
anothermethodiferrorin:mongouadminpadmin123authenticationDatabaseadmin
with:mongou"admin"p"admin123"authenticationDatabaseadmin
workstomeonlinuxMINT18(sarah)

From:selva Reply

Thisisworkforme.thankyou.

From:Chien Reply

Thankforshare!

From:Jonathan Reply

Instep4Ihadtousesystemctldaemonreloadvicesystemddaemonreload.

From:MotiurRehman Reply

ThankYouverymuchforyoursupportthroughthistutorial(manual),
Awsomeimplementationandinstallationwithoutanyerror,greatandgreatjob.
MayAllahgiveyoumoreknowledgetohelpuslikethis.
ThankYou

From:freeelectron Reply

sudoaptgetinstallymongodborgdidnotworkformeIhadtodosudoaptgetinstallymongodb

Tutorials HowtoInstallandConfigureMongoDBonUbuntu16.04

AEREOCONFINSSALVADOR
20/06/2017|
ApartirdeR$225,90

Signupnow!

TutorialInfo

Author: MuhammadArul
Tags: linux,ubuntu

ShareThisPage

Tweet Follow 28.1Kfollowers


Recommend 29

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 6/7
08/04/2017 HowtoInstallandConfigureMongoDBonUbuntu16.04

SapatnisBurnSanDiego
MasculinoMarinho
R$99.90 R$56.91
Aproveite

XenforoskinbyXenfocus Contribute Contact Help Imprint

HowtoforgeprojektfarmGmbH. Terms

https://www.howtoforge.com/tutorial/installmongodbonubuntu16.04/ 7/7

You might also like