티스토리 뷰

728x90


1. Install MongoDB on all the servers that will be part of the replica set. 

You can do this by following the instructions provided in the MongoDB documentation for your Ubuntu version.


2. Once MongoDB is installed, create a directory for the data files and a directory for the log files on each server. 

For example, you could create a data directory at /data/db and a log directory at /var/log/mongodb.


3. Create a configuration file for each MongoDB instance that will be part of the replica set. 

You can do this by creating a file at /etc/mongodb.conf with the following contents:

dbpath=/data/db
logpath=/var/log/mongodb/mongodb.log
logappend=true
bind_ip=your_ip_address
port=27017
fork=true
replSet=your_replica_set_name

Replace your_ip_address with the IP address of the server, and your_replica_set_name with the name 

you want to give to your replica set.

 

4. Start the MongoDB instances using the following command:

sudo service mongodb start

 

5. Log in to one of the MongoDB instances and initiate the replica set using the following command:

mongo
rs.initiate()

6. Add the other MongoDB instances to the replica set by running the following command on each instance:

mongo
rs.add("ip_address:port")

Replace ip_address with the IP address of the server and port with the port number on which MongoDB is running.

 

 

7. Verify that the replica set is working by running the following command on any of the instances:

mongo
rs.status()

This should show the status of the replica set and the name of the primary node.

That's it! Your MongoDB replica set is now configured and ready to use.

728x90
댓글
250x250
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/07   »
1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31
글 보관함