MongoDB 安装、主从配置、以及监控
admin
2023-04-13 19:41:45
0

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

#添加到开机自动启动

chkconfig mongod on

2、启动,停止,重启命令


service mongod start
service mongod stop
service mongod restart

3、测试


使用mongoperf 查看磁盘IO性能

#mongoperf -h

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

进行测试:

[root@php1 ~]# cat

{
  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/

运行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

#两个服务器修改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或直接在服务器上使用命令行工具

#主服务器上

#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、监控管理


#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、解压并运行

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

5、添加一个Mongo Node

即可登录MMS管理地址查看MongoDB 节点监控信息图表



相关内容

热门资讯

徐巧芯剖析赖清德:最怕自己丢掉... 海峡导报综合报道 大罢免投票一周年纪念活动26日举行,台北市长蒋万安出席并怒轰,民进党一年过后仍没有...
中国红十字会总会紧急向广东调拨... 记者从中国红十字会总会了解到,针对台风“红霞”给广东造成的灾情,中国红十字会总会启动四级应急响应,紧...
这些少年,正被“毒蛋”围猎 李梦抽了几口电子烟,吐出了白色的烟雾,有一股浓烈的水果香味。随后,她看着自己握电子烟的手,跟身边人说...
蒋万安号召“倒阁”,卢秀燕认为... 海峡导报综合报道 台北市长蒋万安27日抛出震撼议题,表示多名民代向他提议推动“倒阁”,要求台行政机构...
特朗普将在白宫会见两位重要客人 俄乌战争仍未结束,美伊冲突又有升级风险。在此背景下,美国总统特朗普将在白宫接见乌克兰和以色列领导人。...
新租客打扫卧室柜子上掉落4万元... 近日,莲前西路某小区内,张倩签下一套房子的租赁合同。当天上午,她带着12岁的大女儿周馨怡和11岁的小...
六部门通告:禁止涉军队退役报废... 关于禁止涉军队退役报废装备销售活动的通告近年来,部分经营者在线上线下公开销售涉及我军退役报废装备(指...
九寨沟景区发生泥石流,部分道路... 7月26日,九寨沟风景名胜区管理局发布泥石流灾害通报:2026年7月26日15时50分,九寨沟景区局...
空调26度不凉是什么原因 从空调内部元器件来说,不凉的原因有可能是温度传感器出现故障了,也有可能是空调压缩机或者铜管出现问题,...
鲸鸿动能携手香港国际机场、鸿蒙...   2026 年 7 月 25 日,十余位鸿蒙车主组成的车队从珠海出发,经港珠澳大桥通关抵达香港国际...