1.首先下载MongoDBzip压缩包
2.解压,把bin路径配置到path环境变量
3.在安装目录下创建data目录和log目录
4.在data下创建db目录,在log下创建mongo.log空文件
在cmd下切换到bin目录,执行以下命令:
查看日志:
2020-07-15T23:51:30.976+0800 I CONTROL ?[main] Trying to install Windows service ‘Mongodb‘
2020-07-15T23:51:30.980+0800 I CONTROL ?[main] Error connecting to the Service Control Manager: 拒绝访问。 (5)
解决办法:
找到C:\Windows\System32 ?目录下 ?右击cmd 选择已管理员身份运行
注意,一定要以管理员方式运行
查看日志
2020-07-15T23:54:06.878+0800 I CONTROL ?[main] Trying to install Windows service ‘Mongodb‘
2020-07-15T23:54:09.576+0800 I CONTROL ?[main] Service ‘Mongodb‘ (MongoDB) installed with command line ‘D:\MyUser\java\mongodb\mongodb-3.6.11\bin\mongod.exe --bind_ip 127.0.0.1 --logpath D:\MyUser\java\mongodb\mongodb-3.6.11\log\mongo.log--logappend --dbpath D:\MyUser\java\mongodb\mongodb-3.6.11\data\db --service‘
2020-07-15T23:54:09.577+0800 I CONTROL ?[main] Service can be started from the command line with ‘net start Mongodb‘
说明安装成功
输入net start Mongodb
查看日志:
2020-07-15T23:55:14.421+0800 I CONTROL ?[main] Trying to start Windows service ‘MongoDB‘
2020-07-15T23:55:14.423+0800 I CONTROL ?[initandlisten] MongoDB starting : pid=12084 port=27017 dbpath=D:\MyUser\java\mongodb\mongodb-3.6.11\data\db 64-bit host=DESKTOP-CV5IFFH
2020-07-15T23:55:14.423+0800 I CONTROL ?[initandlisten] targetMinOS: Windows 7/Windows Server 2008 R2
2020-07-15T23:55:14.424+0800 I CONTROL ?[initandlisten] db version v3.6.11
2020-07-15T23:55:14.424+0800 I CONTROL ?[initandlisten] git version: b4339db12bf57ffee5b84a95c6919dbd35fe31c9
2020-07-15T23:55:14.425+0800 I CONTROL ?[initandlisten] OpenSSL version: OpenSSL 1.0.2o-fips ?27 Mar 2018
2020-07-15T23:55:14.425+0800 I CONTROL ?[initandlisten] allocator: tcmalloc
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] modules: none
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] build environment:
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] ? ? distmod: 2008plus-ssl
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] ? ? distarch: x86_64
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] ? ? target_arch: x86_64
2020-07-15T23:55:14.426+0800 I CONTROL ?[initandlisten] options: { net: { bindIp: "127.0.0.1" }, service: true, storage: { dbPath: "D:\MyUser\java\mongodb\mongodb-3.6.11\data\db" }, systemLog: { destination: "file", path: "D:\MyUser\java\mongodb\mongodb-3.6.11\log\mongo.log--logappend" } }
2020-07-15T23:55:14.553+0800 I STORAGE ?[initandlisten] wiredtiger_open config: create,cache_size=3532M,session_max=20000,eviction=(threads_min=4,threads_max=4),config_base=false,statistics=(fast),compatibility=(release="3.0",require_max="3.0"),log=(enabled=true,archive=true,path=journal,compressor=snappy),file_manager=(close_idle_time=100000),statistics_log=(wait=0),verbose=(recovery_progress),
2020-07-15T23:55:14.843+0800 I STORAGE ?[initandlisten] WiredTiger message [1594828514:843383][12084:140727611576928], txn-recover: Set global recovery timestamp: 0
2020-07-15T23:55:15.309+0800 I CONTROL ?[initandlisten]?
2020-07-15T23:55:15.310+0800 I CONTROL ?[initandlisten] ** WARNING: Access control is not enabled for the database.
2020-07-15T23:55:15.310+0800 I CONTROL ?[initandlisten] ** ? ? ? ? ?Read and write access to data and configuration is unrestricted.
2020-07-15T23:55:15.310+0800 I CONTROL ?[initandlisten]?
2020-07-15T23:55:15.311+0800 I STORAGE ?[initandlisten] createCollection: admin.system.version with provided UUID: 0a85b905-43b2-4318-8713-813cd2d3d58d
2020-07-15T23:55:15.442+0800 I COMMAND ?[initandlisten] setting featureCompatibilityVersion to 3.6
2020-07-15T23:55:15.459+0800 I STORAGE ?[initandlisten] createCollection: local.startup_log with generated UUID: 66a35f7b-9d6c-4eeb-bfaf-c7fabe683bae
2020-07-15T23:55:16.318+0800 I FTDC ? ? [initandlisten] Initializing full-time diagnostic data capture with directory ‘D:/MyUser/java/mongodb/mongodb-3.6.11/data/db/diagnostic.data‘
2020-07-15T23:55:16.320+0800 I STORAGE ?[LogicalSessionCacheRefresh] createCollection: config.system.sessions with generated UUID: b17132e9-61d0-4832-be71-191678965503
2020-07-15T23:55:16.320+0800 I NETWORK ?[initandlisten] waiting for connections on port 27017
2020-07-15T23:55:16.320+0800 I STORAGE ?[initandlisten] Service running
2020-07-15T23:55:16.574+0800 I INDEX ? ?[LogicalSessionCacheRefresh] build index on: config.system.sessions properties: { v: 2, key: { lastUse: 1 }, name: "lsidTTLIndex", ns: "config.system.sessions", expireAfterSeconds: 1800 }
2020-07-15T23:55:16.574+0800 I INDEX ? ?[LogicalSessionCacheRefresh] ?? ? building index using bulk method; build may temporarily use up to 500 megabytes of RAM
2020-07-15T23:55:16.599+0800 I INDEX ? ?[LogicalSessionCacheRefresh] build index done. ?scanned 0 total records. 0 secs
2020-07-15T23:55:16.599+0800 I COMMAND ?[LogicalSessionCacheRefresh] command config.$cmd command: createIndexes { createIndexes: "system.sessions", indexes: [ { key: { lastUse: 1 }, name: "lsidTTLIndex", expireAfterSeconds: 1800 } ], $db: "config" } numYields:0 reslen:98 locks:{ Global: { acquireCount: { r: 2, w: 2 } }, Database: { acquireCount: { w: 2, W: 1 } }, Collection: { acquireCount: { w: 2 } } } protocol:op_msg 279ms
?
测试服务是否安装成功:
在浏览器*问:http://localhost:27017/
说明安装成功