Mongodb installation & configuration on rhel

Page 1

LinuxTechLab.com

MongoDB installation & configuration on RHEL/CentOS

Originally published on

LinuxTechLab.com


MongoDB is one of the famous , free & open source document oriented No-SQL database server. MongoDB uses JSON like document format to store data in database, rather than using rows & columns, as used in SQL databases like MS-SQL, mysql etc. When compared with SQL databases or relational databases, MongoDB are far more faster, provide far better performance, are easy to scale & address several shortcomings of any relational database available. MongoDB can handle large amounts of structured or unstructured data or can even support multiple data structures. No-SQL databases, especially MongoDB are the kind of databases that are required to address the needs of data being used today, whether you need databases for IOT or online gaming or for big data, MongoDB will be a right fit. In this tutorial, we will be installing MongoDB community edition (Enterprise version costs money ) on RHEL/CentOS 7, we have tested this method to be working on Centos 7 & same should work on RHEL 7 or earlier versions of OS as well. Remember one thing, MongoDB does not support RHEL 5 or earlier versions, also latest versions of MongoDB does not support 32 Bit system as well. ( Recommended Read : Installing & configuring MariaDB on RHEL/CentOS )

Adding repository for MongoDB At the time of writing this tutorial, 3.4 is the latest version of MongoDB & we will be installing same on our system. For MongoDB installation, we will first create a yum repo file for the official MongoDB repository. So firstly create a file, mongodb-org3.4.repo in /etc/yum.repos.d, $ vi /etc/yum.repos.d/mongodb-org-3.4.repo & add the following repository information, [mongodb-org-3.4] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodborg/3.4/x86_64/ gpgcheck=1 enabled=1


gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc

now save the file & exit. If you are performing installation on earlier versions of RHEL/Centos (mostly version prior to 6.5) than you might want to install earlier versions of MongoDb, as latest one might not work for you. For earlier versions, just replace 3.4 with earlier version i.e. $ vi /etc/yum.repos.d/mongodb-org-2.6.repo [mongodb-org-2.6] name=MongoDB 2.6 Repository baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/ gpgcheck=0 enabled=1 Now that we have our repository ready, we can install MongoDB on our server. Note :– Odd numbered versions of MongoDB are meant for development & should not be used in production environment.

MongoDB Installation To install mongodb on server, execute the following command from terminal $ yum install mongodb-org This will install mongodb on our server. Once installed, we need to start the service & enable it start after boot, $ systemctl start mongod $ systemctl enable mongod

Testing MongoDB To connect to mongodb after its service has been started, open terminal & type $ mongo


Once logged in, we can see all the availabe databases by using $ show dbs To create a new database or to use an already created database, issue command $ use database Though this command will create a database but it will not save the database until some data has been added to it. We will now add a collection named ‘inventory’ in the database & to do that command is $ db.inventory.save ( { inventory : “Desktops” } ) After the collection has been added , database will be automatically saved & we can verify it by executing command “show dbs”. This completes our tutorial, if you have any suggestion or query, please do tell us using the comment box below. ( Recommended Read : MariaDB administration commands for beginners ) If you think we have helped you or just want to support us, please consider these :Connect to us: Facebook | Twitter | Google Plus

LinuxTechLab.com



Turn static files into dynamic content formats.

Create a flipbook
Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.