千家信息网

MongoDB 安装、主从配置、以及监控

发表于:2026-11-02 作者:千家信息网编辑
千家信息网最后更新 2026年11月02日,1、安装#添加安装源[mongodb]name=MongoDB Repositorybaseurl=http://downloads-distro.mongodb.org/repo/redhat/os
千家信息网最后更新 2026年11月02日MongoDB 安装、主从配置、以及监控

1、安装


#添加安装源

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

#添加到开机自动启动

chkconfig mongod on

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


service mongod startservice mongod stopservice 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.8threads: 2 queries/sec: 12786.2threads: 4 queries/sec: 14891.2threads: 8 queries/sec: 16361.2threads: 16 queries/sec: 19811.6threads: 32 queries/sec: 18343.8threads: 64 queries/sec: 26470.4threads: 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 = truesource = php1.dapingmu.conf

#从上添加配置:

#vim /etc/mongod.conf

slave = truesource = 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 节点监控信息图表



管理 配置 地址 服务器 服务 主从 监控 命令 测试 运行 两个 信息 图表 客户 客户端 工具 性能 磁盘 节点 参考 数据库的安全要保护哪些东西 数据库安全各自的含义是什么 生产安全数据库录入 数据库的安全性及管理 数据库安全策略包含哪些 海淀数据库安全审计系统 建立农村房屋安全信息数据库 易用的数据库客户端支持安全管理 连接数据库失败ssl安全错误 数据库的锁怎样保障安全 上海喔噻互联网科技有限公司 华服互联网科技怎么样 互联网科技巨头监管 互联网科技的 重庆科技学院互联网 重庆互联网医院沙龙医盟信息科技 南平创想时代互联网科技有限公司 晓花互联网科技有限公司网址 新兴科技互联网创新大赛颁奖典礼 未来五年的互联网科技 民营互联网公司国防科技 广州新华互联网科技学校电竞方面 北京市互联网新科技 宇信科技在杭州互联网排第几 上海互联网科技公司ppt 互联网风格科技公司名称 抖集互联网科技技术咨询 互联网科技手抄报图片 互联网科技的前景 互联网的科技体现在哪里 港股互联网科技股 青岛互联网科技公司 互联网未来科技 互联网科技公司需要的职位 元气玛特互联网科技公司是外包吗 互联网风格科技公司名称 同城互联网络科技 求路客互联网科技电话 米泉互联网科技专业怎么样 宁波允成互联网科技有限公司
0