How to install Mongodb on Redhat\Centos Linux using Tarball .tgz?


 


                    


                            In this article , we will see how we can install Mongodb 5.0 Enterprise server 

            on CentOS 7 using .tgz Tarball.


OS Platform       : REDHAT/CENTOS 7 Linux

Software             : Mongodb 5.0 Enterprise Server

Method               :  Tarball .tgz


Step 1: Install the dependencies required for the MongoDB Enterprise tarball

$ sudo yum install cyrus-sasl cyrus-sasl-gssapi cyrus-sasl-plain krb5-libs libcurl net-snmp openldap openssl xz-libs



Step 2: Download the tarball from the Mongodb download Centre

Go to the MongoDB download center page and select appropriate version of MongoDB, OS Platform version and package as tgz

After downloading , transfer the tar file from your base machine to target Linux machine via winscp or if you have internet access in your linux machine download it via wget.

$ wget https://downloads.mongodb.com/linux/mongodb-linux-x86_64-enterprise-rhel70-5.0.17.tgz



Step 3 : Extract the tar .tgz file and rename it

# tar -zxvf mongodb-linux-x86_64-enterprise-rhel70-5.0.17.tgz
#  mv mongodb-linux-x86_64-enterprise-rhel70-5.0.17 mongodb

Step 4 : Create mongod os user account and set the correct permission to the binaries

sudo groupadd mongodb
sudo useradd -m mongod
sudo usermod -a -G mongodb mongod
sudo passwd mongod


 chown -R mongod:mongodb /software/mongodb

Step 5 : Create mongodb data and log directories

Create the mongodb data directories , log directories and give necessary permission set to the mongod user.

sudo mkdir -p /var/lib/mongo
sudo mkdir -p /var/log/mongodb
sudo chown -R mongod:mongodb /var/lib/mongo
sudo chown -R mongod:mongodb /var/log/mongodb

Step 6 : Create mongodb configuration file 

Create the mongodb configuration file which will ease the usage of configuration each time and repeatability.

vi mongod.conf
systemLog:
   destination: file
   path: "/var/log/mongodb/mongod.log"
   logAppend: true
storage:
   journal:
      enabled: true
storage:
   dbPath: /var/lib/mongo
processManagement:
   fork: true
net:
   bindIp: 127.0.0.1#this is the ip of the client from which mongod accept connection
   port: 27017
security:
   authorization: enabled
Step 7 : Add the mongodb binary location to the bash profile

[root@centos1 mongo]$ su - mongod
[mongod@centos1 mongo]$ vi ~/.bashrc

export PATH=$PATH:/software/mongodb/bin/

[mongod@centos1 mongo]$ source ~/.bashrc



Step 8 : Start and initialize the mongod 

Now initialize the mongod using config file

mongod -f mongod.conf

Step 9 : Connect to mongod server and create first admin user

  • Now connect to the mongod server via mongo shell(deprecated) recent one is mongosh . But as far this demo am using mongo shell.
mongo --port 27017


  • Next we need to create first admin user . Because we enabled the security authorization . Until or unless we create the first admin user it won't allow you do further operations and won't show any result for your queries.  See the above image its not giving any output for the show dbs command.
db.createUser(
   {
       user: "mongoadmin", 
       pwd: "*******", 
       roles:["root"]
   })


        As per the localhost exception you are only allowed to create the first admin user without                 authentication for further operations you need to authenticate first.



Step 10 : Authenticate with mongodb and load some data and test it

  • Authenticate with mongoadmin user and load sample data to test it.
 
db.auth("mongoadmin","*******")
show dbs
user mongokart
db.createCollection("product")
db.product.insert({
  sku: "111445GB3",
  title: "Simsong One mobile phone",
  description: "The greatest Onedroid phone on the market .....",

  manufacture_details: {
    model_number: "A123X",
    release_date: new ISODate("2012-05-17T08:14:15.656Z")
  },

  shipping_details: {
    weight: 350,
    width: 10,
    height: 10,
    depth: 1
  },

  quantity: 99,

  pricing: {
    price: 1000
  }
})





  • Query the data from the product collection in the  mongokart database.
 db.product.find().pretty()





Hurray! we have reached the end of this article. We have successfully installed MongoDB 5.0 Enterprise server , created the sample database and tested it.

Hope you liked the content (:

Please provide your collaborative ideas , suggestion and valuable feedback’s.

Keep Learning ! Keep Sharing!

No comments:

Post a Comment