MongoDB学习整理之Replica Sets安装
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、查看复制集状态,分析复制集的各项运行指标,如图所示:
OK,,成功了。
上一篇: 关于页面超时