千家信息网

mongdb副本集部署

发表于:2025-01-23 作者:千家信息网编辑
千家信息网最后更新 2025年01月23日,两台机器1.在/etc/hosts文件中写上192.168.255.133 worker1192.168.255.134 worker22.修改配置文件/etc/mongdb.confbindIp:
千家信息网最后更新 2025年01月23日mongdb副本集部署

两台机器

1.在/etc/hosts文件中写上
192.168.255.133 worker1
192.168.255.134 worker2

2.修改配置文件/etc/mongdb.conf
bindIp: 0.0.0.0 #供所有机器访问
replication:
replSetName: rs # 给副本集取名字叫rs

3.启动
mongod

4.初始化副本集

rs.initiate()

5.添加成员节点

rs.add("worker2:27017")

rs.addArb("182.48.115.239:27017") #添加仲裁节点

6.进入mongodb shell中查看配置

>>> rs.conf()MongoDB Enterprise rs:PRIMARY> rs.conf(){        "_id" : "rs",        "version" : 2,        "protocolVersion" : NumberLong(1),        "writeConcernMajorityJournalDefault" : true,        "members" : [                {                        "_id" : 0,                        "host" : "worker1:27017",                        "arbiterOnly" : false,                        "buildIndexes" : true,                        "hidden" : false,                        "priority" : 1,                        "tags" : {                        },                        "slaveDelay" : NumberLong(0),                        "votes" : 1                },                {                        "_id" : 1,                        "host" : "worker2:27017",                        "arbiterOnly" : false,                        "buildIndexes" : true,                        "hidden" : false,                        "priority" : 1,                        "tags" : {                        },                        "slaveDelay" : NumberLong(0),                        "votes" : 1                }        ],        "settings" : {                "chainingAllowed" : true,                "heartbeatIntervalMillis" : 2000,                "heartbeatTimeoutSecs" : 10,                "electionTimeoutMillis" : 10000,                "catchUpTimeoutMillis" : -1,                "catchUpTakeoverDelayMillis" : 30000,                "getLastErrorModes" : {                },                "getLastErrorDefaults" : {                        "w" : 1,                        "wtimeout" : 0                },                "replicaSetId" : ObjectId("5dd12530c247798c40d9cfef")        }}
0