MongoDB Replicaset 설정
2021. 4. 14. 16:55ㆍmongodb
반응형
몽고디비 레플리카셋 설정을 알아보겠다.
1. mongodb 구조를 만든다.
$ mkdir mongodb $ cd mongodb $ mkdir conf $ mkdir data $ mkdir log $ mkdir pid |
2. conf를 설정해준다.
2-1 mongodb_replicaset 1번 설정을 해준다
$ cd conf $ vi mongod_00.conf storage: dbPath: /home/ubuntu/mongodb/data/rs0/ journal: enabled: true systemLog: destination: file logAppend: true path: /home/ubuntu/mongodb/log/rs0/mongod.log replication: replSetName: "rs0" net: port: 27010 bindIp: 0.0.0.0 processManagement: timeZoneInfo: /usr/share/zoneinfo |
728x90
2-1 mongodb_replicaset 2번 설정을 해준다
$ vi mongod_01.conf storage: dbPath: /home/ubuntu/mongodb/data/rs1/ journal: enabled: true systemLog: destination: file logAppend: true path: /home/ubuntu/mongodb/log/rs1/mongod.log replication: replSetName: "rs0" net: port: 27011 bindIp: 0.0.0.0 processManagement: timeZoneInfo: /usr/share/zoneinfo |
2-1 mongodb_replicaset 3번 설정을 해준다
$ vi mongod_01.conf storage: dbPath: /home/ubuntu/mongodb/data/rs2/ journal: enabled: true systemLog: destination: file logAppend: true path: /home/ubuntu/mongodb/log/rs2/mongod.log replication: replSetName: "rs0" net: port: 27012 bindIp: 0.0.0.0 processManagement: timeZoneInfo: /usr/share/zoneinfo |
3. 생성된 파일에 권한을 부여한다.
$ cd .. $ sudo chown -R mongodb:mongodb * |
반응형
3. 서비스를 등록한다.
cd /usr/lib/systemd/system |
3-1 mongodb_replicaset 1번 서비스 설정
$ vi mongodb_rs0.service [Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network-online.target Wants=network-online.target [Service] User=mongodb Group=mongodb EnvironmentFile=-/etc/default/mongod ExecStart=/usr/bin/mongod --config /home/ubuntu/mongodb/conf/mongod_00.conf PIDFile=/home/ubuntu/mongodb/pid/mongodb_rs0.pid # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false [Install] WantedBy=multi-user.target |
3-2 mongodb_replicaset 2번 서비스 설정
$ vi mongodb_rs1.service [Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network-online.target Wants=network-online.target [Service] User=mongodb Group=mongodb EnvironmentFile=-/etc/default/mongod ExecStart=/usr/bin/mongod --config /home/ubuntu/mongodb/conf/mongod_01.conf PIDFile=/home/ubuntu/mongodb/pid/mongodb_rs1.pid # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false [Install] WantedBy=multi-user.target |
3-3 mongodb_replicaset 3번 서비스 설정
$ vi mongodb_rs2.service [Unit] Description=MongoDB Database Server Documentation=https://docs.mongodb.org/manual After=network-online.target Wants=network-online.target [Service] User=mongodb Group=mongodb EnvironmentFile=-/etc/default/mongod ExecStart=/usr/bin/mongod --config /home/ubuntu/mongodb/conf/mongod_02.conf PIDFile=/home/ubuntu/mongodb/pid/mongodb_rs2.pid # file size LimitFSIZE=infinity # cpu time LimitCPU=infinity # virtual memory size LimitAS=infinity # open files LimitNOFILE=64000 # processes/threads LimitNPROC=64000 # locked memory LimitMEMLOCK=infinity # total threads (user+kernel) TasksMax=infinity TasksAccounting=false [Install] WantedBy=multi-user.target |
3-4 mongodb_replicaset 1,2,3번 서비스 등록
$ sudo systemctl enable mongodb_rs0.service $ sudo systemctl enable mongodb_rs1.service $ sudo systemctl enable mongodb_rs2.service |
4. 몽고디비 시작
$ sudo systemctl start mongodb_rs0 $ sudo systemctl start mongodb_rs1 $ sudo systemctl start mongodb_rs2 |
5. 몽고디비 replicaset으로 묶어주기
$ cd ~ $ mongo --port 27010 $ rsconf = {_id: "rs0", members: [{_id: 0, host: "localhost:27010"}, {_id: 1, host: "localhost:27011"}, {_id: 2, host: "localhost:27012"}]} $ rs.initiate(rsconf) |
이렇게 몽고디비를 설정하면, replicaset이 설정이 완료된다.
그대로 따라했다면 크게 문제가 없을 것이다.
그럼 샤드 설정에 대해 알아보겠다.
[샤드 설정]
반응형
'mongodb' 카테고리의 다른 글
mongodb shard 제거하기 ( remove ) (1) | 2021.04.22 |
---|---|
몽고디비(mongodb) 샤드(shard) 설정 (0) | 2021.04.19 |
MongoDB SQL Union All ($facet) 하는 방법 (0) | 2021.04.11 |
MongoDB 데이터 삭제 후, 용량 반환 방법 ( compact 명령어 ) (2) | 2021.04.09 |
Ubuntu MongoDB 설치 가이드 - (로그, 방화벽 관리 한번에) (0) | 2021.04.08 |