本文共 5292 字,大约阅读时间需要 17 分钟。
Use this tutorial to install on Red Hat Enterprise Linux or CentOSLinux versions 6 and 7 from.rpm
packages.
Use the provided distribution packages as described in this page if possible.These packages will automatically install all of MongoDB’s dependencies, and arethe recommended installation method.
1
Create an /etc/yum.repos.d/mongodb-enterprise.repo
file so that you can install MongoDB enterprise directly, using yum
.
For the latest stable release of MongoDB Enterprise
Use the following repository file:
[mongodb-enterprise]name=MongoDB Enterprise Repositorybaseurl=https://repo.mongodb.com/yum/redhat/$releasever/mongodb-enterprise/3.4/$basearch/gpgcheck=1enabled=1gpgkey=https://www.mongodb.org/static/pgp/server-3.4.asc
NOTE:
You can find .repo
files for each release can also be found .Remember that odd-numbered minor release versions (e.g. 2.5) are development versions and are unsuitablefor production deployment.
To install the latest stable version of MongoDB Enterprise, issue the following command:
sudo yum install -y mongodb-enterprise
3
While you should use the .rpm
packages as previously described, you may also manually install MongoDB using the tarballs. See for details.
Configure 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).
To configure SELinux, administrators have three options:
If SELinux is in enforcing
mode,enable access to the relevant ports that the MongoDB deployment will use(e.g.27017
). See for more information on MongoDB’s default ports. For default settings,this can be accomplished by running
semanage port -a -t mongod_port_t -p tcp 27017
Disable SELinux by setting the SELINUX
setting todisabled
in/etc/selinux/config
.
SELINUX=disabled
You must reboot the system for the changes to take effect.
Set SELinux to permissive
mode in/etc/selinux/config
bysetting theSELINUX
setting topermissive
.
SELINUX=permissive
You must reboot the system for the changes to take effect.
You can instead use setenforce
to change topermissive
mode.setenforce
does not require a reboot but isnot persistent.
Alternatively, you can choose not to install the SELinux packages when you areinstalling your Linux operating system, or choose to remove the relevant packages. This option is the most invasive and is not recommended.
Data Directories and Permissions
Warning
On RHEL 7.0, if you change the data path, the default SELinux policies will prevent 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 themongod
user account. You can specify alternate log and data file directories in/etc/mongod.conf
. See and 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.
1
Start MongoDB.
You can start the process by issuing the following command:
sudo service mongod start
2
Verify that MongoDB has started successfully
You can verify that the process has startedsuccess fully by checking the contents of the log file at/var/log/mongodb/mongod.log
for a line reading
[initandlisten] waiting for connections on port
where <port>
is the port configured in/etc/mongod.conf
,27017
by default.
You can optionally ensure that MongoDB will start following a systemreboot by issuing the following command:
sudo chkconfig mongod on
3
Stop MongoDB.
As needed, you can stop the process by issuing the following command:
sudo service mongod stop
4
Restart MongoDB.
You can restart the process by issuing the following command:
sudo service mongod restart
You can follow the state of the process for errors or important messages by watching the output in the/var/log/mongodb/mongod.log
file.
5
Begin using MongoDB.
To help you start using MongoDB, MongoDB provides in various driver editions. See for the available editions.
Before deploying MongoDB in a production environment, consider the document.
Later, to stop MongoDB, press Control+C
in the terminal where the instance is running.
To completely remove MongoDB from a system, you must remove the MongoDBapplications themselves, the configuration files, and any directories containing data and logs. The following section guides you through the necessary steps.
Warning
This process will completely remove MongoDB, its configuration, andall databases. This process is not reversible, so ensure that all of your configuration and data is backed up before proceeding.
1
Stop the process by issuing the following command:
sudo service mongod stop
2
Remove any MongoDB packages that you had previously installed.
sudo yum erase $(rpm -qa | grep mongodb-enterprise)3
Remove MongoDB databases and log files.
sudo rm -r /var/log/mongodb sudo rm -r /var/lib/mongo
转载地址:http://ybfob.baihongyu.com/