基本环境搭建:
useradd octopus-app-user
chgrp octopus-app-user /data -R
chown octopus-app-user /data -R
-====================================
IP:10.250.67.54
|
IP:10.250.67.26
|
IP:10.250.67.4
|
---|---|---|
mongos(27017) | mongos(27017) | mongos(27017) |
config(30000) | config(30000) | config(30000) |
shard1主节点(40001) | shard1副节点(40001) | shard1副节点(40001) |
shard2主节点(40002) | shard2副节点(40002) | shard1副节点(40002) |
shard3主节点(40003) | shard3副节点(40003) | shard1副节点(40003) |
https://www.cnblogs.com/mokafamily/p/4102829.html
http://blog.51cto.com/13643643/2148825
1.--=====创建目录================
mkdir -p /data/mongodb/logs/ log的存放目录
mkdir -p /data/mongodb/etc 配置文件的存放目录
mkdir /data/mongodb/config/
mkdir /data/mongodb/shard{1,2,3}
touch /data/mongodb/logs/shard{1,2,3}.log
touch /data/mongodb/logs/mongos.log
touch /data/mongodb/logs/config.log
chmod 777 /data/mongodb/logs/*.log
2.mongo_config配置
(1)启动config实例:
/data/srv/mongodb-linux-x86_64-4.0.4/bin/mongod -f /data/mongodb/etc/config.conf 三台的操作一致
(2)配置config的副本集:mongo --port 30000
cfg={_id:"OctopusConfigDBset", members:[{_id:0, host:'10.250.67.54:30000', priority:50},{_id:1, host:'10.250.67.26:30000', priority:30}, {_id:2,host:'10.250.67.4:30000', priority:20}]};
rs.initiate(cfg);
--==========================================
3.mongo_shard1配置
(1)启动shard实例:
/data/srv/mongodb-linux-x86_64-4.0.4/bin/mongod -f /data/mongodb/etc/shard1.conf 三台的操作一致
(2)配置shard1的副本集:mongo --port 40001
cfg={_id:"OctopusShard1DBset", members:[{_id:0, host:'10.250.67.54:40001', priority:50},{_id:1, host:'10.250.67.26:40001', priority:30}, {_id:2,host:'10.250.67.4:40001', priority:20}]};
rs.initiate(cfg);
4.mongo_shard2配置
(1)启动shard实例:
/data/srv/mongodb-linux-x86_64-4.0.4/bin/mongod -f /data/mongodb/etc/shard2.conf 三台的操作一致
(2)配置shard2的副本集:mongo --port 40002
cfg={_id:"OctopusShard2DBset", members:[{_id:0, host:'10.250.67.54:40002', priority:50},{_id:1, host:'10.250.67.26:40002', priority:30}, {_id:2,host:'10.250.67.4:40002', priority:20}]};
rs.initiate(cfg);
5.mongo_shard3配置 (:% s/1/3/gc)
(1)启动shard实例:
/data/srv/mongodb-linux-x86_64-4.0.4/bin/mongod -f /data/mongodb/etc/shard3.conf 三台的操作一致
(2)配置shard3的副本集:mongo --port 40003
cfg={_id:"OctopusShard3DBset", members:[{_id:0, host:'10.250.67.54:40003', priority:50},{_id:1, host:'10.250.67.26:40003', priority:30}, {_id:2,host:'10.250.67.4:40003', priority:20}]};
rs.initiate(cfg);
--================================================
6.mongo_mongos路由服务器
(1)启动mongos路由:
/data/srv/mongodb-linux-x86_64-4.0.4/bin/mongos -f /data/mongodb/etc/mongos.conf //三台服务器操作一致
(2)启动分片功能:
mongo //因为默认端口即是27017,所以此处不接端口号
mongos> use admin
mongos> sh.addShard("OctopusShard1DBset/10.250.67.54:40001,10.250.67.26:40001,10.250.67.4:40001")
mongos> sh.addShard("OctopusShard2DBset/10.250.67.54:40002,10.250.67.26:40002,10.250.67.4:40002")
mongos> sh.status() //查看群集状态