Mongo quickly builds a replica set

first step:
Create 3 directories in the D:\MongoDB directory: conf (save the configuration folder), data (save the data folder), log (save the log folder)
Step 2:
Create rs1, rs2, and rs3 in the data folder respectively (save the data of the primary, secondary, and arbiter servers respectively)
third step:
Create rs1.conf, rs2.conf, rs3.conf configuration files in the conf folder
Contents of rs1:
  1. dbpath=D:\MongoDB\data\rs1
  2. logpath=D:\MongoDB\log\rs1.log
  3. journal=true
  4. port=40000
  5. replSet=rs0
Contents of rs2:
  1. dbpath=D:\MongoDB\data\rs2
  2. logpath=D:\MongoDB\log\rs2.log
  3. journal=true
  4. port=40001
  5. replSet=rs0
Contents of rs3:
  1. dbpath=D:\MongoDB\data\rs3
  2. logpath=D:\MongoDB\log\rs3.log
  3. journal=true
  4. port=40002
  5. replSet=rs0
the fourth step:
Start the mongod service with conf
The following 3 commands are executed in 3 command lines respectively
  1. mongod --config D:\MongoDB\conf\rs1.conf
  2. mongod --config D:\MongoDB\conf\rs2.conf
  3. mongod --config D:\MongoDB\conf\rs3.conf
the fifth step:
Login to 3 servers
The following 3 commands are executed in 3 command lines respectively
  1. mongo --port 40000
  2. mongo --port 40001
  3. mongo --port 40002
Step 6:
Execute the following commands in sequence on the client corresponding to port 40000
  1. rs.initiate()
  2. rs.conf()
  3. rs.add("DESKTOP-MNG19L3:40001")
  4. rs.addArb("DESKTOP-MNG19L3:40002")
  5. rs.status()
The result of running is as follows:
  1. > rs.initiate()
  2. {
  3. "info2":"no configuration specified. Using a default configuration for the set",
  4. "me":"DESKTOP-MNG19L3:40000",
  5. "ok":1
  6. }
  7. rs0:SECONDARY> rs.conf()
  8. {
  9. "_id":"rs0",
  10. "version":1,
  11. "protocolVersion":NumberLong(1),
  12. "members":[
  13. {
  14. "_id":0,
  15. "host":"DESKTOP-MNG19L3:40000",
  16. "arbiterOnly":false,
  17. "buildIndexes":true,
  18. "hidden":false,
  19. "priority":1,
  20. "tags":{
  21. },
  22. "slaveDelay":NumberLong(0),
  23. "votes":1
  24. }
  25. ],
  26. "settings":{
  27. "chainingAllowed":true,
  28. "heartbeatIntervalMillis":2000,
  29. "heartbeatTimeoutSecs":10,
  30. "electionTimeoutMillis":10000,
  31. "getLastErrorModes":{
  32. },
  33. "getLastErrorDefaults":{
  34. "w":1,
  35. "wtimeout":0
  36. },
  37. "replicaSetId":ObjectId("593ff0ff57e4befb6527fdac")
  38. }
  39. }
  40. rs0:PRIMARY> rs.add("DESKTOP-MNG19L3:40001")
  41. {"ok":1}
  42. rs0:PRIMARY> rs.addArb("DESKTOP-MNG19L3:40002")
  43. {"ok":1}
  44. rs0:PRIMARY> rs.status()
  45. {
  46. "set":"rs0",
  47. "date":ISODate("2017-06-13T14:05:34.257Z"),
  48. "myState":1,
  49. "term":NumberLong(1),
  50. "heartbeatIntervalMillis":NumberLong(2000),
  51. "members":[
  52. {
  53. "_id":0,
  54. "name":"DESKTOP-MNG19L3:40000",
  55. "health":1,
  56. "state":1,
  57. "stateStr":"PRIMARY",
  58. "uptime":484,
  59. "optime":{
  60. "ts":Timestamp(1497362727,1),
  61. "t":NumberLong(1)
  62. },
  63. "optimeDate":ISODate("2017-06-13T14:05:27Z"),
  64. "infoMessage":"could not find member to sync from",
  65. "electionTime":Timestamp(1497362687,2),
  66. "electionDate":ISODate("2017-06-13T14:04:47Z"),
  67. "configVersion":3,
  68. "self":true
  69. },
  70. {
  71. "_id":1,
  72. "name":"DESKTOP-MNG19L3:40001",
  73. "health":1,
  74. "state":2,
  75. "stateStr":"SECONDARY",
  76. "uptime":15,
  77. "optime":{
  78. "ts":Timestamp(1497362727,1),
  79. "t":NumberLong(1)
  80. },
  81. "optimeDate":ISODate("2017-06-13T14:05:27Z"),
  82. "lastHeartbeat":ISODate("2017-06-13T14:05:33.513Z"),
  83. "lastHeartbeatRecv":ISODate("2017-06-13T14:05:32.541Z"),
  84. "pingMs":NumberLong(1),
  85. "syncingTo":"DESKTOP-MNG19L3:40000",
  86. "configVersion":3
  87. },
  88. {
  89. "_id":2,
  90. "name":"DESKTOP-MNG19L3:40002",
  91. "health":1,
  92. "state":0,
  93. "stateStr":"STARTUP",
  94. "uptime":3,
  95. "lastHeartbeat":ISODate("2017-06-13T14:05:32.526Z"),
  96. "lastHeartbeatRecv":ISODate("2017-06-13T14:05:33.649Z"),
  97. "pingMs":NumberLong(1),
  98. "configVersion":-2
  99. }
  100. ],
  101. "ok":1
  102. }
  103. rs0:PRIMARY>
 

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=327040751&siteId=291194637