몽고디비 클러스터 구성하기 MongoDB Cluster Setup Guide
MongoDB Configuration
Unexpected issues with hosts or MongoDB instances can cause process failures or data loss.
To prepare for such situations, similar to other DBMS types, MongoDB should also use DB HA (High Availability) through replication configuration.
A group configured with replication is called a Replica Set. Furthermore, configuring multiple Replica Sets together for distributed query processing and easier scale-out is called a Sharded Cluster.
PSS / PSA
https://docs.mongodb.com/manual/replication/

(from ncloud MongoDB Cluster)
Setting Up a Cluster
Modifying the Configuration File
- If you haven’t modified the settings, MongoDB on Linux has its configuration values in /etc/mongod.conf by default
- Add and modify the following content in the configuration file
[IMPORTANT] Replica set configuration cannot be set when “security: enable” is active - replace with key later
# /etc/mongod.conf
replication:
replSetName: "mobidicSet"
- The configured replSetName must be applied identically to all RS (Replica Sets) you want to configure
- After applying the settings, you need to restart MongoDB
sudo systemctl stop mongod
sudo systemctl start mongod
sudo systemctl status mongod
TIPS
[When MongoDB clusters cannot communicate with each other]
- Check the EC2 inbound rules
- It’s easiest if the EC2 instances are in the same security group
- Both ICMP and TCP 27017 must be allowed
- As the saying goes “look before you leap” - verify with telnet or ping
[When MongoDB cluster won’t start properly]
- If /data/db is not created - solve with sudo mkdir /data/db
- If /data/db has no permissions - solve with sudo chown mongodb: /data/db
- If status is fail when checking with systemctl status mongod - the error reason is well displayed on the output screen
- If authorization issues occur, you didn’t read the content above carefully, so reflect on that, comment out the security section in /etc/mongod.conf, take a deep sigh, and try again
Configuring the Cluster
If the setup above is complete, you need to connect the Replica Set
-
Connect to mongo shell
mongo -
RS configuration
rs.initiate({ _id : "<Replica Set Name>", members : [ {_id : 0, host : "<BindIp>:<Port>"}, {_id : 1, host : "<BindIp>:<Port>"}, {_id : 2, host : "<BindIp>:<Port>"}, ] }) -
Write in the format above. Note that IP and PORT must all be enclosed in “” (double quotes)
ex)
rs.initiate({ _id : "mobidicSet", members : [ {_id : 0, host : "1.2.3.4:27017"}, {_id : 1, host : "3.2.1.4:27017"}, {_id : 2, host : "4.3.1.2:27017"}, ] }) -
Verify the result
If connected successfully, PRIMARY or SECONDARY will appear in the MongoDB shell
rs.status()
댓글남기기