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
sudo groupadd mongodbsudo useradd -m mongodsudo usermod -a -G mongodb mongodsudo 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/mongosudo mkdir -p /var/log/mongodbsudo chown -R mongod:mongodb /var/lib/mongosudo 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: filepath: "/var/log/mongodb/mongod.log"logAppend: truestorage:journal:enabled: truestorage:dbPath: /var/lib/mongoprocessManagement:fork: truenet:bindIp: 127.0.0.1#this is the ip of the client from which mongod accept connectionport: 27017security: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"]})
- Now if I try to create another user . It will through error because of the local host exception
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 dbsuser mongokartdb.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