详见https://docs.mongodb.com/manual/tutorial/install-mongodb-on-red-hat/#run-mongodb-community-edition
Production Notes
Before deploying MongoDB in a production environment, consider the Production Notes document which offers performance considerations and configuration recommendations for production MongoDB deployments.
Install MongoDB Community Edition
Follow these steps to install MongoDB Community Edition using the yum package manager.
1. Configure the package management system (yum).
Create a /etc/yum.repos.d/mongodb-org-4.2.repo file so that you can install MongoDB directly using yum:**
[mongodb-org-4.2]name=MongoDB Repositorybaseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
You can also download the .rpm files directly from the MongoDB repository. Downloads are organized by Red Hat / CentOS version (e.g. 7), then MongoDB release version (e.g. 4.2), then architecture (e.g. x86_64). Odd-numbered MongoDB release versions, such as 4.3, are development versions and are unsuitable for production deployment.
2. Install the MongoDB packages.
To install the latest stable version of MongoDB, issue the following command:
sudo yum install -y mongodb-org
Alternatively, to install a specific release of MongoDB, specify each component package individually and append the version number to the package name, as in the following example:
sudo yum install -y mongodb-org-4.2.8 mongodb-org-server-4.2.8 mongodb-org-shell-4.2.8 mongodb-org-mongos-4.2.8 mongodb-org-tools-4.2.8
Run MongoDB Community Edition
Non-Default MongoDB Directory Path(s)
semanage fcontext -a -t
- where specify one of the following types as appropriate:
mongod_var_lib_tfor data directorymongod_log_tfor log file directorymongod_var_run_tfor pid file directory
- NOTE
Be sure to include the.*at the end of the directory. - Update the SELinux user policy for the new directory:copycopied
chcon -Rv -u system_u -t
- where specify one of the following types as appropriate:
mongod_var_lib_tfor data directorymongod_log_tfor log directorymongod_var_run_tfor pid file directory
- Apply the updated SELinux policies to the directory:
copy
copied
restorecon -R -v
For examples:
TIP
- Depending on your user permission, you may need to use
sudoto perform these operations. - Be sure to include the
.*at the end of the directory for thesemanage fcontextoperations. - If using a non-default MongoDB data path of
/mongodb/data:
copy
copied
semanage fcontext -a -t mongod_var_lib_t ‘/mongodb/data.*’
chcon -Rv -u system_u -t mongod_var_lib_t ‘/mongodb/data’
restorecon -R -v ‘/mongodb/data’
- If using a non-default MongoDB log directory of
/mongodb/log(e.g. if the log file path is/mongodb/log/mongod.log):
copy
copied
semanage fcontext -a -t mongod_log_t ‘/mongodb/log.*’
chcon -Rv -u system_u -t mongod_log_t ‘/mongodb/log’
restorecon -R -v ‘/mongodb/log’
Non-Default MongoDB Ports
TIP
Depending on your user permission, you may need to use sudo to perform the operation.
copy
copied
semanage port -a -t mongod_port_t -p tcp
