Deploying MongoDB Replica sets in Docker

Source: Internet
Author: User
Tags locale mongodb docker ps docker run

1. Basic information as follows server address 192.168.73.129 replica set name RS container node and port mapping M0 37017:27017 M1 47017:27017 m2 57,017:27,017 Note: Machine Environment installation doc Ker2. Deployment Step 2.1 Download MONGO image

Docker pull Mongo

2.2 Starting three nodes
Docker run--name m0-p 37017:27017-d MONGO--replset "RS" Docker run--name m1-p 47017:27017-d MONGO--replset "RS" dock Er run--name m2-p 57017:27017-d MONGO--replset "RS"

Docker ps-a//View boot container

2.3 Connect any node for replica set configuration

Enter one of the containers: Docker exec-it De242cc5fa5a/bin/bash

Connect any one of the three nodes, note that the IP address is the host IP, my current 192.168.73.129

mongo --host 192.168.73.129 --port 37017

Now connected to the M0 node for replica set configuration

var config={     _id: "rs",     members:[         {_id:0,host: "192.168.73.129:37017"},         {_id:1,host: " 192.168.73.129:47017 "},         {_id:2,host:" 192.168.73.129:57017 "}]};rs.initiate (config)

The response should resemble the following, note that at this point the command prompt has changed from the original > into rs:secondary>

{    "OK": 1,    "Operationtime": Timestamp (1522810920, 1),    "$clusterTime": {        "clustertime": Timestamp ( 1522810920, 1),        "signature": {            "hash": Bindata (0, "aaaaaaaaaaaaaaaaaaaaaaaaaaa="),            "KeyId": Numberlong ( 0)}}}    
2.4 Viewing replica set configuration information
Rs:secondary> rs.conf () {"_id": "RS", "Version": 1, "ProtocolVersion": Numberlong (1), "Writeconcernmajor            Ityjournaldefault ": True," members ": [{" _id ": 0," host ":" 192.168.73.129:37017 ",            "Arbiteronly": false, "buildindexes": True, "hidden": false, "priority": 1,        "tags": {}, "Slavedelay": Numberlong (0), "votes": 1            }, {"_id": 1, "host": "192.168.73.129:47017", "arbiteronly": false,                            "Buildindexes": True, "hidden": false, "priority": 1, "tags": {            }, "Slavedelay": Numberlong (0), "votes": 1}, {"_id": 2, "Host": "192.168.73.129:57017", "arbiteronly": false, "buildindexes": true, "Hidde N ": false,"Priority ": 1," tags ": {}," Slavedelay ": Numberlong (0)," Vo        TES ": 1}]," settings ": {" chainingallowed ": True," Heartbeatintervalmillis ": 2000, "Heartbeattimeoutsecs": Ten, "Electiontimeoutmillis": 10000, "Catchuptimeoutmillis":-1, "Catchupt            Akeoverdelaymillis ": 30000," Getlasterrormodes ": {}," Getlasterrordefaults ": { "W": 1, "Wtimeout": 0}, "Replicasetid": ObjectId ("5b3c937896d237ac24a0648e")}}rs:sec  Ondary>
2.5 Viewing replica set status
Rs:secondary> Rs.status () {"Set": "RS", "Date": Isodate ("2018-07-04t09:45:38.110z"), "MyState": 2, "term ": Numberlong (1)," syncingto ":" 192.168.73.129:37017 "," Syncsourcehost ":" 192.168.73.129:37017 "," Syncsourceid ": 0," Heartbeatintervalmillis ": Numberlong (+)," Optimes ": {" Lastcommittedoptime ": {" TS " : Timestamp (1530697530, 1), "T": Numberlong (1)}, "Readconcernmajorityoptime": {"TS ": Timestamp (1530697530, 1)," T ": Numberlong (1)}," Appliedoptime ": {" ts ": timest AMP (1530697530, 1), "T": Numberlong (1)}, "Durableoptime": {"ts": Timestamp (153069    7530, 1), "T": Numberlong (1)}, "Laststablecheckpointtimestamp": Timestamp (1530697480, 1),            "Members": [{"_id": 0, "name": "192.168.73.129:37017", "Health": 1,         "State": 1,   "Statestr": "PRIMARY", "uptime": 967, "Optime": {"ts": Timestamp (1530697530, 1), "T": Numberlong (1)}, "Optimedurable": {"ts": Timestamp (153069            7530, 1), "T": Numberlong (1)}, "Optimedate": Isodate ("2018-07-04t09:45:30z"), "Optimedurabledate": Isodate ("2018-07-04t09:45:30z"), "Lastheartbeat": Isodate ("2018-07-04t09:45:36.22            1Z ")," Lastheartbeatrecv ": Isodate (" 2018-07-04t09:45:36.296z ")," Pingms ": Numberlong (0), "Lastheartbeatmessage": "", "Syncingto": "", "Syncsourcehost": "", "Syncsourceid": -1, "InfoMessage": "", "Electiontime": Timestamp (1530696579, 1), "electiondate": Isoda Te ("2018-07-04t09:29:39z"), "ConfigVersion": 1}, {"_id": 1, "name": "1   92.168.73.129:47017 ",         "Health": 1, "state": 2, "statestr": "Secondary", "uptime": 967, "Optime": {"ts": Timestamp (1530697530, 1), "T": Numberlong (1)}, "            Optimedurable ": {" ts ": Timestamp (1530697530, 1)," T ": Numberlong (1)},            "Optimedate": Isodate ("2018-07-04t09:45:30z"), "Optimedurabledate": Isodate ("2018-07-04t09:45:30z"), "Lastheartbeat": Isodate ("2018-07-04t09:45:36.221z"), "Lastheartbeatrecv": Isodate ("2018-07-04t09:45: 36.219Z ")," Pingms ": Numberlong (0)," lastheartbeatmessage ":" "," syncingto ":" 192.168. 73.129:37017 "," Syncsourcehost ":" 192.168.73.129:37017 "," Syncsourceid ": 0," Infomessag E ":" "," ConfigVersion ": 1}, {" _id ": 2," name ":" 192.168.73.129:57017 "," Health ": 1, "state": 2, "statestr": "Secondary", "uptime": 2153, "Optime": { "TS": Timestamp (1530697530, 1), "T": Numberlong (1)}, "Optimedate": ISOD Ate ("2018-07-04t09:45:30z"), "syncingto": "192.168.73.129:37017", "Syncsourcehost": "192.168.73.12 9:37017 "," Syncsourceid ": 0," InfoMessage ":" "," ConfigVersion ": 1," self "    : True, "lastheartbeatmessage": ""}], "OK": 1, "Operationtime": Timestamp (1530697530, 1), "$clusterTime": {"Clustertime": Timestamp (1530697530, 1), "signature": {"hash": Bindata (  0, "aaaaaaaaaaaaaaaaaaaaaaaaaaa="), "KeyId": Numberlong (0)}}}rs:secondary>
2.6 Client Tool Connection

Deploying MongoDB Replica sets in Docker

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.