mongodb作为一种文档型的nosql数据库,使用起来非常灵活,回避了关系型数据库前期的复杂数据库设计。mongodb存储基于json格式,同
mongodb部署实验系列文章,mongodb做为nosql数据库,最近几年持续升温,越来越多的企业都开始尝试用mongodb代替原有database做一些事情。mongodb也在集群,分片,复制上也有相当不错的的表现。我通过将做各种mongodb的部署实验进行介绍。
前言
mongodb作为一种文档型的nosql数据库,使用起来非常灵活,回避了关系型数据库前期的复杂数据库设计。mongodb存储基于json格式,同时用javascript做为数据库操作语言,给了使用者无限想象的空间,可以通过编程在mongodb服务器中解决非常复杂的条件查询的问题。
目录
1 mongodb在windows中安装在windows系统上安装mongodb数据库是件非常简单的事情,下载可执行安装文件(exe),双击安装即可。下载地址:
mongodb服务器运行命令:mongodb安装目录/bin/mongod.exemongodb客户端运行命令:mongodb安装目录/bin/mongo.exe2 mongodb在linux ubuntu中安装本文使用的linux是ubuntu 12.04.2 lts 64bit的系统,安装mongodb数据库软件包可以通过apt-get实现。但我们修要安装官方提供mongodb软件源。
修改apt的source.list文件,增加10gen的设置。
# 下载密钥文件~ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 7f0ceb10executing: gpg --ignore-time-conflict --no-options --no-default-keyring --secret-keyring /tmp/tmp.kvfab9xyw0 --trustdb-name /etc/apt/trustdb.gpg --keyring /etc/apt/trusted.gpg --primary-keyring /etc/apt/trusted.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv 7f0ceb10gpg: 下载密钥‘7f0ceb10’,从 hkp 服务器 keyserver.ubuntu.comgpg: 密钥 7f0ceb10:公钥“richard kreuter ”已导入gpg: 没有找到任何绝对信任的密钥gpg: 合计被处理的数量:1gpg:已导入:1 (rsa: 1)# 在source.list中增加mongodb源的配置~ echo 'deb dist 10gen' | sudo tee /etc/apt/sources.list.d/mongodb.listdeb dist 10gen# 更新软件源~ sudo apt-get update在linux ubuntu中安装mongodb数据库
#安装mongodb服务器端~ sudo apt-get install mongodb-10gen安装完成后,mongodb服务器会自动启动,我们检查mongodb服务器程序
# 检查mongodb服务器系统进程~ ps -aux|grep mongomongodb 6870 3.7 0.4 349208 39740 ?ssl 10:27 2:23 /usr/bin/mongod --config /etc/mongodb.conf# 通过启动命令检查mongodb服务器状态~ netstat -nlt|grep 27017tcp00 0.0.0.0:270170.0.0.0:*listen# 通过启动命令检查mongodb服务器状态~ sudo /etc/init.d/mongodb statusrather than invoking init scripts through /etc/init.d, use the service(8)utility, e.g. service mongodb statussince the script you are attempting to invoke has been converted to anupstart job, you may also use the status(8) utility, e.g. status mongodbmongodb start/running, process 6870# 通过系统服务检查mongodb服务器状态~ sudo service mongodb statusmongodb start/running, process 6870通过web的控制台,查看mongodb服务器的状态。在浏览器输入 :28017 ,,就可以打开通过web的控制台了。
3. 通过命令行客户端访问mongodb安装mongodb服务器,会自动地一起安装mongodb命令行客户端程序。
在本机输入mongo命令就可以启动,客户端程序访问mongodb服务器。
~ mongomongodb shell version: 2.4.9connecting to: testwelcome to the mongodb shell.for interactive help, type help.for more comprehensive documentation, seequestions? try the support group# 查看命令行帮助> helpdb.help()help on db methodsdb.mycoll.help()help on collection methodssh.help()sharding helpersrs.help()replica set helpershelp adminadministrative helphelp connectconnecting to a db helphelp keyskey shortcutshelp miscmisc things to knowhelp mrmapreduceshow dbsshow database namesshow collectionsshow collections in current databaseshow usersshow users in current databaseshow profileshow most recent system.profile entries with time >= 1msshow logsshow the accessible logger namesshow log [name]prints out the last segment of log in memory, 'global' is defaultuse set current databasedb.foo.find()list objects in collection foodb.foo.find( { a : 1 } )list objects in foo where a == 1itresult of the last line evaluated; use to further iteratedbquery.shellbatchsize = x set default number of items to display on shellexitquit the mongo shellmongodb服务器,默认情况下是允许外部访问的。这样单节的mongodb,我们已经成功地安装在linux ubuntu系统中。
mongodb 的详细介绍:请点这里
mongodb 的下载地址:请点这里
相关阅读:
mongodb备份与恢复
centos编译安装mongodb
centos 编译安装 mongodb与mongodb的php扩展
centos 6 使用 yum 安装mongodb及服务器端配置
ubuntu 13.04下安装mongodb2.4.3
如何在mongodb中建立新数据库和集合
mongodb入门必读(概念与实战并重)
《mongodb 权威指南》(mongodb: the definitive guide)英文文字版[pdf]