mongodb - Replication Set搭建过程

1.创建目录

mkdir -p /mongodb/data/r1
mkdir -p /mongodb/data/r2
mkdir -p /mongodb/data/r3
mkdir -p /mongodb/mlog

2.启动三个实例,并声明实例属于复制集

./mongod --dbpath /mongodb/data/r1  --logpath /mongodb/mlog/r1.log --fork --port 27017 --replSet ybb --smallfiles
./mongod --dbpath /mongodb/data/r2  --logpath /mongodb/mlog/r2.log --fork --port 27018 --replSet ybb --smallfiles
./mongod --dbpath /mongodb/data/r3  --logpath /mongodb/mlog/r3.log --fork --port 27019 --replSet ybb --smallfiles

3.复制集初始化
这一步初始化的复制集只是包含当前节点

# ./mongo --port=27017
> rs.initiate()
{
        "info2" : "no configuration specified. Using a default configuration for the set",
        "me" : "cc.example.com:27017",
        "ok" : 1
}

4.验证复制集初始化配置

这一步初始化的复制集只是包含当前节点

ybb:OTHER> rs.conf()
{
        "_id" : "ybb",
        "version" : 1,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "cc.example.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                }
        }
}
ybb:PRIMARY> 

5.添加其它节点

ybb:PRIMARY> rs.add("cc.example.com:27018")rs.add("cc.example.com:27018")
{ "ok" : 1 }
ybb:PRIMARY> rs.add("cc.example.com:27019")rs.add("cc.example.com:27019")
{ "ok" : 1 }
ybb:PRIMARY> 

6.检查复制集的状态

ybb:PRIMARY> rs.status()rs.status()
{
        "set" : "ybb",
        "date" : ISODate("2016-03-15T05:26:06.682Z"),
        "myState" : 1,
        "term" : NumberLong(1),
        "heartbeatIntervalMillis" : NumberLong(2000),
        "members" : [
                {
                        "_id" : 0,
                        "name" : "cc.example.com:27017",
                        "health" : 1,
                        "state" : 1,
                        "stateStr" : "PRIMARY",
                        "uptime" : 482,
                        "optime" : {
                                "ts" : Timestamp(1458019522, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2016-03-15T05:25:22Z"),
                        "electionTime" : Timestamp(1458019202, 2),
                        "electionDate" : ISODate("2016-03-15T05:20:02Z"),
                        "configVersion" : 3,
                        "self" : true
                },
                {
                        "_id" : 1,
                        "name" : "cc.example.com:27018",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 47,
                        "optime" : {
                                "ts" : Timestamp(1458019522, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2016-03-15T05:25:22Z"),
                        "lastHeartbeat" : ISODate("2016-03-15T05:26:04.822Z"),
                        "lastHeartbeatRecv" : ISODate("2016-03-15T05:26:05.826Z"),
                        "pingMs" : NumberLong(0),
                        "syncingTo" : "cc.example.com:27017",
                        "configVersion" : 3
                },
                {
                        "_id" : 2,
                        "name" : "cc.example.com:27019",
                        "health" : 1,
                        "state" : 2,
                        "stateStr" : "SECONDARY",
                        "uptime" : 43,
                        "optime" : {
                                "ts" : Timestamp(1458019522, 1),
                                "t" : NumberLong(1)
                        },
                        "optimeDate" : ISODate("2016-03-15T05:25:22Z"),
                        "lastHeartbeat" : ISODate("2016-03-15T05:26:04.822Z"),
                        "lastHeartbeatRecv" : ISODate("2016-03-15T05:26:04.821Z"),
                        "pingMs" : NumberLong(0),
                        "configVersion" : 3
                }
        ],
        "ok" : 1
}
ybb:PRIMARY> 

7.查看复制集的最新配置

ybb:PRIMARY> rs.config();rs.config();
{
        "_id" : "ybb",
        "version" : 3,
        "protocolVersion" : NumberLong(1),
        "members" : [
                {
                        "_id" : 0,
                        "host" : "cc.example.com:27017",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 1,
                        "host" : "cc.example.com:27018",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                },
                {
                        "_id" : 2,
                        "host" : "cc.example.com:27019",
                        "arbiterOnly" : false,
                        "buildIndexes" : true,
                        "hidden" : false,
                        "priority" : 1,
                        "tags" : {

                        },
                        "slaveDelay" : NumberLong(0),
                        "votes" : 1
                }
        ],
        "settings" : {
                "chainingAllowed" : true,
                "heartbeatIntervalMillis" : 2000,
                "heartbeatTimeoutSecs" : 10,
                "electionTimeoutMillis" : 10000,
                "getLastErrorModes" : {

                },
                "getLastErrorDefaults" : {
                        "w" : 1,
                        "wtimeout" : 0
                }
        }
}
ybb:PRIMARY> 

 

转载于:https://www.cnblogs.com/abclife/p/5279234.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
为什么会这样[user_mongo@nosql01 replicaset]$ cd /opt [user_mongo@nosql01 opt]$ ll total 0 drwxr-xr-x. 3 root root 25 Mar 16 17:08 servers drwxr-xr-x. 2 root root 51 Mar 16 17:10 software [user_mongo@nosql01 opt]$ tar -zxvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/LICENSE-Community.txt: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/MPL-2 tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/MPL-2: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/README tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/README: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/THIRD-PARTY-NOTICES: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/install_compass: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongo: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongod: Cannot open: No such file or directory mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos tar: mongodb-linux-x86_64-rhel70-4.4.12: Cannot mkdir: Permission denied tar: mongodb-linux-x86_64-rhel70-4.4.12/bin/mongos: Cannot open: No such file or directory tar: Exiting with failure status due to previous errors [user_mongo@nosql01 opt]$ tar -zcvf /opt/software/mongodb-linux-x86_64-rhel70-4.4.12.tgz -C /opt/servers/mongodb_demo/replicaset/ tar: Cowardly refusing to create an empty archive Try `tar --help' or `tar --usage' for more information.
最新发布
06-01
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值