部署replica set

replica set应该有奇数个成员,这样可以让选举正常进行。需要在每个机器上安装mongodb,replica set成员的网络必须是可通的,下面是测试的方式
EXAMPLE
Given a replica set with three members running on three separate hosts:

m1.example.net
m2.example.net
m3.example.net
Test the connection from m1.example.net to the other hosts with the following operation set m1.example.net:
mongo –host m2.example.net –port 27017

mongo –host m3.example.net –port 27017
Test the connection from m2.example.net to the other two hosts with the following operation set from m2.example.net, as in:
mongo –host m1.example.net –port 27017

mongo –host m3.example.net –port 27017
You have now tested the connection between m2.example.net and m1.example.net in both directions.
Test the connection from m3.example.net to the other two hosts with the following operation set from the m3.example.net host, as in:
mongo –host m1.example.net –port 27017

mongo –host m2.example.net –port 27017

在/etc/mongod.conf中配置指定存储数据的位置

1启动replica set中的每个成员
对每个成员,启动mongod,指定replica set名称
mongod –replSet “rs0”
也可以在控制文件中指定replica set的名字,然后用控制文件启动
mongod –config $HOME/.mongodb/config
2连接replica set 成员
3初始化replica set
只在一个成员上使用rs.initiate()初始化
4验证replica set配置
rs.conf()
5添加其他成员到replica set中
rs.add(“mongodb1.example.net”)
这个命令在一些情况下会触发一次选举,如果连接的mongod变成了secondary,你就需要使用mongoshell 连接到新的primary,在继续添加成员,可以使用rs.status() 来标识primary
6查看
rs.status()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值