环境
centos7.4 mongodb-4.0.22
配置说明
Shard | config | mongos | |
192.168.56.1 | 27017 | 27018 | 27019 |
192.168.56.2 | 27017 | 27018 | |
192.168.56.3 | 27017 | 27018 | |
192.168.56.4 | 27017 |
安装过程
Shard(27017) | Config(27018) | mongos(27019) | |
安装 | useradd mongodb -p mongodb su - mongodb
wget xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx/mongodb-linux-x86_64-4.0.22.tgz tar -zxf mongodb-linux-x86_64-4.0.22.tgz
vim .bash_profile
| ||
配置文件 | processManagement:
net: storage:
| processManagement:
replication: sharding: | processManagement: net: sharding: 192.168.56.2:27018,192.168.56.3:27018 |
创建目录 | su - mongodb mkdir mongodb_27017 touch mongodb_27017/mongodb.log | su - mongodb mkdir mongodb_27018 touch mongodb_27018/mongodb.log | su - mongodb mongodb_27019 touch mongodb_27019/mongodb.log |
启动实例 | /home/mongodb/mongodb/bin/mongod -f /home/mongodb/mongod_27017.conf & | ||
初始化 副本集 | mongo --host 127.0.0.1:27018
{_id: 0, host: "192.168.56.1:27018"}, {_id: 1, host: "192.168.56.2:27018"}, {_id: 2, host: "192.168.56.3:27018"} ]}
rs.status() | ||
添加分片 | mongo --host 127.0.0.1:27019
sh.addShard("192.168.56.3:27017") sh.addShard("192.168.56.4:27017") sh.status() | ||
表分片 | mongo --host 127.0.0.1:27019
use admin;
sh.status() |