|
# 建立超级用户admin use admin
db.createUser(
{
user: 'admin',
pwd: '@admin',
roles: [ { role: 'root', db: 'admin' } ]
}
);
# 建立app数据库的管理员app
use app
db.createUser(
{
user: 'app',
pwd: '@app',
roles: [ { role: 'dbOwner', db: 'app' } ]
}
);
# 认证登录
db.auth('admin', '@admin')
# 增加secondary
rs.add('10.0.70.102:27017')
rs.add('10.0.70.103:27017')
# 查看配置
rs.conf()
{
"_id" : "myapp",
"version" : 3,
"protocolVersion" : NumberLong(1),
"members" : [
{
"_id" : 0,
"host" : "10.0.70.101:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 1,
"host" : "10.0.70.102:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
},
{
"_id" : 2,
"host" : "10.0.70.103:27017",
"arbiterOnly" : false,
"buildIndexes" : true,
"hidden" : false,
"priority" : 1,
"tags" : {
},
"slaveDelay" : NumberLong(0),
"votes" : 1
}
],
"settings" : {
"chainingAllowed" : true,
"heartbeatIntervalMillis" : 2000,
"heartbeatTimeoutSecs" : 10,
"electionTimeoutMillis" : 10000,
"catchUpTimeoutMillis" : 2000,
"getLastErrorModes" : {
},
"getLastErrorDefaults" : {
"w" : 1,
"wtimeout" : 0
},
"replicaSetId" : ObjectId("59248e52d45510744805fb78")
}
}
# 查看状态
rs.status()
{
"set" : "myapp",
"date" : ISODate("2017-05-23T20:37:08.946Z"),
"myState" : 1,
"term" : NumberLong(1),
"heartbeatIntervalMillis" : NumberLong(2000),
"optimes" : {
"lastCommittedOpTime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"appliedOpTime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"durableOpTime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
}
},
"members" : [
{
"_id" : 0,
"name" : "10.0.70.101:27017",
"health" : 1,
"state" : 1,
"stateStr" : "PRIMARY",
"uptime" : 4968,
"optime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2017-05-23T20:37:07Z"),
"electionTime" : Timestamp(1495567955, 2),
"electionDate" : ISODate("2017-05-23T19:32:35Z"),
"configVersion" : 3,
"self" : true
},
{
"_id" : 1,
"name" : "10.0.70.102:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 77,
"optime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2017-05-23T20:37:07Z"),
"optimeDurableDate" : ISODate("2017-05-23T20:37:07Z"),
"lastHeartbeat" : ISODate("2017-05-23T20:37:07.702Z"),
"lastHeartbeatRecv" : ISODate("2017-05-23T20:37:06.951Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.0.70.103:27017",
"configVersion" : 3
},
{
"_id" : 2,
"name" : "10.0.70.103:27017",
"health" : 1,
"state" : 2,
"stateStr" : "SECONDARY",
"uptime" : 77,
"optime" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"optimeDurable" : {
"ts" : Timestamp(1495571827, 1),
"t" : NumberLong(1)
},
"optimeDate" : ISODate("2017-05-23T20:37:07Z"),
"optimeDurableDate" : ISODate("2017-05-23T20:37:07Z"),
"lastHeartbeat" : ISODate("2017-05-23T20:37:07.708Z"),
"lastHeartbeatRecv" : ISODate("2017-05-23T20:37:07.733Z"),
"pingMs" : NumberLong(0),
"syncingTo" : "10.0.70.101:27017",
"configVersion" : 3
}
],
"ok" : 1
} |
|