How to install MongoDB - Enterprise on CentOS
1. Configure repository.
Create an
/etc/yum.repos.d/mongodb-enterprise.repo file so that you can install MongoDB enterprise directly, using yum.[mongodb-enterprise] name=MongoDB Enterprise Repository baseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/3.4/$basearch/ gpgcheck=1 enabled=1 gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
2. Install the MongoDB Enterprise packages and associated tools.
To install the latest stable version of MongoDB Enterprise, issue the following command:
sudo yum install -y mongodb-enterprise
3. Config SELinux
IMPORTANT
If you are using SELinux, you must configure SELinux to allow MongoDB to start on Red Hat Linux-based systems (Red Hat Enterprise Linux or CentOS Linux).
a
To configure SELinux, administrators have three options:
- If SELinux is in
enforcingmode, enable access to the relevant ports that the MongoDB deployment will use (e.g.27017). See Default MongoDB Port for more information on MongoDB’s default ports. For default settings, this can be accomplished by runningsemanage port -a -t mongod_port_t -p tcp 27017 - Disable SELinux by setting the
SELINUXsetting todisabledin/etc/selinux/config.SELINUX=disabled
You must reboot the system for the changes to take effect. - Set SELinux to
permissivemode in/etc/selinux/configby setting theSELINUXsetting topermissive.SELINUX=permissive
You must reboot the system for the changes to take effect.You can instead usesetenforceto change topermissivemode.setenforcedoes not require a reboot but is not persistent.
Alternatively, you can choose not to install the SELinux packages when you are installing your Linux operating system, or choose to remove the relevant packages. This option is the most invasive and is not recommended.
4. Config Database Options
4.1 Data Directories and Permissions
WARNING
On RHEL 7.0, if you change the data path, the default SELinux policies will prevent
mongod from having write access on the new data path if you do not change the security context.
The MongoDB instance stores its data files in
/var/lib/mongo and its log files in /var/log/mongodb by default, and runs using the mongod user account. You can specify alternate log and data file directories in /etc/mongod.conf. See systemLog.path and storage.dbPath for additional information.
If you change the user that runs the MongoDB process, you must modify the access control rights to the
/var/lib/mongo and /var/log/mongodb directories to give this user access to these directories.ulimit
Most Unix-like operating systems limit the system resources that a session may use. These limits may negatively impact MongoDB operation. See UNIX ulimit Settings for more information.
4.2 Database Directory
Note: if you already start the MongoDB before setting this, you need to change the storagePath to a new directory and do this step again.
If you want to store database into individual directory, you should put this key and value in to the config file in /etc/mongod.conf :
directoryPerDB : true
Then you start the MongoDB for first time.
5. Run the database
sudo systemctl restart mongod
6. Verifying Startup
Because a database-driven application cannot function without a database, we’ll make sure that the MongoDB daemon,
mongod, will start with the system.
Use the
systemctl utility to check its startup status:
- systemctl is-enabled mongod; echo $?
An output of zero confirms an enabled daemon, which we want. A one, however, confirms a disabled daemon that will not start.
Output
. . .
enabled
0
In the event of a disabled daemon, use the
systemctl utility to enable it:
- sudo systemctl enable mongod
We now have a running instance of MongoDB that will automatically start following a system reboot.
*****************
Finish!
Enjoy your DB !
No comments:
Post a Comment