zoukankan      html  css  js  c++  java
  • 记MongoDB的安装

    在我的win10系统下可以正常安装MongoDB官网的msi文件,但为我的另一台安装时却报告以下错误:

    service 'mongodb server' failed to start. verify that you have sufficient privileges to start system services

    提示我没有足够的权限开启系统服务。我在cmd里开启管理员权限还是不行。

    经过一番折腾还是不行,只得作罢,转而安装MongoDB的zip包,具体步骤如下:

    1. 从官网下载后直接解压至指定目录D:MongoDB。

    2. 在该目录下新建两个文件夹

    D:MongoDBdata 用于存放数据库

    D:MongoDBlog ,并新建文件mongod.log,用于存放日志

    3. 在D:MongoDBin 目录下新建mongod.cfg配置文件,内容如下:

     1 # mongod.conf
     2 
     3 # for documentation of all options, see:
     4 #   http://docs.mongodb.org/manual/reference/configuration-options/
     5 
     6 # Where and how to store data.
     7 storage:
     8   dbPath: D:MongoDBdata
     9   journal:
    10     enabled: true
    11 #  engine:
    12 #  mmapv1:
    13 #  wiredTiger:
    14 
    15 # where to write logging data.
    16 systemLog:
    17   destination: file
    18   logAppend: true
    19   path:  D:MongoDBlogmongod.log
    20 
    21 # network interfaces
    22 net:
    23   port: 27017
    24   bindIp: 127.0.0.1
    25 
    26 
    27 #processManagement:
    28 
    29 #security:
    30 
    31 #operationProfiling:
    32 
    33 #replication:
    34 
    35 #sharding:
    36 
    37 ## Enterprise-Only Options:
    38 
    39 #auditLog:
    40 
    41 #snmp:
    View Code

    配置文件中指定了数据库和日志的路径。

    4. 将D:MongoDBin 目录加入环境变量方便调用。

    5. 注册service服务 以便于以后好启动

    在CMD中输入mongod --config D:MongoDBinmongod.cfg --install 进行安装,mongod.cfg中已经指定了数据库和日志的路径。

    在Windows服务中已经可以看到MongoDB服务。

    如何删除现有服务:mongod --config D:MongoDBinmongod.cfg --remove

    6.  在CMD中输入net start mongodb开启MongoDB服务

     至此 安装已经结束!

    通过pymongo调用MongoDB:

    1 import pymongo
    2 from pymongo import MongoClient
    3 
    4 client = MongoClient('localhost', 27017)
    5 
    6 db = client.test
    7 
    8 
    9 db.insert_one({'index': 1, 'name': name})


  • 相关阅读:
    opencast的docker安装
    编译openwrt_MT7688_hiwooya
    linux中mysql自动同步
    网站服务器迁移
    vtigercrm安装
    ixcache的蜜汁突发故障
    20180628
    pip3 install -r requirements.txt安装超时解决方法
    pytest文档29-allure-pytest
    pytest框架
  • 原文地址:https://www.cnblogs.com/jiangkejie/p/13198562.html
Copyright © 2011-2022 走看看