This article describes how to install MongoDB Community Edition on CentOS Linux. The same installation applies to RedHat Linux versions.
Versions:
Operating System: CentOS Linux 7 – 64bit
MongoDB: MongoDB Community Edition 3.2
If you want to install Sharded Cluster you may want to read below article.
“Deploy Sharded Cluster with Keyfile Access Control on Red Hat Enterprise Linux or CentOS Linux”
Step 1: Create a User For Administration
1 2 | [root@mongodbserv ~]# adduser mongodb [root@mongodbserv ~]# passwd mongodb |
Step 2: Configure yum For Installation
You can also install directly with .rpm. You can download packages at https://www.mongodb.com/download-center#community. For YUM configuration, file mongodb-org-3.2.repo is created under /etc/yum.repos.d and set as follows.
1 2 3 4 5 6 7 8 | [root@mongodbserv ~]# vi /etc/yum.repos.d/mongodb-org-3.2.repo [mongodb-org-3.2] name=MongoDB Repository baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.2/x86_64/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.2.asc |
Step 3: Install MongoDB with mongodb user
1 | [mongodb@mongodbserv ~]$ sudo yum install -y mongodb-org |
Step 4: Start MongoDB
MongoDB is enabled using the mongod process. The MongoDB service is started as follows.
1 | [mongodb@mongodbserv ~]$ sudo service mongod start |
Step 5: Configure mongod
It is configured as follows to automatically start the mongod service when the system restarts.
1 | [mongodb@mongodbserv ~]$ sudo chkconfig mongod on |
Where is MongoDB Data Files and Log Files?
By default, MongoDB stores data files in the /var/lib/mongo path and log files in /var/log/mongodb. To change these values, it is necessary to start the mongod process with the appropriate parameters or to use a configuration file.