mongodb卸载_如何在Windows上安装MongoDB,启动,卸载

mongodb卸载

Today we will learn how to install MongoDB on Windows. Most of us use Windows for our personal use. That’s why I am writing this tutorial to help you install MongoDB on Windows. We will also learn how to start and uninstall MongoDB on Windows.

今天,我们将学习如何在Windows上安装MongoDB。 我们大多数人都将Windows用于个人用途。 这就是为什么我编写本教程来帮助您在Windows上安装MongoDB的原因。 我们还将学习如何在Windows上启动和卸载MongoDB。

Windows版MongoDB (MongoDB for Windows)

Starting from MongoDB version 2.2, MongoDB doesn’t support Windows XP. So if you are on Windows XP, either upgrade it or use the lower versions of MongoDB. This tutorial is intended to help you in installing MongoDB on Windows latest versions i.e Windows 7 and Windows 8, 8.1 etc.

从MongoDB 2.2版开始,MongoDB不支持Windows XP。 因此,如果您使用的是Windows XP,请升级它或使用较低版本的MongoDB。 本教程旨在帮助您在Windows最新版本(例如Windows 7和Windows 8、8.1等)上安装MongoDB。

在Windows上安装MongoDB (Install MongoDB on Windows)

Follow below steps to perform the installation of MongoDB into your windows system.

请按照以下步骤将MongoDB安装到Windows系统中。

  1. Consider specific MongoDB build type which you need actually

    Three build types of MongoDB for Windows are available.

    1. MongoDB for Windows Server 2008 R2 series: This build type runs only on 2008R2, Windows 7 64-bit, Windows 8, and latest versions of Windows.
    2. MongoDB for Windows 64-bit: This build type of MongoDB runs on any 64-bit version of Windows latest than Windows XP, involve Windows Server 2008 R2 and Windows 7 64-bit.
    3. MongoDB for Windows 32-bit: MongoDB runs on any 32-bit version of Windows latest than Windows XP, 32-bit version of MongoDB are only designed for older system and use for testing and developing systems. Windows 32-bit versions of MongoDB support only database smaller than 2GB.

    If you want to know that which specific version of windows you are running at your system, then simply use following command on command prompt.

    Microsoft Windows [Version 6.3.9600]
    (c) 2013 Microsoft Corporation. All rights reserved.
    
    C:\Users\Pankaj>wmic os get osarchitecture
    OSArchitecture
    64-bit
    
    C:\Users\Pankaj>

    考虑您实际需要的特定MongoDB构建类型

    适用于Windows的三种MongoDB构建类型。

    1. Windows Server 2008 R2系列的MongoDB :此构建类型仅在2008R2,Windows 7 64位,Windows 8和Windows的最新版本上运行。
    2. 适用于Windows 64位的MongoDB:此MongoDB的构建类型可在Windows XP以外的任何64位版本的Windows上运行,涉及Windows Server 2008 R2和Windows 7 64位。
    3. 适用于Windows 32位版的MongoDB:MongoDB可以在Windows XP以外的任何32位版本的Windows上运行,MongoDB的32位版本仅适用于较旧的系统,并用于测试和开发系统。 Windows 32位版本的MongoDB仅支持小于2GB的数据库。

    如果您想知道系统上正在运行Windows的特定版本,则只需在命令提示符下使用以下命令。

  2. Download MongoDB for Windows

    Download the latest version release from the MongoDB Download page. Make sure you download the latest version of MongoDB for your Windows. Note that 64-bit versions of MongoDB do not run with 32-bit Windows.

    下载Windows版MongoDB

    从MongoDB下载页面下载最新版本。 确保为Windows下载了最新版本的MongoDB。 请注意,MongoDB的64位版本不能在32位Windows上运行。

  3. MongoDB Installation Options

    In Windows Explorer, simply locate downloaded MongoDB msi file, then Double-click the msi file. A series of screens will guide you through the installation procedure. There are multiple options such as Typical, Custom and Complete installation. MongoDB default installation goes into Program Files, so if you want to change it then go for Custom installation.

    MongoDB安装选项

    在Windows资源管理器中,只需找到下载的MongoDB msi文件,然后双击该msi文件。 一系列屏幕将指导您完成安装过程。 有多个选项,例如“典型”,“自定义”和“完整”安装。 MongoDB默认安装进入“程序文件”,因此,如果要更改它,则进行“自定义”安装。

  4. MongoDB installation folder move to another location (Optional)

    Sometimes we want to move the installation to another directory, we can use move command for this. This command needs to be run as administrator. For example, to move the folder to C:\MongoDB follow the steps shown in below images.

    MongoDB does not depend at any other system because it is self contained. You can execute MongoDB from the folder of your choice and can install it in any folder (for, example D:\test\mongodb)

    MongoDB安装文件夹移至另一个位置(可选)

    有时我们想将安装移动到另一个目录,为此可以使用move命令。 该命令需要以管理员身份运行。 例如,要将文件夹移动到C:\ MongoDB,请按照下图所示的步骤进行操作。

    MongoDB不依赖于任何其他系统,因为它是独立的。 您可以从您选择的文件夹中执行MongoDB,并将其安装在任何文件夹中(例如D:\ test \ mongodb)

