博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MongoDB replSet
阅读量:5983 次
发布时间:2019-06-20

本文共 4425 字,大约阅读时间需要 14 分钟。

hot3.png

还是看官方文档吧!

新建目录# mkdir -p /data/rs0 /data/rs1 /data/rs2启动mongod replSet# ./bin/mongod --port 11100 --dbpath /data/rs0 --replSet fish  --smallfiles# ./bin/mongod --port 11101 --dbpath /data/rs1 --replSet fish  --smallfiles# ./bin/mongod --port 11102 --dbpath /data/rs2 --replSet fish  --smallfilesmongod replSet 报错Fri Nov 30 16:07:27 [rsStart] warning: getaddrinfo("lenovo11") failed: Name or service not knownFri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not knownFri Nov 30 16:07:27 [rsStart] trying to contact lenovo11:11100Fri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not knownFri Nov 30 16:07:27 [rsStart] couldn't connect to lenovo11:11100: couldn't connect to server lenovo11:11100Fri Nov 30 16:07:27 [rsStart] getaddrinfo("lenovo11") failed: Name or service not knownFri Nov 30 16:07:27 [rsStart] replSet can't get local.system.replset config from self or any seed (yet)# /usr/local/mongodb/bin/mongo localhost:11100> config = { _id: 'fish' ,members: [{_id:0,host:"127.0.0.1:11100"},{_id:1,host:"127.0.0.1:11101"},{_id:2,host:"127.0.0.1:11102}]}> rs.initiate(config){	"startupStatus" : 4,	"info" : "fish",	"errmsg" : "all members and seeds must be reachable to initiate set",           	"ok" : 0}> rs.status(){	"startupStatus" : 4,	"errmsg" : "can't currently get local.system.replset config from self or any seed (EMPTYUNREACHABLE)",	"ok" : 0}> rs.conf()null> db.getReplicationInfo(){ "errmsg" : "neither master/slave nor replica set replication detected" }*****************************************  解决  **********************************************问了公司一个高手,虽然有点不屑这种小问题,不过还是指出问题所在。“这就是DNS的问题,它找不到“lenovo11”这个机器对应的ip。”   ---> 原来是mongodb不能解析lenovo11.在/etc/hosts 添加一行:127.0.0.1   lenovo11[root@lenovo11 mongodb]# ./bin/mongo localhost:11100MongoDB shell version: 2.2.1connecting to: localhost:11100/test> config = { _id:'fish',members:[ {_id:0,host:'localhost:11100'}, {_id:1,host:'localhost:11101'}, {_id:2,host:'localhost:11102'}]}{	"_id" : "fish",	"members" : [		{			"_id" : 0,			"host" : "localhost:11100"		},		{			"_id" : 1,			"host" : "localhost:11101"		},		{			"_id" : 2,			"host" : "localhost:11102"		}	]}> rs.initiate(config){	"info" : "Config now saved locally.  Should come online in about a minute.",	"ok" : 1}> rs.status(){	"set" : "fish",	"date" : ISODate("2012-11-30T09:41:51Z"),	"myState" : 1,	"members" : [		{			"_id" : 0,			"name" : "localhost:11100",			"health" : 1,			"state" : 1,			"stateStr" : "PRIMARY",			"uptime" : 172,			"optime" : Timestamp(1354268446000, 1),			"optimeDate" : ISODate("2012-11-30T09:40:46Z"),			"self" : true		},		{			"_id" : 1,			"name" : "localhost:11101",			"health" : 1,			"state" : 2,			"stateStr" : "SECONDARY",			"uptime" : 55,			"optime" : Timestamp(1354268446000, 1),			"optimeDate" : ISODate("2012-11-30T09:40:46Z"),			"lastHeartbeat" : ISODate("2012-11-30T09:41:50Z"),			"pingMs" : 1,			"errmsg" : "syncing to: localhost:11100"		},		{			"_id" : 2,			"name" : "localhost:11102",			"health" : 1,			"state" : 3,			"stateStr" : "RECOVERING",			"uptime" : 55,			"optime" : Timestamp(0, 0),			"optimeDate" : ISODate("1970-01-01T00:00:00Z"),			"lastHeartbeat" : ISODate("2012-11-30T09:41:49Z"),			"pingMs" : 207		}	],	"ok" : 1}fish:PRIMARY> rs.confrs.conf(    rs.config(fish:PRIMARY> rs.conf(){	"_id" : "fish",	"version" : 1,	"members" : [		{			"_id" : 0,			"host" : "localhost:11100"		},		{			"_id" : 1,			"host" : "localhost:11101"		},		{			"_id" : 2,			"host" : "localhost:11102"		}	]}fish:PRIMARY> rs.rs.add(                   rs.constructor            rs.isMaster(              rs.status(rs.addArb(                rs.debug                  rs.propertyIsEnumerable(  rs.stepDown(rs.apply(                 rs.freeze(                rs.prototype              rs.syncFrom(rs.call(                  rs.hasOwnProperty(        rs.reconfig(              rs.toLocaleString(rs.conf(                  rs.help(                  rs.remove(                rs.toString(rs.config(                rs.initiate(              rs.slaveOk(               rs.valueOf(fish:PRIMARY> rs.isMaster(){	"setName" : "fish",	"ismaster" : true,	"secondary" : false,	"hosts" : [		"localhost:11100",		"localhost:11102",		"localhost:11101"	],	"primary" : "localhost:11100",	"me" : "localhost:11100",	"maxBsonObjectSize" : 16777216,	"localTime" : ISODate("2012-11-30T09:45:59.351Z"),	"ok" : 1}

转载于:https://my.oschina.net/shineyyl/blog/92973

你可能感兴趣的文章
Algorithm | Random
查看>>
十二道MR习题 - 3 - 交集并集差集
查看>>
scala学习手记11 - 类定义
查看>>
Javascript——DOM学习笔记
查看>>
mongodb- 主从复制
查看>>
[ZJOI2010]排列计数
查看>>
C语言难点2之预处理器
查看>>
人月神话阅读笔记01
查看>>
用Ueditor存入数据库带HTML标签的文本,从数据库取出来后,anjular用ng-bind-html处理带HTML标签的文本...
查看>>
SVN入门
查看>>
【spring data jpa】jpa实现update操作 字段有值就更新,没值就用原来的
查看>>
express-session
查看>>
Docker - 容器互联
查看>>
java中的clone
查看>>
陶教授,我记不住定理的证明该怎么办?(我看到陶哲轩在博客上与学生一则有意思的互动,就翻译过来了)...
查看>>
Spring容器关于继承的应用案例
查看>>
TXT导入数据到SQL
查看>>
单元格内数字复制和递增
查看>>
通过组策略实现客户端注册证书
查看>>
如何根据IP查找计算机名
查看>>