MongoDB: MongoDB 安装和使用(zip)

[复制链接]
发表于 2022-10-15 02:33:00 | 显示全部楼层 |阅读模式

MongoDB 安装和使用(zip)

 

 

 

 

一、MongoDB 准备工作:

 

 

  1、MongoDB 下载:

    1.1、mongodb 下载(version-windows-zip):https://www.mongodb.com/try/download/community

    1.2、shell 下载(version-windows-zip):https://www.mongodb.com/try/download/compass

 

 

  2、建立目录:

    2.1、MongoDB安装目录:D:\tools\web\db\mongodb

    2.2、MongoDB安装根目录:D:\tools\web\db\mongodb\mongodb_install

    2.3、数据存储目录:D:\tools\web\db\mongodb\mongodb_data\data

    2.4、日志存储目录:D:\tools\web\db\mongodb\mongodb_data\log\mongod.log

    2.5、建立空文件mogod.log:D:\tools\web\db\mongodb\mongodb_data\log\mongod.log

 

 

  3、配置文件(D:\tools\web\db\mongodb\mongodb602\mongod.cfg)

    3.1、yaml入门教程:https://www.runoob.com/w3cnote/yaml-intro.html

    3.2、配置文件内容(mongod.cfg):

storage:
    dbPath: D:\tools\web\db\mongodb\mongodb_data\data
systemLog:
    destination: file
    path: D:\tools\web\db\mongodb\mongodb_data\log\mongod.log

 

 

   4、配置系统环境变量(以追加添加环境变量):

      4.1、path = ;D:\tools\web\db\mongodb\mongodb_install\bin;

 

 

 

 

 

 

 

二、MongoDB:安装服务、服务开启、服务关闭、卸载服务

 

 

  1、MongoDB:安装服务、服务开启、服务关闭、卸载服务:

 

 1 G:\tmpWorkspaces>mongod  --config "D:\tools\web\db\mongodb\mongodb_install\bin\mongod.cfg"  --install
 2 
 3 G:\tmpWorkspaces>net start MongoDB
 4 The MongoDB service is starting...
 5 The MongoDB service was started successfully.
 6 
 7 
 8 G:\tmpWorkspaces>net stop MongoDB
 9 The MongoDB service is stopping.
10 The MongoDB service was stopped successfully.
11 
12 
13 G:\tmpWorkspaces>mongod  --remove
14 {"t":{"$date":"2023-01-27T04:20:06.891+08:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"-","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
15 {"t":{"$date":"2023-01-27T04:20:06.899+08:00"},"s":"I",  "c":"NETWORK",  "id":4915701, "ctx":"thread1","msg":"Initialized wire specification","attr":{"spec":{"incomingExternalClient":{"minWireVersion":0,"maxWireVersion":17},"incomingInternalClient":{"minWireVersion":0,"maxWireVersion":17},"outgoing":{"minWireVersion":6,"maxWireVersion":17},"isInternalClient":true}}}
16 {"t":{"$date":"2023-01-27T04:20:11.155+08:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"thread1","msg":"Implicit TCP FastOpen in use."}
17 {"t":{"$date":"2023-01-27T04:20:11.161+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationDonorService","namespace":"config.tenantMigrationDonors"}}
18 {"t":{"$date":"2023-01-27T04:20:11.161+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"TenantMigrationRecipientService","namespace":"config.tenantMigrationRecipients"}}
19 {"t":{"$date":"2023-01-27T04:20:11.162+08:00"},"s":"I",  "c":"REPL",     "id":5123008, "ctx":"thread1","msg":"Successfully registered PrimaryOnlyService","attr":{"service":"ShardSplitDonorService","namespace":"config.tenantSplitDonors"}}
20 {"t":{"$date":"2023-01-27T04:20:11.162+08:00"},"s":"I",  "c":"CONTROL",  "id":23307,   "ctx":"thread1","msg":"Trying to remove Windows service","attr":{"name":"MongoDB"}}
21 {"t":{"$date":"2023-01-27T04:20:11.180+08:00"},"s":"I",  "c":"CONTROL",  "id":23312,   "ctx":"thread1","msg":"Service removed","attr":{"serviceName":"MongoDB"}}
22 
23 G:\tmpWorkspaces>
24 G:\tmpWorkspaces>

 

 

 

 

  2、MongoDB:安装服务、服务开启、服务关闭、卸载服务 (操作实例)

 

 

 

 

 

三、MongoDB 使用教程

 

 

  1、MongoDB 教程(菜鸟教程):https://www.runoob.com/mongodb/mongodb-tutorial.html

 

回复

使用道具 举报

发表于 2026-10-4 20:16:52 | 显示全部楼层
感谢楼主分享! zip 方式安装确实灵活,适合做绿色版或者多版本切换。补充一个我踩过的坑:手动创建数据目录后,首次启动时最好先到 bin 目录下用 mongod --dbpath "数据目录路径" 测试一下能否正常启动,确认没问题再封装成服务。另外如果遇到 mongo shell 连接报错,很可能是新版 shell 版本和服务器版本不匹配,记得去楼主给的第二个链接单独下载对应版本的 mongosh,别直接装 compass 完事哦~期待后续配置副本集的文章!
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

圆梦公社,专注于为全球华人提供纯粹技术交流的地方,请勿发布任何政治及违法的言论。如有相关侵权、举报、投诉及建议等,请发 E-mail:dzh188@hotmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部