运行MongoDB服务器 (Running MongoDB Server)

We need to create a directory where MongoDB server will store all it’s data. The MongoDB default data directory path is \data\db. Make this folder using the following commands from Command Prompt. Note that if the directory doesn’t exists, MongoDB will try to create it. But it’s good to create it before hand.

我们需要创建一个目录,MongoDB服务器将在其中存储所有数据。 MongoDB的默认数据目录路径为\ data \ db。 使用命令提示符中的以下命令创建此文件夹。 请注意,如果该目录不存在,MongoDB将尝试创建它。 但是事先创建它是很好的。

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Pankaj>cd \

C:\>md \data\db

C:\>

To start MongoDB server, we need to run mongod.exe. For example, from the Command Prompt;

要启动MongoDB服务器,我们需要运行mongod.exe。 例如,从命令提示符;

C:\>C:\MongoDB\bin\mongod.exe

This MongoDB starts the main databases process. The waiting for connection message in the console results determines that the mongod.exe process is complete.

此MongoDB启动主数据库过程。 控制台结果中的等待连接消息确定mongod.exe进程已完成。

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Pankaj>cd \

C:\>MongoDB\bin\mongod.exe
MongoDB\bin\mongod.exe --help for help and startup options
2014-11-11T13:36:19.016+0530 [initandlisten] MongoDB starting : pid=5292 port=27
017 dbpath=\data\db\ 64-bit host=Meghna
2014-11-11T13:36:19.017+0530 [initandlisten] targetMinOS: Windows 7/Windows Serv
er 2008 R2
2014-11-11T13:36:19.017+0530 [initandlisten] db version v2.6.5
2014-11-11T13:36:19.017+0530 [initandlisten] git version: e99d4fcb4279c0279796f2
37aa92fe3b64560bf6
2014-11-11T13:36:19.017+0530 [initandlisten] build info: windows sys.getwindowsv
ersion(major=6, minor=1, build=7601, platform=2, service_pack='Service Pack 1')
BOOST_LIB_VERSION=1_49
2014-11-11T13:36:19.017+0530 [initandlisten] allocator: system
2014-11-11T13:36:19.017+0530 [initandlisten] options: {}
2014-11-11T13:36:19.092+0530 [initandlisten] journal dir=\data\db\journal
2014-11-11T13:36:19.094+0530 [initandlisten] recover : no journal files present,
 no recovery needed
2014-11-11T13:36:19.186+0530 [initandlisten] allocating new ns file \data\db\loc
al.ns, filling with zeroes...
2014-11-11T13:36:20.002+0530 [FileAllocator] allocating new datafile \data\db\lo
cal.0, filling with zeroes...
2014-11-11T13:36:20.003+0530 [FileAllocator] creating directory \data\db\_tmp
2014-11-11T13:36:20.031+0530 [FileAllocator] done allocating datafile \data\db\l
ocal.0, size: 64MB,  took 0.018 secs
2014-11-11T13:36:20.035+0530 [initandlisten] build index on: local.startup_log p
roperties: { v: 1, key: { _id: 1 }, name: "_id_", ns: "local.startup_log" }
2014-11-11T13:36:20.036+0530 [initandlisten]     added index to empty collection

2014-11-11T13:36:20.037+0530 [initandlisten] command local.$cmd command: create
{ create: "startup_log", size: 10485760, capped: true } ntoreturn:1 keyUpdates:0
 numYields:0  reslen:37 851ms
2014-11-11T13:36:20.038+0530 [initandlisten] waiting for connections on port 270
17

You can use a different path for data files using the –dbpath option to mongod.exe, for example:

您可以使用mongod.exe的–dbpath选项为数据文件使用其他路径,例如:

C:\>C:\MongoDB\bin\mongod.exe --dbpath D:\test\mongodb\data

If your path contains white spaces, then you need to use double quotes as shown below.

