Home > Database > Mysql Tutorial > MongoDB复制集搭建

MongoDB复制集搭建

WBOY
Release: 2016-06-07 17:20:44
Original
893 people have browsed it

MongoDB复制集搭建,默认从库不可查询,执行如下语句使得当前从库可以查询,分担主库查询负载

看了mongodb权威指南之后,对于读写分离的方式采用复制集比较合适,一般的系统足够使用了。

很容易找到下载地址,暂不累述,,只描述关键步骤。

2台服务器分别为201和202 共3个节点,2个初始配置在202上,1个后来添加在201上

先部署2个节点
202:
./mongod --dbpath ./db1 --port 10002 --replSet blort/Server202:10001
./mongod --dbpath ./db --port 10001 --replSet blort/Server202:10002

./mongo Server202:10001/admin
db.runCommand({"replSetInitiate":{"_id":"blort","members":[{"_id":1,"host":"Server202:10001"},{"_id":2,"host":"Server202:10002"}]}})
db._adminCommand("replSetGetStatus");

增加一个节点
201:
./mongod --dbpath ./db --port 10001 --replSet blort/Server202:10002
202:
rs.add("Server201:10002");

默认从库不可查询,执行如下语句使得当前从库可以查询,分担主库查询负载
db.getMongo().setSlaveOk()

随机器自动启动脚本在/etc/rc.local
rm -rf /home/aircom/mongodb-linux-i686-2.0.6/bin/db/*.lock
rm -rf /home/aircom/mongodb-linux-i686-2.0.6/bin/db1/*.lock
/home/aircom/mongodb-linux-i686-2.0.6/bin/mongod --dbpath /home/aircom/mongodb-linux-i686-2.0.6/bin/db --port 10001 --replSet blort/Server202:10002 --fork --logpath /home/aircom/mongodb-linux-i686-2.0.6/bin/log/1001.log
/home/aircom/mongodb-linux-i686-2.0.6/bin/mongod --dbpath /home/aircom/mongodb-linux-i686-2.0.6/bin/db1 --port 10002 --replSet blort/Server202:10001 --fork --logpath /home/aircom/mongodb-linux-i686-2.0.6/bin/log/1002.log

修改配置,如修改优先级等,可以利用优先级来控制主几点那个ji
conf=rs.conf()
conf.members[0].priority=3
conf.members[1].priority=2
conf.members[2].priority=1
conf.members[3].priority=0.5
rs.reconfig(conf)

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template