单机主从模式

1:启动master

[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data --port 10000 --master
2014-09-05T15:11:50.115+0800 [initandlisten] MongoDB starting : pid=23623 port=10000 dbpath=/home/jifeng/mongodb-linux-x86_64-2.6.4/data master=1 64-bit host=jifeng04
2014-09-05T15:11:50.116+0800 [initandlisten] db version v2.6.4
2014-09-05T15:11:50.116+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15:11:50.117+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T15:11:50.117+0800 [initandlisten] allocator: tcmalloc
2014-09-05T15:11:50.117+0800 [initandlisten] options: { master: true, net: { port: 10000 }, storage: { dbPath: "/home/jifeng/mongodb-linux-x86_64-2.6.4/data" } }
2014-09-05T15:11:50.127+0800 [initandlisten] journal dir=/home/jifeng/mongodb-linux-x86_64-2.6.4/data/journal
2014-09-05T15:11:50.127+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-09-05T15:11:50.298+0800 [initandlisten] waiting for connections on port 10000

2:启动slave

[jifeng@jifeng04 ~]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data2 --port 10001 --slave --source localhost:10000
2014-09-05T15:12:48.411+0800 [initandlisten] MongoDB starting : pid=23636 port=10001 dbpath=/home/jifeng/mongodb-linux-x86_64-2.6.4/data2 slave=1 64-bit host=jifeng04
2014-09-05T15:12:48.412+0800 [initandlisten] db version v2.6.4
2014-09-05T15:12:48.412+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T15:12:48.412+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T15:12:48.412+0800 [initandlisten] allocator: tcmalloc
2014-09-05T15:12:48.413+0800 [initandlisten] options: { net: { port: 10001 }, slave: true, source: "localhost:10000", storage: { dbPath: "/home/jifeng/mongodb-linux-x86_64-2.6.4/data2" } }
2014-09-05T15:12:48.417+0800 [initandlisten] journal dir=/home/jifeng/mongodb-linux-x86_64-2.6.4/data2/journal
2014-09-05T15:12:48.417+0800 [initandlisten] recover : no journal files present, no recovery needed
2014-09-05T15:12:48.434+0800 [initandlisten] waiting for connections on port 10001
2014-09-05T15:12:49.438+0800 [replslave] repl: syncing from host:localhost:10000
2014-09-05T15:13:48.454+0800 [clientcursormon] mem (MB) res:51 virt:584
2014-09-05T15:13:48.454+0800 [clientcursormon]  mapped (incl journal view):320
2014-09-05T15:13:48.454+0800 [clientcursormon]  connections:0
2014-09-05T15:14:04.315+0800 [replslave] repl:   checkpoint applied 285 operations
2014-09-05T15:14:04.316+0800 [replslave] repl:   syncedTo: Sep  5 15:13:54 540962b2:1

3:显示数据

[jifeng@jifeng04 ~]$ mongo localhost:10000
MongoDB shell version: 2.6.4
connecting to: localhost:10000/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
> 

[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongo localhost:10001
MongoDB shell version: 2.6.4
connecting to: localhost:10001/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }

4:主写数据

> db.master.insert({uid:1004})
WriteResult({ "nInserted" : 1 })
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
{ "_id" : ObjectId("5409638c0a6617467df195ec"), "uid" : 1004 }
> 

从查询数据

[jifeng@jifeng04 ~]$ cd mongodb-linux-x86_64-2.6.4
[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongo localhost:10001
MongoDB shell version: 2.6.4
connecting to: localhost:10001/test
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
> db.master.find()
{ "_id" : ObjectId("540942bed89f094a5fbd9b5a"), "uid" : 1000 }
{ "_id" : ObjectId("540946bcd89f094a5fbd9b5b"), "uid" : 1001 }
{ "_id" : ObjectId("540956b7789903d8baf6b1b3"), "uid" : 1002 }
{ "_id" : ObjectId("5409638c0a6617467df195ec"), "uid" : 1004 }
> 

从机日志

2014-09-05T15:15:48.791+0800 [initandlisten] connection accepted from 127.0.0.1:35622 #1 (1 connection now open)
2014-09-05T15:16:34.336+0800 [replslave] repl:   checkpoint applied 15 operations
2014-09-05T15:16:34.336+0800 [replslave] repl:   syncedTo: Sep  5 15:16:24 54096348:1
2014-09-05T15:18:48.556+0800 [clientcursormon] mem (MB) res:36 virt:585
2014-09-05T15:18:48.556+0800 [clientcursormon]  mapped (incl journal view):320
2014-09-05T15:18:48.556+0800 [clientcursormon]  connections:1
2014-09-05T15:18:54.357+0800 [replslave] repl:   checkpoint applied 15 operations
2014-09-05T15:18:54.358+0800 [replslave] repl:   syncedTo: Sep  5 15:18:44 540963d4:1

关闭MongoDB :

方法一:

[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongod  --shutdown  --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data
killing process with pid: 22745
方法二:
<pre name="code" class="html"><pre name="code" class="html">[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongo localhost:10000
MongoDB shell version: 2.6.4
connecting to: localhost:10001/test
> use admin;
switched to db admin
> db.shutdownServer();
2014-09-05T15:23:59.910+0800 DBClientCursor::init call() failed
server should be down...
2014-09-05T15:23:59.912+0800 trying reconnect to localhost:10000 (127.0.0.1) failed
2014-09-05T15:23:59.915+0800 warning: Failed to connect to 127.0.0.1:10000, reason: errno:111 Connection refused
2014-09-05T15:23:59.915+0800 reconnect localhost:10000 (127.0.0.1) failed failed couldn't connect to server localhost:10000 (127.0.0.1), connection attempt failed
> exit;
[jifeng@jifeng04 ~]$ 

多机主从模式:

[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mkdir log
[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data --master --rest --nojournal --fork --logpath /home/jifeng/mongodb-linux-x86_64-2.6.4/log
2014-09-05T10:31:44.158+0800 ** WARNING: --rest is specified without --httpinterface,
2014-09-05T10:31:44.172+0800 **          enabling http interface
about to fork child process, waiting until server is ready for connections.
forked process: 22535
ERROR: child process failed, exited with error number 1

报错,发现日志文件不存在

[jifeng@jifeng04 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data --master --rest --nojournal --fork --logpath /home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log
2014-09-05T16:12:09.321+0800 ** WARNING: --rest is specified without --httpinterface,
2014-09-05T16:12:09.322+0800 **          enabling http interface
about to fork child process, waiting until server is ready for connections.
forked process: 24061
child process started successfully, parent exiting

启动成功,rest有问题

2:启动slave

[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data   --slave --source jifeng04:27017 --rest --nojournal --fork --logpath /home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log
2014-09-05T16:13:57.872+0800 ** WARNING: --rest is specified without --httpinterface,
2014-09-05T16:13:57.872+0800 **          enabling http interface
about to fork child process, waiting until server is ready for connections.
forked process: 2787
child process started successfully, parent exiting
[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ cat log/mongod.log
2014-09-05T16:13:57.883+0800 [initandlisten] MongoDB starting : pid=2787 port=27017 dbpath=/home/jifeng/mongodb-linux-x86_64-2.6.4/data slave=1 64-bit host=jifeng05
2014-09-05T16:13:57.883+0800 [initandlisten] db version v2.6.4
2014-09-05T16:13:57.883+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T16:13:57.883+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T16:13:57.883+0800 [initandlisten] allocator: tcmalloc
2014-09-05T16:13:57.883+0800 [initandlisten] options: { net: { http: { RESTInterfaceEnabled: true, enabled: true } }, processManagement: { fork: true }, slave: true, source: "jifeng04:27017", storage: { dbPath: "/home/jifeng/mongodb-linux-x86_64-2.6.4/data", journal: { enabled: false } }, systemLog: { destination: "file", path: "/home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log" } }
2014-09-05T16:13:57.929+0800 [initandlisten] waiting for connections on port 27017
2014-09-05T16:13:57.929+0800 [websvr] admin web console waiting for connections on port 28017
2014-09-05T16:13:58.929+0800 [replslave] repl: --source jifeng04:27017 != jifeng04 from local.sources collection
2014-09-05T16:13:58.929+0800 [replslave] repl: for instructions on changing this slave's source, see:
2014-09-05T16:13:58.929+0800 [replslave] http://dochub.mongodb.org/core/masterslave
2014-09-05T16:13:58.929+0800 [replslave] repl: terminating mongod after 30 seconds

错误提示: repl: --source jifeng04:27017 != jifeng04 from local.sources collection

[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data   --slave --source 10.5.4.57:27017 --rest --nojournal --fork --logpath /home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log
2014-09-05T16:15:59.408+0800 ** WARNING: --rest is specified without --httpinterface,
2014-09-05T16:15:59.408+0800 **          enabling http interface
about to fork child process, waiting until server is ready for connections.
forked process: 2809
child process started successfully, parent exiting
[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ cat log/mongod.log
2014-09-05T16:15:59.415+0800 [initandlisten] MongoDB starting : pid=2809 port=27017 dbpath=/home/jifeng/mongodb-linux-x86_64-2.6.4/data slave=1 64-bit host=jifeng05
2014-09-05T16:15:59.415+0800 [initandlisten] db version v2.6.4
2014-09-05T16:15:59.415+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T16:15:59.415+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T16:15:59.415+0800 [initandlisten] allocator: tcmalloc
2014-09-05T16:15:59.415+0800 [initandlisten] options: { net: { http: { RESTInterfaceEnabled: true, enabled: true } }, processManagement: { fork: true }, slave: true, source: "10.5.4.57:27017", storage: { dbPath: "/home/jifeng/mongodb-linux-x86_64-2.6.4/data", journal: { enabled: false } }, systemLog: { destination: "file", path: "/home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log" } }
2014-09-05T16:15:59.447+0800 [initandlisten] waiting for connections on port 27017
2014-09-05T16:15:59.449+0800 [websvr] admin web console waiting for connections on port 28017
2014-09-05T16:16:00.449+0800 [replslave] repl: --source 10.5.4.57:27017 != jifeng04 from local.sources collection
2014-09-05T16:16:00.449+0800 [replslave] repl: for instructions on changing this slave's source, see:
2014-09-05T16:16:00.449+0800 [replslave] http://dochub.mongodb.org/core/masterslave
2014-09-05T16:16:00.449+0800 [replslave] repl: terminating mongod after 30 seconds
[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ 

 错误提示:repl: --source 10.5.4.57:27017 != jifeng04 from local.sources collection


[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ mongod --dbpath /home/jifeng/mongodb-linux-x86_64-2.6.4/data   --slave --source jifeng04 --rest --nojournal --fork --logpath /home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log
2014-09-05T16:19:02.564+0800 ** WARNING: --rest is specified without --httpinterface,
2014-09-05T16:19:02.564+0800 **          enabling http interface
about to fork child process, waiting until server is ready for connections.
forked process: 2832
child process started successfully, parent exiting
[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ cat log/mongod.log
2014-09-05T16:19:02.575+0800 [initandlisten] MongoDB starting : pid=2832 port=27017 dbpath=/home/jifeng/mongodb-linux-x86_64-2.6.4/data slave=1 64-bit host=jifeng05
2014-09-05T16:19:02.575+0800 [initandlisten] db version v2.6.4
2014-09-05T16:19:02.575+0800 [initandlisten] git version: 3a830be0eb92d772aa855ebb711ac91d658ee910
2014-09-05T16:19:02.575+0800 [initandlisten] build info: Linux build7.nj1.10gen.cc 2.6.32-431.3.1.el6.x86_64 #1 SMP Fri Jan 3 21:39:27 UTC 2014 x86_64 BOOST_LIB_VERSION=1_49
2014-09-05T16:19:02.575+0800 [initandlisten] allocator: tcmalloc
2014-09-05T16:19:02.575+0800 [initandlisten] options: { net: { http: { RESTInterfaceEnabled: true, enabled: true } }, processManagement: { fork: true }, slave: true, source: "jifeng04", storage: { dbPath: "/home/jifeng/mongodb-linux-x86_64-2.6.4/data", journal: { enabled: false } }, systemLog: { destination: "file", path: "/home/jifeng/mongodb-linux-x86_64-2.6.4/log/mongod.log" } }
2014-09-05T16:19:02.608+0800 [initandlisten] waiting for connections on port 27017
2014-09-05T16:19:02.610+0800 [websvr] admin web console waiting for connections on port 28017
2014-09-05T16:19:03.612+0800 [replslave] repl: syncing from host:jifeng04
2014-09-05T16:19:03.613+0800 [replslave] warning: Failed to connect to 10.5.4.57:27017, reason: errno:113 No route to host
2014-09-05T16:19:03.613+0800 [replslave] repl: couldn't connect to server jifeng04:27017 (10.5.4.57), connection attempt failed
2014-09-05T16:19:03.613+0800 [replslave] repl: sleep 3 sec before next pass
[jifeng@jifeng05 mongodb-linux-x86_64-2.6.4]$ 

 错误提示:warning: Failed to connect to 10.5.4.57:27017, reason: errno:113 No route to host

连接不上

MongoDB 2.6.4 主从同步相关推荐

  1. MongoDB配置主从同步(二)

    配置MongoDB 主从同步 主:命令行启动方式 /usr/local/mongodb/bin/mongod --bind_ip 192.168.137.12 --port 27017 --dbpat ...

  2. 重启mysql主从同步mongodb(tungsten-replicator)

    1. 连接mysql mysql -uroot -p;(mysql从库) 输入数据库密码 2. 停止主同步 mysql> stop slave; 3. 清数据 将mongo库数据清空 4. 杀主 ...

  3. Redis如何实现分布式锁延时队列以及限流应用丨Redis源码原理|跳表|B+树|分布式锁|中间件|主从同步|存储原理

    Redis如何实现分布式锁延时队列以及限流应用 视频讲解如下,点击观看: Redis如何实现分布式锁延时队列以及限流应用丨Redis源码原理|跳表|B+树|分布式锁|中间件|主从同步|存储原理|数据模 ...

  4. 深度解析串行并发并行,开发人员需彻底搞懂丨mysql|redis|skynet|协程|索引|读写分离|分布式锁|主从同步

    深度解析串行并发并行,开发人员需彻底搞懂 视频讲解如下,点击观看: 深度解析串行并发并行,开发人员需彻底搞懂丨mysql|redis|skynet|协程|索引|读写分离|分布式锁|主从同步丨C/C++ ...

  5. Linux服务器开发,Reids源码 主从同步与对象模型

    ──────────────────────────────────────────────────────────────── ┌------------┐ │▉▉♥♥♥♥♥♥♥♥ 99% │ ♥❤ ...

  6. 使用MySQL Proxy解决MySQL主从同步延迟

    MySQL的主从同步机制非常方便的解决了高并发读的应用需求,给Web方 面开发带来了极大的便利.但这种方式有个比较大的缺陷在于MySQL的同步机制是依赖Slave主动向Master发请求来获取数据的, ...

  7. mysql 8.0配置主从同步_MySQL8.0.19开启GTID主从同步CentOS8

    前言本次搭建目标为1主2从MySQL主从同步结构.采用CentOS8作为操作系统,IP为[10.0.0.211,10.0.0.212,10.0.0.213].MySQL版本为8.0.19,端口均采用3 ...

  8. Linux下的redis的持久化,主从同步及哨兵

    redis持久化 Redis是一种内存型数据库,一旦服务器进程退出,数据库的数据就会丢失, 为了解决这个问题,Redis提供了两种持久化的方案,将内存中的数据保存到磁盘中,避免数据的丢失. RDB持久 ...

  9. mysql数据库主从同步过程详述(三)

    续mysql数据库主从同步过程详述(二) 在此说明下:在最后试验过程中,当查看从库状态的时候,IO_Running显示为no,从error_log中看到如下报错提示: 120523  0:55:31 ...

最新文章

  1. 淘宝店、淘宝商城排名规则及流量提升培训教程
  2. Ubuntu创建opencv工程并显示一张图片
  3. linux下nginx编译安装
  4. KubeVela:标准化的云原生平台构建引擎
  5. 科技核心期刊目录_中医学2019年版中国科技核心期刊目录(附影响因子)
  6. oracle 表更新表,Oracle 更新表(另一张表)
  7. Tomcat设置cmd窗口的title属性
  8. JCG新年献礼,JHR-N825R给力上市
  9. testlink匹配mysql8_如何安装Testlink
  10. setTimeout 和 setInterval 的区别
  11. django 1.8 官方文档翻译: 1-2-4 编写你的第一个Django应用,第4部分
  12. 引入方式之行内样式表(CSS、HTML)
  13. Fluent Design System 设计语言元素
  14. 单片机支持EM4100和T5577两种ID门禁卡
  15. 关于MATLAB直方图的绘制及应用
  16. 计算机磁盘文件怎么加密,win10怎样对电脑硬盘文件进行加密 windows10给电脑硬盘文件加密教程...
  17. IEEE UV 2022 “Vision Meets Algae” 目标检测竞赛正式启动!
  18. 金蝶eas系统服务器连接,金蝶eas服务器连接设置
  19. DataGuard - 利用Cascaded Redo Log Destinations避免WAN稳定性问题
  20. 本地消息表(异步确保)

热门文章

  1. java jdk工具
  2. wp comments post.php,通过修改wp-comments-post.php 防wordpress垃圾(spam)评论 | 沉默过客
  3. java jdk 检测安装_JDK如何安装和配置环境变量以及检验是否成功安装JDK的方法
  4. ddr4服务器内存和普通内存_DDR4内存可以在普通电脑上使用吗?有影响吗?
  5. Mybatis源码解析之Mybatis初始化过程
  6. SVM支持向量机详解
  7. 四、Go语言复合数据类型(上)
  8. 一个想法:走向“纳什均衡”是普遍存在的大趋势
  9. 博士申请 | 约翰霍普金斯大学招收2022年入学trustworthy AI方向博士生
  10. 评测任务实战:中文文本分类技术实践与分享 - PaperWeekly 第49期