Advertisement
nguyenhappy92

MongoDB Replication on CentOS 7

Sep 2nd, 2019
1,796
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.55 KB | None | 0 0
  1. I. Mongo 1
  2. IP: 192.168.111.142
  3. yum install epel-release -y
  4. yum update -y
  5. vi /etc/hosts
  6. 192.168.111.142 mongo01
  7. 192.168.111.143 mongo02
  8. 192.168.111.144 mongo03
  9. setenfore 0
  10. sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  11. vi /etc/yum.repos.d/mongodb-org-4.2.repo
  12. [mongodb-org-4.2]
  13. name=MongoDB Repository
  14. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
  15. gpgcheck=1
  16. enabled=1
  17. gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
  18. yum install -y mongodb-org
  19. openssl rand -base64 756 > mongo.key
  20. mkdir /opt/mongo
  21. mv ~/mongo.key /opt/mongo
  22. scp /opt/mongo/mongo.key [email protected]:/opt/mongo/
  23. scp /opt/mongo/mongo.key [email protected]:/opt/mongo/
  24. chmod 400 /opt/mongo/mongo.key
  25. chown mongod:mongod /opt/mongo/mongo.key
  26. mongo
  27. use admin
  28. db.createUser({user: "happy", pwd: "TDAn94xB6Bw3uZmW", roles:[{role: "root", db: "admin"}]})
  29. vi /etc/mongod.conf
  30. net:
  31. port: 27017
  32. bindIp: 0.0.0.0
  33. security:
  34. keyFile: /opt/mongo/mongo.key
  35. replication:
  36. replSetName: happy
  37. firewall-cmd --permanent --add-port=27017/tcp
  38. firewall-cmd --reload
  39. systemctl restart mongod
  40. systemctl enable mongod
  41. mongo -u happy -p --authenticationDatabase admin
  42. rs.initiate()
  43. rs.add("mongo02")
  44. rs.addArb("mongo03")
  45. rs.conf()
  46. rs.status()
  47. rs.isMaster()
  48. mongo -u happy -p --authenticationDatabase admin
  49. use demo
  50. for (var i = 0; i <= 10; i++) db.exampleCollection.insert( { x : i } )
  51. II. Mongo 2
  52. IP: 192.168.111.143
  53. yum install epel-release -y
  54. yum update -y
  55. vi /etc/hosts
  56. 192.168.111.142 mongo01
  57. 192.168.111.143 mongo02
  58. 192.168.111.144 mongo03
  59. setenfore 0
  60. sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  61. vi /etc/yum.repos.d/mongodb-org-4.2.repo
  62. [mongodb-org-4.2]
  63. name=MongoDB Repository
  64. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
  65. gpgcheck=1
  66. enabled=1
  67. gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
  68. yum install -y mongodb-org
  69. mkdir /opt/mongo
  70. chmod 400 /opt/mongo/mongo.key
  71. chown mongod:mongod /opt/mongo/mongo.key
  72. mongo
  73. use admin
  74. db.createUser({user: "happy", pwd: "TDAn94xB6Bw3uZmW", roles:[{role: "root", db: "admin"}]})
  75. vi /etc/mongod.conf
  76. net:
  77. port: 27017
  78. bindIp: 0.0.0.0
  79. security:
  80. keyFile: /opt/mongo/mongo.key
  81. replication:
  82. replSetName: happy
  83. firewall-cmd --permanent --add-port=27017/tcp
  84. firewall-cmd --reload
  85. systemctl restart mongod
  86. systemctl enable mongod
  87. netstat -plntu
  88. mongo -u happy -p --authenticationDatabase admin
  89. db.getMongo().setSlaveOk()
  90. use demo
  91. db.exampleCollection.find()
  92. III. Mongo 3
  93. IP: 192.168.111.144
  94. yum install epel-release -y
  95. yum update -y
  96. vi /etc/hosts
  97. 192.168.111.142 mongo01
  98. 192.168.111.143 mongo02
  99. 192.168.111.144 mongo03
  100. setenfore 0
  101. sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=disabled/g' /etc/sysconfig/selinux
  102. vi /etc/yum.repos.d/mongodb-org-4.2.repo
  103. [mongodb-org-4.2]
  104. name=MongoDB Repository
  105. baseurl=https://repo.mongodb.org/yum/redhat/$releasever/mongodb-org/4.2/x86_64/
  106. gpgcheck=1
  107. enabled=1
  108. gpgkey=https://www.mongodb.org/static/pgp/server-4.2.asc
  109. yum install -y mongodb-org
  110. mkdir /opt/mongo
  111. chmod 400 /opt/mongo/mongo.key
  112. chown mongod:mongod /opt/mongo/mongo.key
  113. mongo
  114. use admin
  115. db.createUser({user: "happy", pwd: "TDAn94xB6Bw3uZmW", roles:[{role: "root", db: "admin"}]})
  116. vi /etc/mongod.conf
  117. net:
  118. port: 27017
  119. bindIp: 0.0.0.0
  120. security:
  121. keyFile: /opt/mongo/mongo.key
  122. replication:
  123. replSetName: happy
  124. firewall-cmd --permanent --add-port=27017/tcp
  125. firewall-cmd --reload
  126. systemctl restart mongod
  127. systemctl enable mongod
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement