标签:info _id logs pretty 查看 集群 server man out
机器:ubuntu 2台
ip:
安装mongodb
sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 0C49F3730359A14518585931BC711F9BA15703C6 echo "deb [ arch=amd64 ] http://repo.mongodb.org/apt/ubuntu trusty/mongodb-org/3.4 multiverse" | sudo tee /etc/apt/sources.list.d/mongodb-org-3.4.list sudo apt-get update sudo apt-get install -y mongodb-org
文件目录
port:
27018 分片
dbpath:
null mongos
/app/mongo/data/config/data configServer
/app/mongo/data/shard/data shard
将启动mongod配置文件放在/app/mongo/config目录下
在192.168.0.131
mkdir -p /app/mongo/data/config/data mkdir -p /app/mongo/data/config/log vim /app/mongo/config/configserver.conf
dbpath=/app/mongo/data/config/data port=30000 bind_ip=0.0.0.0 configsvr=true replSet=conf
利用supervisor启停
[program:configdb] command=mongod -f /app/mongo/config/configserver.conf autostart=true autorestart=true stderr_logfile =/app/mongo/data/config/log/err.log stdout_logfile =/app/mongo/data/config/log/out.log
在192.168.0.132 同样操作
登陆任意服务器客户端初始化config
mongo --port 30000
config = {_id:"conf", members:[ {_id:0, host:"192.168.0.131:30000"}, {_id:1, host:"192.168.0.132:30000"} ] }; rs.initiate(config);
在192.168.0.132
mkdir -p /app/mongo/data/mongos/log
vim /app/mongo/config/mongos.conf
port = 27017
bind_ip=0.0.0.0 configdb=conf/192.168.0.131:30000,192.168.0.132:30000
利用supervisor启停
[program:mongos] command=mongos -f /app/mongo/config/mongos.conf autostart=true autorestart=true stdout_logfile = /app/mongo/data/mongos/log/out.log stderr_logfile = /app/mongo/data/mongos/log/err.log loglevel=info
在192.168.0.131
mkdir -p /app/mongo/data/shard/data
mkdir -p /app/mongo/data/shard/logs
vim /app/mongo/config/mongod.conf
dbpath=/app/mongo/data/shard/data
port=27018
bind_ip=0.0.0.0
shardsvr=true
利用supervisor启停
#mongod.conf [program:mongod] command=mongod -f /app/mongo/config/mongod.conf autorestart=true redirect_stderr=true stdout_logfile = /app/mongo/data/shard/logs/mongod.log loglevel=info
supervisorctl reload
在192.168.0.132
mkdir -p /app/mongo/data/shard/data mkdir -p /app/mongo/data/shard/logs
mongo --port 27017 use admin db.runCommand( {addshard : "192.168.0.131:27018"}); db.runCommand( {addshard : "192.168.0.132:27018"});
查看节点信息
db.runCommand( { listshards : 1 } );
为数据库添加分片主键(以db.col为例)
sh.enableSharding("db")
db.runCommand({"shardCollection":"db.col","key":{"_id":1}})
标签:info _id logs pretty 查看 集群 server man out
原文地址:https://www.cnblogs.com/fwdqxl/p/9097362.html