永利开户送38元体验金 1

CentOS7 安装MongoDB 3.0服务器

MongoDB 前几天宣布3.0正经版本将在发布。那标识着 MongoDB
数据库步入了叁个全新的提升阶段,提供强大、灵活何况轻松管理的数据库管理种类。MongoDB
3.0
在品质和伸缩性方面皆有那些巨大的进级换代,通过在存款和储蓄层的大幅修正完成。内建
WiredTiger存储引擎,那是一项出乎意料的工夫完毕,提供无门闩、非窒碍算法来利用先进的硬件平台来进步性能。通过
WiredTiger ,MongoDB 3.0
完成了文书档案级其余现身调节,由此大幅度进级了大并发下的写负载。透明的磁盘压缩本事裁减对存款和储蓄的体量供给达
百分之九十。

1,下载&安装

MongoDB 3.0 正式版本宣布!那注解着 MongoDB
数据库步入了四个簇新的上扬阶段,提供强大、灵活並且便于管理的数据库管理种类。MongoDB宣称,3.0新本子不但提高7到10倍的写入功效甚至扩张十分九的数据压缩率,还是能减小95%的运转花费。
  MongoDB 3.0第一新特征包涵:
  ·可插入式的蕴藏引擎 API
  ·援救 WiredTiger 存款和储蓄引擎
  ·MMAPv1 提升
  ·复制集周全提升
  ·集群方面包车型地铁改良
  ·进步了安全性
  ·工具的升级
