Ubuntu 16.04 - MongoDB 4.4 Installation
zero, environment
Host version: Windows11
Virtual machine version: ubuntukylin-16.04-desktop-amd64
VMware version: VMware® Workstation 17 Pro
NIC: bridge mode
Note: The hardware version used is compatible with VMware 12.X.
1. Introduction to MongoDB
MongoDB is a popular open source document data storage and NoSQL
database management system. MongoDB uses a document-oriented data model to store data in BSON
(binary JSON) format, each document represents an entity or object, and documents can contain nested fields and values. MongoDB is suitable for handling various data types such as unstructured, hierarchical, and semi-structured data.
MongoDB uses JSON
a style query language and an extensible data model, which makes it easy to expand the database without modifying the schema. MongoDB's indexing engine is efficient and can be used to support text search and geospatial queries. MongoDB also provides automatic failure recovery and dynamic load balancing, which can automatically manage failure and data recovery between multiple servers without service interruption.
In addition to the above core functions, MongoDB also provides easy-to-use functions of replica sets and shard clusters, as well as a built-in JavaScript
engine for convenient data processing and query. MongoDB can be used in a variety of applications such as Web
applications, content management and e-commerce platforms, games and advertising templates, etc.
MongoDB Features
-
Document-oriented database management system : MongoDB adopts the document data model, and data is stored in the form of documents similar to JSON. Each document can contain multiple fields and values, and the structure of each document can be the same or different.
-
Highly scalable : MongoDB can be scaled horizontally, allowing data and load to be distributed among multiple servers, thereby improving the performance and scalability of the system. MongoDB provides a mechanism that can automatically handle failover and data recovery to ensure high availability of the cluster.
-
Ability to handle unstructured data : MongoDB can handle a large amount of unstructured data, such as log data, geospatial data, image data, etc.
-
Flexible query language : MongoDB uses JavaScript to query and manipulate data, so it is easy to debug, easy to learn and use. MongoDB can support various query types, including precise query, range query, compound query and text query, and also supports aggregation operations.
-
Asynchronous Write Operations : MongoDB can write large amounts of data quickly because it uses asynchronous write operations that do not block client applications while data is being written. This means that under high load, MongoDB can handle more write requests.
-
Data backup and recovery : MongoDB can generate snapshots or store data persistently, and allows rollback when data is restored.
-
Built-in functions : MongoDB has built-in various functions, such as text search, geospatial search, and graph processing, etc., which can be used directly.
Differences between MongoDB and traditional relational databases
The following is a table of differences between MongoDB and traditional relational databases:
features | MongoDB | traditional relational database |
---|---|---|
data model | Document Data Model | relational data model |
query language | JavaScript API | SQL |
Scalability | High scalability, support horizontal expansion | Difficult to scale horizontally, often run on a single server |
handle large data sets | Easier to handle large data sets, able to handle unstructured data | Relatively difficult to handle large datasets |
index | MongoDB's index has rich functions | Traditional databases have relatively few indexing capabilities |
transaction processing | Transactions are implemented in some versions | Traditional relational databases are popular and support transaction processing |
availability | Automatic failover, supporting automatic data backup and recovery | Traditional databases require manual configuration of any of these backup and failover operations |
performance | Higher performance can be achieved with asynchronous write operations | Potentially poor performance on large datasets |
cost | Free, and free to modify the source code | A certain license fee is required, and free modification of the source code is not allowed |
In short, MongoDB has higher flexibility, scalability and better performance than traditional relational databases, but it may not be suitable for some application scenarios. Therefore, when selecting a database system, it should be selected according to the specific application scenario.
2. Install MongoDB 4.4
MongoDB has different compatibility requirements on different Linux platforms. Therefore, I found the following table in the official documentation. Readers can search and compare the table below to choose to download and install the MongoDB version that suits their machines.
Platform | Architecture | Editing | 6.0 | 5.0 | 4.4 | 4.2 | 4.0 |
---|---|---|---|---|---|---|---|
Amazon Linux 2022 | x86_64 | Enterprise | 6.2.0+ | ||||
Amazon Linux 2022 | x86_64 | Community | 6.2.0+ | ||||
Amazon Linux V2 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | ✓ |
Amazon Linux V2 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | ✓ |
Amazon Linux V1 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | |
Amazon Linux V1 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | |
Debian 11 | x86_64 | Enterprise | ✓ | 5.0.8+ | |||
Debian 11 | x86_64 | Community | ✓ | 5.0.8+ | |||
Debian 10 | x86_64 | Enterprise | ✓ | ✓ | ✓ | 4.2.1+ | |
Debian 10 | x86_64 | Community | ✓ | ✓ | ✓ | 4.2.1+ | |
Debian 9 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | |
Debian 9 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | |
RHEL/CentOS/Oracle Linux/Rocky/Alma 9.0+ | x86_64 | Enterprise | 6.0.4+ | ||||
RHEL/CentOS/Oracle Linux/Rocky/Alma 9.0+ | x86_64 | Community | 6.0.4+ | ||||
RHEL/CentOS/Oracle Linux/Rocky/Alma 8.0+ | x86_64 | Enterprise | ✓ | ✓ | ✓ | 4.2.1+ | 4.0.14+ |
RHEL/CentOS/Oracle Linux/Rocky/Alma 8.0+ | x86_64 | Community | ✓ | ✓ | ✓ | 4.2.1+ | 4.0.14+ |
RHEL/CentOS/Oracle Linux 7.0+ | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | ✓ |
RHEL/CentOS/Oracle Linux 7.0+ | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | ✓ |
RHEL/CentOS/Oracle Linux 6.2+ | x86_64 | Enterprise | ✓ | ✓ | ✓ | ||
RHEL/CentOS/Oracle Linux 6.2+ | x86_64 | Community | ✓ | ✓ | ✓ | ||
SLES 15 | x86_64 | Enterprise | ✓ | ✓ | ✓ | 4.2.1+ | |
SLES 15 | x86_64 | Community | ✓ | ✓ | ✓ | 4.2.1+ | |
SLES 12 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | ✓ |
SLES 12 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | ✓ |
Ubuntu 22.04 | x86_64 | Enterprise | 6.0.4+ | ||||
Ubuntu 22.04 | x86_64 | Community | 6.0.4+ | ||||
Ubuntu 20.04 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ||
Ubuntu 20.04 | x86_64 | Community | ✓ | ✓ | ✓ | ||
Ubuntu 18.04 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | 4.0.1+ |
Ubuntu 18.04 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | 4.0.1+ |
Ubuntu 16.04 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ||
Ubuntu 16.04 | x86_64 | Community | ✓ | ✓ | ✓ | ||
Windows Server 2019 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | |
Windows Server 2019 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | |
Windows 7/8/8.1 | x86_64 | Enterprise | ✓ | ✓ | |||
Windows 7/8/8.1 | x86_64 | Community | ✓ | ✓ | |||
Windows Server 2008R2/2012/2012R2 | x86_64 | Enterprise | ✓ | ✓ | |||
Windows Server 2008R2/2012/2012R2 | x86_64 | Community | ✓ | ✓ | |||
Windows 10 / Server 2016 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | ✓ |
Windows 10 / Server 2016 | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | ✓ |
macOS 11 | x86_64 | Enterprise | ✓ | ||||
macOS 11 | x86_64 | Community | ✓ | ||||
macOS 10.14+ | x86_64 | Enterprise | ✓ | ✓ | ✓ | ✓ | |
macOS 10.14+ | x86_64 | Community | ✓ | ✓ | ✓ | ✓ | |
macOS 10.13 | x86_64 | Enterprise | ✓ | ✓ | ✓ | ||
macOS 10.13 | x86_64 | Community | ✓ | ✓ | ✓ | ||
macOS 10.12 | x86_64 | Enterprise | ✓ | ✓ | |||
macOS 10.12 | x86_64 | Community | ✓ | ✓ | |||
macOS 11 | arm64 | Enterprise | ✓ | ||||
macOS 11 | arm64 | Community | ✓ | ||||
Amazon Linux 2022 | arm64 | Enterprise | 6.2.0+ | ||||
Amazon Linux 2022 | arm64 | Community | 6.2.0+ | ||||
Amazon Linux 2 | arm64 | Enterprise | ✓ | ✓ | 4.4.4+ | 4.2.13+ | |
Amazon Linux 2 | arm64 | Community | ✓ | ✓ | 4.4.4+ | 4.2.13+ | |
RHEL/CentOS/Rocky/Alma 8 | arm64 | Enterprise | ✓ | ✓ | 4.4.4+ | ||
RHEL/CentOS/Rocky/Alma 8 | arm64 | Community | ✓ | ✓ | 4.4.4+ | ||
Ubuntu 22.04 | arm64 | Enterprise | 6.0.4+ | ||||
Ubuntu 22.04 | arm64 | Community | 6.0.4+ | ||||
Ubuntu 20.04 | arm64 | Enterprise | ✓ | ✓ | ✓ | ||
Ubuntu 20.04 | arm64 | Community | ✓ | ✓ | ✓ | ||
Ubuntu 18.04 | arm64 | Enterprise | ✓ | ✓ | ✓ | ✓ | |
Ubuntu 18.04 | arm64 | Community | ✓ | ✓ | ✓ | ✓ | |
Ubuntu 16.04 | arm64 | Enterprise | ✓ | ✓ | ✓ | ||
Ubuntu 16.04 | arm64 | Community | ✓ | ||||
RHEL/CentOS/Rocky/Alma 8 | ppc64le | Enterprise | ✓ | ✓ | ✓ | 4.2.7+ | |
RHEL/CentOS/Rocky/Alma 8 | ppc64le | Community | |||||
RHEL/CentOS 7 | ppc64le | Enterprise | ✓ | ✓ | 4.0.0 - 4.0.27 | ||
RHEL/CentOS 7 | ppc64le | Community | |||||
Ubuntu 18.04 | ppc64le | Enterprise | 4.4.0 - 4.4.10 | 4.2.1 - 4.2.17 | |||
Ubuntu 18.04 | ppc64le | Community | |||||
RHEL/CentOS/Rocky/Alma 8 | s390x | Enterprise | ✓ | 5.0.9+ | |||
RHEL/CentOS/Rocky/Alma 8 | s390x | Community | |||||
RHEL/CentOS 7 | s390x | Enterprise | ✓ | ✓ | ✓ | 4.2.0 - 4.2.17 | 4.0.6 - 4.0.27 |
RHEL/CentOS 7 | s390x | Community | ✓ | ✓ | 4.2.0 - 4.2.9 | 4.0.6 - 4.0.13 | |
RHEL/CentOS 6 | s390x | Enterprise | 4.2.4 - 4.2.14 | 4.0.0 - 4.0.24 | |||
RHEL/CentOS 6 | s390x | Community | 4.0.0 - 4.0.13 | ||||
SLES 12 | s390x | Enterprise | 4.4.0 - 4.4.6 | 4.2.0 - 4.2.14 | 4.0.6 - 4.0.24 | ||
SLES 12 | s390x | Community | 4.4.0 - 4.4.6 | 4.2.0 - 4.2.9 | 4.0.6 - 4.0.13 | ||
Ubuntu 18.04 | s390x | Enterprise | 4.4.0 - 4.4.6 | 4.2.1 - 4.2.14 | 4.0.6 - 4.0.25 | ||
Ubuntu 18.04 | s390x | Community | 4.4.0 - 4.4.6 | 4.2.1 - 4.2.9 | 4.0.6 - 4.0.13 |
最终我选用了 MongoDB 4.4 的版本,因为 5.0 以上的版本不支持 Ubuntu 16.04,所以矮子里面挑高个,我就选了 4.4 ,不建议选择 4.0,因为 v4.0 于2022年4月30日达到生命周期结束,不再被 MongoDB 正式支持。
离线安装 MongoDB
因为在线安装我个人认为比较麻烦,所以我在这里就选择离线安装的方式,在线安装可以直接去看后面的内容。
找到适合的版本后,我们点击进入下列链接寻找合适的版本组件进行下载
我的版本就放在下面这里,是 X64
架构的笔记本,Ubuntu 16.04
版本
- Ubuntu 16.04 x64
- Archive: mongodb-linux-x86_64-ubuntu1604-4.4.21.tgz
- Server Package: mongodb-org-server_4.4.21_amd64.deb
- Mongos Package: mongodb-org-mongos_4.4.21_amd64.deb
- Mongo Shell Package: mongodb-org-shell_4.4.21_amd64.deb
系统架构可以根据下面方法查看,因为都用的是虚拟机,所以我们可以在 Windows 下,按 Win + i
键,打开控制面板,如下图,中系统,选中 系统--> 系统信息
就可以看到设备规格,其中系统类型就会显示处理器的架构了。
(1)下载
下载过程一般都是出奇的简单以及枯燥,但是为了照顾到大家,这里我还是将三种方法都列一下。
1、Xftp 传输
首先我们需要在 Windows
主系统中,下载 MongoDB
的压缩包
下载完成后打开 Xftp
,找到下载文件的地方并且打开对应虚拟机的位置(你安装包经常放的位置,避免到时候自己找不到东西),双击将需要传输的包传输过去。
这样便传输完毕了。
2、浏览器下载
打开自带的浏览器 Firefox
,找到 MongoDB
的官网,选择 Products --> Community Server
,如果是企业版的可以选择前面的 Enterprise Server
。
根据上面的表格选择对应需要下载的版本、对应的平台、下载格式,然后点击 Download
按钮。
确认自己选择下载的版本,没错就可以点击确定。
可以在下载管理器中看到下载的进度,等待下载完成即可。
下载完成后可以直接提取到想要的位置
3、wget 下载
先找到下载的链接。
输入 wget + 链接地址 + -P + 存放的目录路径
即可
wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu1604-4.4.22-rc2.tgz -P ~/下载/
下载完成后可以在 ~/下载/
目录下找到下载的压缩包。
(2)解压
下载完成后就可以在 ~/下载
目录下找到 mongodb-linux-x86_64-ubuntu1604-4.4.22-rc1.tgz
压缩包,但是只有下载完成,整个压缩包才是完整的,否则就是没有用的。然后我们输入下面命令将压缩包
sudo tar -zxf 下载/mongodb-linux-x86_64-ubuntu1604-4.4.22-rc1.tgz -C /usr/local/
进入解压后所在的目录,然后对文件夹进行重命名,以便后面使用。
cd /usr/local/
sudo mv mongodb-linux-x86_64-ubuntu1604-4.4.22-rc1/ mongodb
ll
更改属主权限,方便后续的执行。
sudo chown -R hadoop mongodb/ # 更改 mongodb 文件夹的属主。hadoop 是用户名
(3)配置 MongoDB
创建日志文件
接下来我们将创建一个 data/db
作为数据保存目录,data/db/journal/mongodb.log
作为日志文件
cd /usr/local/mongodb/ # 进入 MongoDB 的安装目录
mkdir -p data/db/journal # 创建 data/db 作为数据目录
cd data/db/journal
touch mongodb.log #创建 mongodb.log 作为日志文件
配置文件 mongodb.conf
输入下列命令创建配置文件
cd /usr/local/mongodb/data/ # 进入数据存储目录
vim mongodb.conf # 目录下没有 mongodb.conf 文件时用本条命令会自动创建 mongodb.conf 文件
创建后会看见左下角显示这是一个新文件
键入下面文件内容,然后保存退出。
#日志文件位置
logpath=/usr/local/mongodb/data/db/journal/mongodb.log
# 以追加方式写入日志
logappend=true
# 是否以守护进程方式运行
fork=true
# 默认27017
#port = 27017
# 数据库文件位置
dbpath=/usr/local/mongodb/data/db
# 启用定期记录CPU利用率和 I/O 等待
#cpu = true
# 是否以安全认证方式运行,默认是不认证的非安全方式
#noauth = true
#auth = true
# 详细记录输出
#verbose = true
# Inspect all client data for validity on receipt (useful for
# developing drivers)用于开发驱动程序时验证客户端请求
#objcheck = true
# Enable db quota management
# 启用数据库配额管理
#quota = true
# 设置oplog记录等级
# Set oplogging level where n is
# 0=off (default)
# 1=W
# 2=R
# 3=both
# 7=W+some reads
#diaglog=0
# Diagnostic/debugging option 动态调试项
#nocursors = true
# Ignore query hints 忽略查询提示
#nohints = true
# 禁用http界面,默认为localhost:28017
#nohttpinterface = true
# 关闭服务器端脚本,这将极大的限制功能
# Turns off server-side scripting. This will result in greatly limited
# functionality
#noscripting = true
# 关闭扫描表,任何查询将会是扫描失败
# Turns off table scans. Any query that would do a table scan fails.
#notablescan = true
# 关闭数据文件预分配
# Disable data file preallocation.
#noprealloc = true
# 为新数据库指定.ns文件的大小,单位:MB
# Specify .ns file size for new databases.
# nssize =
# Replication Options 复制选项
# in replicated mongo databases, specify the replica set name here
#replSet=setname
# maximum size in megabytes for replication operation log
#oplogSize=1024
# path to a key file storing authentication info for connections
# between replica set members
#指定存储身份验证信息的密钥文件的路径
#keyFile=/path/to/keyfile
效果如下:
输入 cat
命令可以查看文件内容
cat mongodb.conf
在线安装 MongoDB
导入程序包管理系统使用的公钥
在线安装会比离线安装更为复杂,需要导入程序包管理系统使用的公钥。首先输入下面命令从终端安装 gnupg
工具(如果它还不可用),curl
工具
sudo apt-get install gnupg curl -y
下载完之后,输入以下命令从中导入 MongoDB
公共 GPG
密钥
curl -fsSL https://pgp.mongodb.com/server-4.4.asc | \
sudo gpg -o /usr/share/keyrings/mongodb-server-4.4.gpg \
--dearmor
为 MongoDB 创建一个列表文件
为您的 Ubuntu
版本创建列表文件 /etc/apt/sources.list.d/mongodb-org-6.0.list
,在创建之前,运行 lsb_release -dc
命令,查看当前 Linux
衍生版的版本
lsb_release -dc
下面提供 Ubuntu
版本的命令:
16.04
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/ubuntu xenial/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
18.04
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/ubuntu bionic/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
20.04
echo "deb [ arch=amd64,arm64 signed-by=/usr/share/keyrings/mongodb-server-4.4.gpg ] https://repo.mongodb.org/apt/ubuntu focal/mongodb-org/4.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-4.4.list
效果如下:
重新加载本地包数据库
输入以下命令以重新加载本地包数据库
sudo apt-get update -y
出现下面这种就算是加载成功了。
也有可能会遇到一些错误,比如说:
错误:1 http://archive.ubuntukylin.com:10006/ubuntukylin trusty InRelease
无法连接上 archive.ubuntukylin.com:10006 (124.126.103.228)。 - connect (111: 拒绝连接)
遇上这个问题,我们需要进入 /etc/apt/sources.list.d
目录下,查看后缀为 .list
的文件,如下图有两个,我们一个个看。
cd /etc/apt/sources.list.d
使用 cat
命令,分别查看两个文件内容
cat mongodb-org-4.4.list
cat ubuntukylin.list
找到对应报错的地方,使用下面命令,将文件内容进行注释。
sudo vim ubuntukylin.list
安装MongoDB包
可以选择安装 MongoDB 的最新稳定版本或 MongoDB 的特定版本,这里我们选择安装 MongoDB 的最新稳定版,输入下面命令
sudo apt-get install -y mongodb-org
出现下图的情况就可以安心等待下载完成了。
安装完成
虽然可以指定任何可用的 MongoDB
版本,但 apt-get
会在新版本可用时升级包。为了防止意外升级,可以使用下面命令将软件包固定在当前安装的版本
echo "mongodb-org hold" | sudo dpkg --set-selections
echo "mongodb-org-server hold" | sudo dpkg --set-selections
echo "mongodb-org-shell hold" | sudo dpkg --set-selections
echo "mongodb-org-mongos hold" | sudo dpkg --set-selections
echo "mongodb-org-tools hold" | sudo dpkg --set-selections
三、使用 MongoDB
启动 MongoDB 服务
init 方式启动 MongoDB(在线安装测试)
这里是在线安装下测试的,但是除了一些文件的存放位置,其他命令与离线安装还是一样的。
要运行和管理 mongod
进程,您将使用操作系统的内置 init
系统。最近的 Linux
版本倾向于使用 systemd
(使用 systemctl
命令),而旧版本的 Linux
倾向于使用 System V init
(使用 service
命令)。
如果不确定您的平台使用哪个 init
系统,可以运行以下命令:
ps --no-headers -o comm 1
输入下面命令开启 MongoDB
服务
sudo systemctl start mongod
输入 pgrep mongo -l
可以查看是否启动成功
pgrep mongo -l
如果在启动时收到类似于以下内容的错误 mongod
Failed to start mongod.service: Unit mongod.service not found.
首先运行以下命令:
sudo systemctl daemon-reload
然后再次运行上面的启动命令。
输入下面命令可以确保 MongoDB
在系统重启后自动启动
sudo systemctl enable mongod
重新启动 MongoDB
sudo systemctl restart mongod
您可以跟踪流程的状态以获取错误或重要消息 通过观察文件中的输出。/var/log/mongodb/mongod.log
进入 MongoDB Shell
模式,输入下面命令启动 MongoDB Shell
没有任何命令行选项连接到 mongod
默认在本地主机上的27017端口:
mongo
脚本方式启动 MongoDB 服务(离线安装测试)
因为在线安装没有配置文件,所以这部分就只是离线安装的环境下测试。
先进入 MongoDB
的安装目录,再用脚本文件进行启动。
cd /usr/local/mongodb
./bin/mongod -f data/mongodb.conf
成功启动如下所示:
输入 pgrep mongo -l
可以查看是否启动成功
pgrep mongo -l
跟上面的进程号相对应,7891
。
启动失败示意图:
进入 MongoDB Shell 模式
cd /usr/local/mongodb
./bin/mongo
输入exit
或Ctrl+C
退出 shell
模式
关闭 MongoDB 服务
根据需要,输入下面命令可以停止 mongod
服务
sudo systemctl stop mongod
或者进入 MongoDB Shell
模式, 输入下面命令对 MongoDB
服务进行关闭。
use admin
db.shutdownServer()
使用 pgrep
命令查看 MongoDB
的进程号来判断服务是否仍在运行
pgrep mongo -l
可以发现 MongoDB
没有进程号,进而判断服务已经关闭。
四、附记(离线安装下)
如果想在任何目录都可以启动 MongoDB
的服务,可以将 MongoDB
的执行路径添加到环境变量的 PATH
中。
输入下面命令使用 vim
编辑器打开环境变量文件
sudo vim /etc/bash.bashrc
输入下列配置项,然后保存退出
#MongoDB
export MONGODB_HOME=/usr/local/mongodb
export PATH=$PATH:/usr/local/mongodb/bin
重新加载环境变量
source ~/.bashrc
再次输入 mongo
,按两下 tab
,就可以看见有 mongod
命令存在了,之后就可以使用 mongod
就可以打开 MongoDB
服务了,并且可以直接使用 mongo
命令进入 MongoDB Shell
模式。
使用 mongod -f + [脚本文件路径]
来启动 MongoDB
服务。
mongod -f /usr/local/mongodb/data/mongodb.conf # 开启 MongoDB 服务
启动 MongoDB
服务后,输入 mongo
命令就可以打开 MongoDB Shell
模式。
mongo
伍、写在最后
这篇文章到后面写的有点乱,因为就是在线安装跟离线安装有很多的不一样,启动的方式,日志存放的位置也有很多的不同。因为我是先做的离线安装,所以数据存放的位置和日志存放的位置和在线安装会有很多的不一样,所以这篇有很多比较乱的地方。希望各位看完也能收获一些部署的心得。