Detailed procedures for installing mongodb 3.4 under Ubuntu
- 2020-06-19 11:57:21
- OfStack
An overview of the
This tutorial covers the long - term support of Ubuntu Linux systems
.deb
Package steps to install Mongodb Community edition. Although MongoDB packages are included in the Ubuntu software repository, they are not the latest version.
Platform support:
MongoDB provides a package that supports only 64-bit long-term support versions of the Ubuntu distribution. For example, Ubuntu 12.04 LTS (precise), 14.04 LTS (trusty), 16.04 LTS (xenial) and so on. These packages may work on other distributions, but are not supported.
Notes:
3.4 Incompatible with Ubuntu 16.04 on IBM Power Systems
package
MongoDB offers an officially supported installation package in its own warehouse. The following packages are included in the repository
包 | 功能 |
---|---|
mongodb-org | 这个包会自动安装以下的 4 个组件包 |
mongodb-org-server | 包含了 mongod 守护进程及其相关的配置和初始化脚本 |
mongodb-org-mongos | 包含了 mongos 守护进程 |
mongodb-org-shell | 包含了 mongo 客户端程序 |
mongodb-org-tools | 包含了1下 MongoDB 工具: mongoimport bsondump, mongodump, mongoexport, mongofiles,mongooplog, mongoperf, mongorestore, mongostat, mongotop. |
The initialization script provided by package mongodb-ES43en-ES44en starts mongod with the following configuration file:
/etc/mongod.conf
These installation packages are available with Ubuntu
mongodb
,
mongodb-server
,
mongodb-clients
Packet collision.
The configuration file /etc/ mongod. conf default configuration bind_ip is 127.0.0.1. Modify this setting to suit your needs before initializing 1 replication cluster (replica set).
Install the MongoDB Community edition
MongoDB provides a package that supports only the 64-bit, long-term support version of the Ubuntu distribution. For example, Ubuntu 12.04 LTS (precise), 14.04 LTS (trusty), 16.04 LTS (xenial) and so on. These packages may work on other distributions, but are not supported.
Import the public key used by the package management system
Ubuntu's package management tools (dpkg and APT) require package publishers to sign GPG keys to ensure package integrity and authenticity. Import the MongoDB public GPG key with the following command:
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6
Create list file for MongoDB
Create according to the version of Ubuntu using the appropriate command
list file: /etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 12.04
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 14.04
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Ubuntu 16.04
echo "deb [ arch=amd64,arm64 ] http://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
Redownload the local package database index
sudo apt-get update
Install MongoDB
Install the latest reliable version with the following command
sudo apt-get install -y mongodb-org
Run the MongoDB community edition
By default, the data file for the MongoDB instance is located at
/var/lib/mongodb
, the log file is located at
/var/log/mongodb
And run through user mongodb. You can do this in the configuration file
/etc/mongod.conf
Specify the different log file and data file directories, configured as systemLog.path and storage.dbPath.
If you change the user running the MongoDB process, you must change it
/var/lib/mongodb
and
/etc/mongod.conf
0
To give users access to these directories.
Start the MongoDB
Execute the following command to start the mongod process
sudo service mongod start
# or
sudo systemctl start mongod
Verify that MongoDB started successfully
By checking the log file/var/log/mongodb/mongod log to verify whether mongod process start is successful, log file should contain the following information:
[initandlisten] waiting for connections on port <port>
<port>
With configuration 1 of configuration file /etc/ mongod.conf, the default is 27017
Stop MongoDB
If necessary, you can stop the mongod process with the following command
sudo service mongod stop
# or
sudo systemctl stop mongod
Restart MongoDB
sudo service mongod status
# or
sudo systemctl status mongod
View MongoDB status
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
0
Uninstall MongoDB Community edition
To completely remove MongoDB from the system, you need to remove the MongoDB application, configuration files, log and data file directories. Please refer to the following operation steps:
Stop MongoDB
Stop the mongod process with the following command
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
1
Delete package
Remove all MongoDB packages
echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu precise/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list
2
Delete data and log directories
Delete the MongoDB data and log directories
sudo rm -r /var/log/mongodb
sudo rm -r /var/lib/mongodb
conclusion
The above is the whole content of this article, I hope the content of this article can bring 1 definite help to your study or work, if you have any questions, you can leave a message to communicate.