WiredTiger存款和储蓄引擎是一项匪夷所思的手艺实现,提供无门闩、非窒碍算法来利用先进的硬件平台(如大体积微电路缓存和线程化构造State of Qatar来提高品质。通过
WiredTiger,MongoDB 3.0
实现了文档次和品级别的面世调整,因此小幅度进步了大并发下的写负载。

MongoDB 提供了centos yum安装格局。
参考:
pdf 手册:

vi /etc/yum.repos.d/mongodb-org-3.0.repo

[mongodb-org-3.0]name=MongoDB Repositorybaseurl=http://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/3.0/x86_64/gpgcheck=0enabled=1

安装mongodb

yum install -y mongodb-org

设置了具备有关服务。

......Running transaction  Installing : mongodb-org-shell-3.0.2-1.el7.x86_64      1/5   Installing : mongodb-org-tools-3.0.2-1.el7.x86_64      2/5   Installing : mongodb-org-mongos-3.0.2-1.el7.x86_64     3/5   Installing : mongodb-org-server-3.0.2-1.el7.x86_64     4/5   Installing : mongodb-org-3.0.2-1.el7.x86_64            5/5   Verifying  : mongodb-org-3.0.2-1.el7.x86_64           1/5   Verifying  : mongodb-org-server-3.0.2-1.el7.x86_64    2/5   Verifying  : mongodb-org-mongos-3.0.2-1.el7.x86_64    3/5   Verifying  : mongodb-org-tools-3.0.2-1.el7.x86_64     4/5   Verifying  : mongodb-org-shell-3.0.2-1.el7.x86_64     5/5

布署文件在:/etc/mongod.conf 数据文件在:/var/lib/mongo
日志文件在:/var/log/mongodb mongodb服务应用

#启动service mongod start#停止service mongod stop#重启service mongod restart#增加开机启动chkconfig mongod on

2,MongoDB CRUD

参考:

接连几天到MongoDB,很简短,实施mongo就能够了。

# mongoMongoDB shell version: 3.0.2connecting 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-userServer has startup warnings: 2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] 2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] ** WARNING: Readahead for /var/lib/mongo is set to 4096KB2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          http://dochub.mongodb.org/core/readahead2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/enabled is 'always'.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: /sys/kernel/mm/transparent_hugepage/defrag is 'always'.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] **        We suggest setting it to 'never'2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] 2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] ** WARNING: soft rlimits too low. rlimits set to 4096 processes, 64000 files. Number of processes should be at least 32000 : 0.5 times number of files.2015-04-29T18:03:17.679+0800 I CONTROL  [initandlisten] > 

2.1,创造数量:

> db.users.insert(... {... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({ "nInserted" : 1 })> db.users.insert(... {... _id:1,... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({ "nInserted" : 1 })> db.users.insert(... {... _id:1,... name:"zhang san",... age:26,... city:"bei jing"... }... )WriteResult({        "nInserted" : 0,        "writeError" : {                "code" : 11000,                "errmsg" : "E11000 duplicate key error index: test.users.$_id_ dup key: { : 1.0 }"        }})> db.users.insert(... {... _id:2,... name:"li si",... age:28,... city:"shang hai"... }... )WriteResult({ "nInserted" : 1 })

多少能够未有主键_永利开户送38元体验金,id,若无,会自动生成四个。要是设置了_id主键,就务须不另行。
不然报主键冲突:“E11000 duplicate key error index: test.users.$_id_
dup key: { : 1.0 }”

2.2,更新数据:

> db.users.update(... {_id:2},... {... $set: {... city:"guang zhou"... }... }... )WriteResult({ "nMatched" : 1, "nUpserted" : 0, "nModified" : 1 })> db.users.update(... {_id:3},... {... $set: {... city:"si chuan"... }... },... { upsert: true }... )WriteResult({ "nMatched" : 0, "nUpserted" : 1, "nModified" : 0, "_id" : 3 })

履新使用update,如若扩张{ upsert: true },则代表并未有查询到数码间接插入。

2.3,删除:

> db.users.remove({_id:3})WriteResult({ "nRemoved" : 1 })> db.users.remove({_id:4})WriteResult({ "nRemoved" : 0 })

查询到数码才开展删减,何况重回删除数量。

2.4,查询:

> db.users.find({age:{ $gt: 26}}){ "_id" : 2, "name" : "li si", "age" : 28, "city" : "guang zhou" }> db.users.find({age:{ $gt: 25}}){ "_id" : ObjectId("5540adf29b0f52a6786de216"), "name" : "zhang san", "age" : 26, "city" : "bei jing" }{ "_id" : 1, "name" : "zhang san", "age" : 26, "city" : "bei jing" }{ "_id" : 2, "name" : "li si", "age" : 28, "city" : "guang zhou" }#查询全部数据> db.users.find(){ "_id" : ObjectId("5540adf29b0f52a6786de216"), "name" : "zhang san", "age" : 26, "city" : "bei jing" }{ "_id" : 1, "name" : "zhang san", "age" : 26, "city" : "bei jing" }{ "_id" : 2, "name" : "li si", "age" : 28, "city" : "guang zhou" }

2.5,越来越多措施

db.collection.aggregate() db.collection.count() db.collection.copyTo()
db.collection.createIndex() db.collection.getIndexStats()
db.collection.indexStats() db.collection.dataSize()
db.collection.distinct() db.collection.drop() db.collection.dropIndex()
db.collection.dropIndexes() db.collection.ensureIndex()
db.collection.explain() db.collection.find()
db.collection.findAndModify() db.collection.findOne()
db.collection.getIndexes() db.collection.getShardDistribution()
db.collection.getShardVersion() db.collection.group()
db.collection.insert() db.collection.isCapped()
db.collection.mapReduce() db.collection.reIndex() db.collection.remove()
db.collection.renameCollection() db.collection.save()
db.collection.stats() db.collection.storageSize()
db.collection.totalSize() db.collection.totalIndexSize()
db.collection.update() db.collection.validate()

3,MongoDB可视化学工业具

永利开户送38元体验金 2

动用可视化工具,方便使用MongoDB管理。 首先要改革下端口和ip vi
/etc/mongod.conf

port=27017dbpath=/var/lib/mongo# location of pidfilepidfilepath=/var/run/mongodb/mongod.pid# Listen to local interface only. Comment out to listen on all interfaces.bind_ip=192.168.1.36

然后重启MongoDB

service mongod restart

接下去就足以创设贰个mongodb连接:永利开户送38元体验金 3
连接成功今后效果: 永利开户送38元体验金 4

4,总结

本文最早的文章连接:

MongoDB 3.0操作起来依然很有益于的。能高效的运用。
同有的时候候MongoDB增添也很有利。接下来切磋。
对应网络业务以来未有复杂的join查询。只追求急迅,快捷访谈。

安装MongoDB 3.0服务器 1,下载安装 MongoDB
3.0 正式版本发表!那评释着 MongoDB
数据库步向了三个全新的进步阶段,提供强盛、灵活并且易…

相关文章