如果路径中包含空格,则需要使用双引号,如下所示。

C:\>C:\MongoDB\bin\mongod.exe --dbpath "D:\test\mongo db data"

The security level depends on your system configurations, Windows provide pop up a Security Alert dialog box about blocking few features of C:\Folder Name\MongoDB\bin\mongod.exe from communication on networks.

安全级别取决于您的系统配置,Windows提供弹出的“安全警报”对话框,用于阻止C:\Folder Name\MongoDB\bin\mongod.exe功能阻止网络通信。

All the clients should choose Private Networks. For example, my home or work network and click Allow access. For more information on security and MongoDB, please look into the Security Documentation.

所有客户端都应选择专用网络。 例如,我的家庭或工作网络,然后单击“允许访问”。 有关安全性和MongoDB的更多信息,请查看安全性文档。

通过命令提示符连接到MongoDB服务器 (Connecting to MongoDB server through Command Prompt)

We can connect to MongoDB server through mongo.exe client application, just open another command prompt and execute it.

我们可以通过mongo.exe客户端应用程序连接到MongoDB服务器,只需打开另一个命令提示符并执行它即可。

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Pankaj>C:\MongoDB\bin\mongo.exe
MongoDB shell version: 2.6.5
connecting to: test
Welcome to the MongoDB shell.
For interactive help, type "help".
For more comprehensive documentation, see
        https://docs.mongodb.org/
Questions? Try the support group
        https://groups.google.com/group/mongodb-user
>

That’s it, once connected we can issue any MongoDB shell commands. To close the client connection, just fire “exit” command or simply close the command prompt.

就是这样,一旦连接,我们就可以发出任何MongoDB shell命令。 要关闭客户端连接,只需触发“退出”命令或直接关闭命令提示符即可。

MongoDB作为Windows服务 (MongoDB as Windows Service)

The problem with above installation is that we need to start MongoDB server manually and then keep the command prompt open. The solution is to configure it as Windows service, so that it can start as soon as system is up and running. Since it will be running in background, there is no need to keep command prompt open.

上面安装的问题是我们需要手动启动MongoDB服务器,然后保持命令提示符打开。 解决方案是将其配置为Windows服务,以便它可以在系统启动并运行后立即启动。 由于它将在后台运行,因此无需保持命令提示符打开。

Before we configure our MongoDB installation as Windows service, let’s create a configuration file for the MongoDB logs.

在将MongoDB安装配置为Windows服务之前,让我们为MongoDB日志创建一个配置文件。

Microsoft Windows [Version 6.3.9600]
(c) 2013 Microsoft Corporation. All rights reserved.

C:\Users\Pankaj>cd \

C:\>md MongoDB-logs

Now using echo command we can create a configuration file. If you get any permission issues, then run the command prompt as administrator.

现在,使用echo命令,我们可以创建一个配置文件。 如果遇到任何权限问题,请以管理员身份运行命令提示符。

C:\WINDOWS\system32>echo logpath=C:\MongoDB-logs\mongo.log > C:\MongoDB\mongod.conf

Now run below command as administrator to setup MongoDB as service.

现在以管理员身份在命令下方运行,以将MongoDB设置为服务。

C:\>C:\MongoDB\bin\mongod.exe --config C:\MongoDB\mongod.conf --install

C:\>

If you want to change MongoDB server port or any other configurations, then you can provide them in the above configuration file.

如果要更改MongoDB服务器端口或任何其他配置,则可以在上述配置文件中提供它们。

If you want to install services for multiple example of mongod.exe, install every service with a unique –serviceName and –serviceDisplayName. Use the multiple examples only when sufficient system resources exist and your design requires it.

如果要为mongod.exe的多个示例安装服务,请使用唯一的–serviceName和–serviceDisplayName安装每个服务。 仅当存在足够的系统资源并且您的设计需要它时,才使用多个示例。

卸载MongoDB Windows (Uninstall MongoDB Windows)

If you want to remove the MongoDB service, then run below command as administrator.

如果要删除MongoDB服务,请以管理员身份在命令下方运行。

C:\>C:\MongoDB\bin\mongod.exe --config C:\MongoDB\mongod.conf --remove

C:\>

That’s all for installing MongoDB on Windows and running it as Windows service. We will look into different MongoDB commands in coming posts.

这就是在Windows上安装MongoDB并将其作为Windows服务运行的全部内容。 我们将在后续文章中研究不同的MongoDB命令。

翻译自: https://www.journaldev.com/6128/install-mongodb-windows-start-uninstall

mongodb卸载

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值