>데이터 베이스 >MySQL 튜토리얼 >MongoDB学习整理之Replica Sets安装

MongoDB学习整理之Replica Sets安装

WBOY
WBOY원래의
2016-06-07 17:14:30798검색

MongoDB学习整理之Replica Sets安装

准备:       
        服务器       端口             数据目录                                        日志                                    复制集key文件
        Server1  28010   /app/mongo/mongodb/data/sets/r0    /app/mongo/mongodb/data/sets/log/r0.log    /app/mongo/mongodb/data/sets/key/r0
        Server2  28011   /app/mongo/mongodb/data/sets/r1    /app/mongo/mongodb/data/sets/log/r2.log    /app/mongo/mongodb/data/sets/key/r1
        Server3  28012   /app/mongo/mongodb/data/sets/r2    /app/mongo/mongodb/data/sets/log/r3.log    /app/mongo/mongodb/data/sets/key/r2

1、创建数据文件、日志路径目录及复制集key文件
        mkdir -p /app/mongo/mongodb/data/sets/r0
        mkdir -p /app/mongo/mongodb/data/sets/r1
        mkdir -p /app/mongo/mongodb/data/sets/r2
        mkdir -p /app/mongo/mongodb/data/sets/key/
        mkdir -p /app/mongo/mongodb/data/sets/log/

        echo "test sets" > /app/mongo/mongodb/data/sets/key/r0
        echo "test sets" > /app/mongo/mongodb/data/sets/key/r1
        echo "test sets" > /app/mongo/mongodb/data/sets/key/r2

        chmod 600 /app/mongo/mongodb/data/sets/key/r*

2、启动3个mongodb实例模拟3个节点服务器:

/app/mongo/mongodb/bin/mongod --replSet rs1 --keyFile /app/mongo/mongodb/data/sets/key/r0 --port 28010 --dbpath=/app/mongo/mongodb/data/sets/r0 --logpath=/app/mongo/mongodb/data/sets/log/r0.log --logappend --fork

/app/mongo/mongodb/bin/mongod --replSet rs1 --keyFile /app/mongo/mongodb/data/sets/key/r1 --port 28011 --dbpath=/app/mongo/mongodb/data/sets/r1 --logpath=/app/mongo/mongodb/data/sets/log/r2.log --logappend --fork

/app/mongo/mongodb/bin/mongod --replSet rs1 --keyFile /app/mongo/mongodb/data/sets/key/r2 --port 28012 --dbpath=/app/mongo/mongodb/data/sets/r2 --logpath=/app/mongo/mongodb/data/sets/log/r3.log --logappend --fork

3、初始化Replica Sets环境
[mongodb@ mongo]$ /app/mongo/mongodb/bin/mongo -port 28010      //连接

>config_rs={_id:'rs1',members:[{_id:0,host:'localhost:28010'},{_id:1,host:'localhost:28011'},{_id:2,host:'localhost:28012'}]}
>rs.initiate(config_rs);

4、查看复制集状态,分析复制集的各项运行指标,如图所示:

MongoDB学习整理之Replica Sets安装

MongoDB学习整理之Replica Sets安装

OK,,成功了。

linux

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.