sábado, 9 de março de 2019

Installing MongoDB

This post is about my first impression installing MongoDB, since this is my second installation I'm writing acording I'm discovering things, and for my surprise mongo is very similar to MySQL, apart from the fact the mongo is document oriented and MySQL is tabular all other administration task is very close to our friend DB MySQL.

Preparing


Download

We can download mongo from here https://www.mongodb.com/download-center/community, there is  three methods for installing, Package manager, package and Tar-balls. I choose to install from a downloadble package from the site, you can use wget to get the last version of RPM or you can choose other method or package from the site above:

wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-server-4.0.6-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-mongos-4.0.6-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-tools-4.0.6-1.el7.x86_64.rpm
wget https://repo.mongodb.org/yum/redhat/7/mongodb-org/4.0/x86_64/RPMS/mongodb-org-shell-4.0.6-1.el7.x86_64.rpm
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel70-4.0.6.tgz

Create users


Usualy mongo run as mongod user and mongod group, the installer create this user and group but for a professional installation you can create before as bellow:

# groupadd mongod
# useradd mongod -g mongod
# passwd mongod

Creating directories


I create two separates lv from a single separate vg and make them permanent from boot and change the owner to mongod you can copy the process from http://www.dhnomura.com/2013/07/linux-logical-partitions.html

mkdir -p /mongodb/data && mount -t ext4 /dev/mongo_vg/mongodb_data_lv /mongodb/data
mkdir -p /mongodb/log && mount -t ext4 /dev/mongo_vg/mongodb_log_lv /mongodb/log

chown -R mongod:mongod /mongodb

Disable SE Linux


From the installation guide you can make mongod able to read and write to other directories diferents from the default, but I find easier to simple disable SE Linux and you can do this like https://www.tecmint.com/disable-selinux-temporarily-permanently-in-centos-rhel-fedora/ here is a very good explanation.

Installing


It relative simple to install from a rpm package just type rpm -ivh like bellow:

rpm -ivh mongodb-org-*
warning: mongodb-org-mongos-4.0.6-1.el7.x86_64.rpm: Header V3 RSA/SHA1 Signature, key ID e52529d4: NOKEY
Preparing...                          ################################# [100%]
Updating / installing...
   1:mongodb-org-tools-4.0.6-1.el7    ################################# [ 25%]
   2:mongodb-org-shell-4.0.6-1.el7    ################################# [ 50%]
   3:mongodb-org-server-4.0.6-1.el7   ################################# [ 75%]
Created symlink from /etc/systemd/system/multi-user.target.wants/mongod.service to /usr/lib/systemd/system/mongod.service.
   4:mongodb-org-mongos-4.0.6-1.el7   ################################# [100%]

Ok now we have mongo installed, let's prepare do some post installation tasks.

Post-Install


Edit Path location


Very similar to MySQL, Mongo create a parameter file in /etc called mongod.conf where you define startup parameter, let's change two, path and dbPath, we gonna tell mongo where to storage our files outside the default location.

Edit the /etc/mongod.conf and alter these two parameters, at the end we have a file like this:

# where to write logging data.
systemLog:
  destination: file
  logAppend: true
  path: /mongodb/log/mongodb/mongod.log

# Where and how to store data.
storage:
  dbPath: /mongodb/data
  journal:
    enabled: true


Starting / Stop


We use Linux Systemctl to stop/start mongodb service, like bellow

systemctl status mongod
systemctl start mongod
systemctl status mongod


Nenhum comentário: