MongoDB的安装与配置(windows&Linux)

来源:互联网 发布:纳什均衡和福利最优化 编辑:程序博客网 时间:2024/05/22 08:01

windows

1、下载安装
根据个人系统的不同,下载相应的MongoDB解压到D:/MongoDB
创建数据库目录D:\MongoDB\data,接下来打开命令行窗口,切换到D:\MongoDB\bin 目录执行如下命令:

mongod --dbpath D:\MongoDB\data

最后出现如下信息就表示执行成功:2014-04-23T10:38:48.391+0800 [initandlisten] waiting for connections on port 27017
在浏览器输入http://localhost:27017/得到如下信息:It looks like you are trying to access MongoDB over HTTP on the native driver port.就表示启动成功了。
2、MongoDB作为windows服务启动
创建log目录D:\MongoDB\logs ;
执行如下命令:

mongod --dbpath D:\MongoDB\data --logpath=D:\MongoDB\logs\mongodb.log --logappend

附注

2.6版无法安装windows服务BUG链接 https://jira.mongodb.org/browse/SERVER-13515
MongoDB官网:http://www.mongodb.org/


linux

1、下载
MongoDB下载地址:https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-2.7.0.tgz 下载到/usr/local/目录
2、解压安装(无需编译)

#步骤一:解压mongodb-linux-x86_64-3.0.4.tgz压缩包[root@XXTS-db mongodb]# tar -zxvf mongodb-linux-x86_64-3.0.4.gz #步骤二:创建数据目录和日志目录mv  mongodb-linux-x86_64-2.7.0 /usr/local/mongodb  #移动解压文件夹到mongodbmkdir  -p  /hxdata/mongodb/data                #创建MongoDB数据库存放路径mkdir  -p  /hxdata/mongodb/log               #创建MongoDB数据库日志存放路径步骤三:启动:进入mongodb解压目录(默认端口27017)./bin/mongod -port 27017 --dbpath=/data/mongodb_data/ --logpath=//data/mongodb_log/server.log  --fork#步骤四:验证是否启动成功[root@localhost mongodb-linux-i686-3.0.4]# ./bin/mongoMongoDB shell version: 3.0.4connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".

3、检测mongodb的运行情况

  • 用netstat检测端口监听状态
netstat -ntpl  | grep 27017    #查看MongoDB是否启动 默认端口号是27017

4、使用&部分操作

进入到bin目录,执行mongo开启客户端程序连接到数据库。运行./mongo

./bin/mongoMongoDB shell version: 3.0.4connecting to: testWelcome to the MongoDB shell.For interactive help, type "help".For more comprehensive documentation, see    http://docs.mongodb.org/Questions? Try the support group    http://groups.google.com/group/mongodb-user//使用msgs数据库use collections                                                                  switched to db collections//查看msgs数据库的状态(名字、集合、数据等,以及索引数量和大小)db.stats();                                                               {    "db" : "collections_name",    "collections" : 17,    "objects" : 546815,    "avgObjSize" : 961.1196181523916,    "dataSize" : 525554624,    "storageSize" : 868048896,    "numExtents" : 58,    "indexes" : 17,    "indexSize" : 39252976,    "fileSize" : 1006632960,    "nsSizeMB" : 16,    "dataFileVersion" : {        "major" : 4,        "minor" : 5    },    "extentFreeList" : {        "num" : 0,        "totalSize" : 0    },    "ok" : 1}> db.system.indexes.find();                                                 #查看当前索引的建立的情况{ "v" : 1, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "collection_name.db" }> db.collection_name.ensureIndex({"list_name":1});                                      #为这个集合增加索引,默认是这样写是不指定索引的名字的,默认名字比如这个就是 数据集名_1 
0 0
原创粉丝点击