日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
CentOS7安裝MongoDB3.0服務(wù)

1,下載&安裝

MongoDB 3.0 正式版本發(fā)布!這標(biāo)志著 MongoDB 數(shù)據(jù)庫(kù)進(jìn)入了一個(gè)全新的發(fā)展階段,提供強(qiáng)大、靈活而且易于管理的數(shù)據(jù)庫(kù)管理系統(tǒng)。MongoDB宣稱,3.0新版本不只提升7到10倍的寫(xiě)入效率以及增加80%的數(shù)據(jù)壓縮率,還能減少95%的運(yùn)維成本。
  MongoDB 3.0主要新特性包括:
  ·可插入式的存儲(chǔ)引擎 API
  ·支持 WiredTiger 存儲(chǔ)引擎
  ·MMAPv1 提升
  ·復(fù)制集全面提升
  ·集群方面的改進(jìn)
  ·提升了安全性
  ·工具的提升
WiredTiger 存儲(chǔ)引擎是一項(xiàng)難以置信的技術(shù)實(shí)現(xiàn),提供無(wú)門閂、非堵塞算法來(lái)利用先進(jìn)的硬件平臺(tái)(如大容量芯片緩存和線程化架構(gòu))來(lái)提升性能。通過(guò) WiredTiger,MongoDB 3.0 實(shí)現(xiàn)了文檔級(jí)別的并發(fā)控制,因此大幅提升了大并發(fā)下的寫(xiě)負(fù)載。

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

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

安裝mongodb

yum install -y mongodb-org

安裝了所有相關(guān)服務(wù)。

......
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
數(shù)據(jù)文件在:/var/lib/mongo
日志文件在:/var/log/mongodb
mongodb服務(wù)使用

#啟動(dòng)
service mongod start
#停止
service mongod stop
#重啟
service mongod restart
#增加開(kāi)機(jī)啟動(dòng)
chkconfig mongod on

2,MongoDB CRUD

連接到MongoDB,很簡(jiǎn)單,執(zhí)行mongo就可以了。

# mongo
MongoDB shell version: 3.0.2
connecting to: test
Welcome 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
Server 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 4096KB
2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          We suggest setting it to 256KB (512 sectors) or less
2015-04-29T18:03:17.544+0800 I STORAGE  [initandlisten] **          http://dochub.mongodb.org/core/readahead
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/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,創(chuàng)建數(shù)據(jù):

http://docs.mongodb.org/manual/tutorial/insert-documents/
http://docs.mongodb.org/manual/reference/method/db.collection.insert/

> 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 })

數(shù)據(jù)可以沒(méi)有主鍵_id,如果沒(méi)有,會(huì)自動(dòng)生成一個(gè)。如果設(shè)置了_id主鍵,就必須不重復(fù)。
否則報(bào)主鍵沖突:“E11000 duplicate key error index: test.users.$_id_ dup key: { : 1.0 }”

2.2,更新數(shù)據(jù):

http://docs.mongodb.org/manual/tutorial/modify-documents/

> 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 },則表示沒(méi)有查詢到數(shù)據(jù)直接插入。

2.3,刪除:

http://docs.mongodb.org/manual/tutorial/remove-documents/

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

查詢到數(shù)據(jù)才進(jìn)行刪除,并且返回刪除數(shù)量。

2.4,查詢:

http://docs.mongodb.org/manual/tutorial/query-documents/

> 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" }
#查詢?nèi)繑?shù)據(jù)
> 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可視化工具

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

port=27017

dbpath=/var/lib/mongo

# location of pidfile
pidfilepath=/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

4,總結(jié)

MongoDB 3.0操作起來(lái)還是很方便的。能高效的使用。
同時(shí)MongoDB擴(kuò)展也很方便。接下來(lái)研究。
對(duì)應(yīng)互聯(lián)網(wǎng)業(yè)務(wù)來(lái)說(shuō)沒(méi)有復(fù)雜的join查詢。只追求高效,快速訪問(wèn)。


標(biāo)題名稱:CentOS7安裝MongoDB3.0服務(wù)
鏈接地址:http://www.5511xx.com/article/cdhdepp.html