溫馨提示×

溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊×
其他方式登錄
點(diǎn)擊 登錄注冊 即表示同意《億速云用戶服務(wù)條款》

MongoDB 安裝、主從配置、以及監(jiān)控

發(fā)布時間:2020-07-01 10:47:53 來源:網(wǎng)絡(luò) 閱讀:1007 作者:mrcto 欄目:MongoDB數(shù)據(jù)庫

1、安裝


#添加安裝源

[mongodb]
name=MongoDB Repository
baseurl=http://downloads-distro.mongodb.org/repo/redhat/os/x86_64/
gpgcheck=0
enabled=1
#yum 安裝
yum install -y mongo-10gen mongo-10gen-server

#添加到開機(jī)自動啟動

chkconfig mongod on

2、啟動,停止,重啟命令


service mongod start
service mongod stop
service mongod restart

3、測試


使用mongoperf 查看磁盤IO性能

#mongoperf -h

usage:
 mongoperf < myjsonconfigfile
{
  nThreads:<n>,   // number of threads (default 1)
  fileSizeMB:<n>,  // test file size (default 1MB)
  sleepMicros:<n>, // pause for sleepMicros/nThreads between each operation (default 0)
  mmf:<bool>,    // if true do i/o's via memory mapped files (default false)
  r:<bool>,     // do reads (default false)
  w:<bool>,     // do writes (default false)
  recSizeKB:<n>,  // size of each write (default 4KB)
  syncDelay:<n>   // secs between fsyncs, like --syncdelay in mongod. (default 0/never)
}

進(jìn)行測試:

[root@php1 ~]# cat <jsonfile

{
  nThreads:1,
  fileSizeMB:1,
  sleepMicros:0,
  mmf:'true',
  r:'true',
  w:'true',
  recSizeKB:4,
  syncDelay:0
 }

#參考Real world MongoDB benchmarks with benchRun

https://blog.serverdensity.com/real-world-mongodb-benchmarks-with-benchrun/

運(yùn)行mongo

#mongo

>db.foo.insert( { _id : 1 } )
>ops = [{ op :"findOne", ns :"test.foo", query : { _id : 1 } }, { op :"update", ns :"test.foo", query : { _id : 1 } , update : { $inc : { x : 1 } } } ]
[
{
"op":"findOne",
"ns":"test.foo",
"query": {
"_id": 1
}
},
{
"op":"update",
"ns":"test.foo",
"query": {
"_id": 1
},
"update": {
"$inc": {
"x": 1
}
}
}
]
>for( x = 1; x<=128; x*=2){
...   res = benchRun( { parallel : x ,
...            seconds : 5 ,
...            ops : ops
...           } )
...   print("threads: "+ x +"\t queries/sec: "+ res.query )
... }
threads: 1 queries/sec: 7886.8
threads: 2 queries/sec: 12786.2
threads: 4 queries/sec: 14891.2
threads: 8 queries/sec: 16361.2
threads: 16 queries/sec: 19811.6
threads: 32 queries/sec: 18343.8
threads: 64 queries/sec: 26470.4
threads: 128 queries/sec: 36110.4

4、主從配置


php1172.17.16.7
mysql1172.17.16.21

#兩個服務(wù)器修改hosts:

172.17.16.7 php1.domain.com

#主上添加配置:vim /etc/mongod.conf

master = true
source = php1.dapingmu.conf

#從上添加配置:

#vim /etc/mongod.conf

slave = true
source = php1.dapingmu.com

#查看主從,使用robomongo或直接在服務(wù)器上使用命令行工具

#主服務(wù)器上

#mongo

>use local
>db.slaves.find()
/* 0 */
{
  "_id" : ObjectId("526b44843f12574552e6ce48"),
  "config" : {
    "host" : "172.17.16.21:29025",
    "upgradeNeeded" : true
  },
  "ns" : "local.oplog.$main",
  "syncedTo" : Timestamp(1382870579, 1)
}

5、監(jiān)控管理


#mongostat

The mongostat utility provides a quick overview of the status of a currently running mongod or mongos instance. mongostat is functionally similar to the UNIX/Linux file system utility vmstat, but provides data regarding mongod and mongos instances.


#mongotop

mongotop provides a method to track the amount of time a MongoDB instance spends reading and writing data. mongotop provides statistics on a per-collection level. By default, mongotop returns values every second.


#mongodb連接管理客戶端robomongo

下載地址:www.robomongo.org


#MMS管理

管理地址:https://mms.mongodb.com

需要安裝pymongo并安裝mms agent

1、安裝Python 2.6+

2、安裝PyMongo

3、下載:mms-monitoring-agent

wget https://mms.mongodb.com/settings/mmsAgent/15f01bbee11f24c1c5b2b31fab30c406/mms-monitoring-agent-(MMS-Group-Name).tar.gz

4、解壓并運(yùn)行

$ nohup python agent.py >> /YOUR_LOG_DIRECTORY/agent.log 2>&1 &

5、添加一個Mongo Node

即可登錄MMS管理地址查看MongoDB 節(jié)點(diǎn)監(jiān)控信息圖表



向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI