Install MongoDB

In this tutorial, we will prepare and start an installation of MongoDB Enterprise Edition on the CentOS operating system, for 64-bit versions of Red Hat Enterprise Linux Operating Systems (RHEL).
RHEL / CentOS 8; RHEL / CentOS 7; RHEL / CentOS 6;
Installing MongoDB using the YUM package manager
with any test editor (vi.vim.nano) we will create an installation file through yum.
vi /etc/yum.repos.d/mongodb-enterprise-4.4.repo
Add to following parameters:
[mongodb-enterprise-4.4] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/4.4/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-4.4.asc
The version we are going to install is the latest one to keep Banco MongoDB more unstable with the following command:
yum install -y mongodb-enterprise
Or Install a specific version of MongoDB;
yum install -y mongodb-org-4.4.0 mongodb-org-server-4.4.0 mongodb-org-shell-4.4.0 mongodb-org-mongos-4.4.0 mongodb-org-tools-4.4.0
Note:
If the package manager was used, MongoDB will create a user account and the following directories will be used by default.
/var/lib/mongo (the data directory)
/var/log/mongodb (the log directory)
Now you have the advantage of doing the whole procedure with a single Click using our scripts.
Install Auto Database MongoDB for Centos6/7.x
Installation via .tgz files
Download the .tgz file, decompress the file with the following commands:
Download MongoDB
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-rhel62-4.4.0.tgz
tar -zxvf mongodb-linux-*-4.4.0.tgz
Copy Binaries to a PATH variable directory like /usr /local /bin:
cp /path/to/the/mongodb-directory/bin/* /usr/local/bin/
Create symbolic links to the binaries:
ln -s /path/to/the/mongodb-directory/bin/* /usr/local/bin/
How to install custom and need to create default MongoDB directories:
mkdir -p /var/lib/mongo
mkdir -p /var/log/mongodb
The MongoDB Database uses the user account for this reason and it is necessary to define the owner and the group of these directories.
chown -R mongod:mongod <directory>
The MongoDB installation documentation states that:
'The current SELinux Policy does not allow the MongoDB process to access /sys/fs/cgroup, which is required to determine the available memory on your system. If you intend to run SELinux in enforcing mode, you will need to make the following adjustment to your SELinux policy:'
Configuring SELINUX with a text editor edit vi /etc/selinux/config as follows:
SELINUX=Disabled
Verify that the Operating System has checkpolicy package installed:
yum install checkpolicy
Resources Prerequisites
Unix-type operating systems limit some processes that can directly impact Banco MongoDB's operations. For this reason, starting with the version of MongoDB4.4, it can start with an error if the ulimit is lower than 64000.
Create a custom memory file mongodb_cgroup_memory.te:
cat> mongodb_cgroup_memory.te <<
módulo
EOF mongodb_cgroup_memory 1.0; require {
type cgroup_t;
digite mongod_t;
pesquisa de dir de classe;
arquivo de classe {getattr open read};
}
# ============= mongod_t ==============
permitir mongod_t cgroup_t: dir search;
permitir mongod_t cgroup_t: arquivo {getattr open read};
EOF
Let's compile mongodb_cgroup_memory.te to load the policy modules
checkmodule -M -m -o mongodb_cgroup_memory.mod mongodb_cgroup_memory.te
semodule_package -o mongodb_cgroup_memory.pp -m mongodb_cgroup_memory.mod
sudo semodule -i mongodb_cgroup_memory.pp
Run MongoDB.
To run MongoDB, run the MongoDB process at the system prompt:
mongod --dbpath /var/lib/mongo --logpath /var/log/mongodb/mongod.log --fork
Now we check if MongoDB has been successfully launched.
tail -200f /var/log/mongodb/mongod.log:
Ready to start using MongoDB.
mongo