mkdir /data/mongod/shard1/{log,db} -p mkdir /data/mongod/shard2/{log,db} -p mkdir /data/mongod/shard3/{log,db} -p chmod -R 777 /data/mongod/shard1 chmod -R 777 /data/mongod/shard2 chmod -R 777 /data/mongod/shard3 mkdir -p /data/mongod/conf/{shard1,shard2,shard3} |
storage: dbPath: /home/mongod/db journal: enabled: true directoryPerDB: true systemLog: destination: file logAppend: true path: /home/mongod/log/mongod.log net: bindIpAll: true setParameter: enableLocalhostAuthBypass: false replication: replSetName: rs_shardsvr1 sharding: clusterRole: shardsvr |
storage: dbPath: /home/mongod/db journal: enabled: true directoryPerDB: true systemLog: destination: file logAppend: true path: /home/mongod/log/mongod.log net: bindIpAll: true setParameter: enableLocalhostAuthBypass: false replication: replSetName: rs_shardsvr2 sharding: clusterRole: shardsvr |
storage: dbPath: /home/mongod/db journal: enabled: true directoryPerDB: true systemLog: destination: file logAppend: true path: /home/mongod/log/mongod.log net: bindIpAll: true setParameter: enableLocalhostAuthBypass: false replication: replSetName: rs_shardsvr3 sharding: clusterRole: shardsvr |
docker run --name shardsvr1 -d -p 9005:27018 \ --entrypoint "mongod" \ -v /data/mongod/shard1:/home/mongod \ -v /data/mongod/conf/keyfile/:/data/keyfile/ \ -v /data/mongod/conf/shard1/:/data/conf/ \ mongo:4.0.21 -f /data/conf/mongod.conf |
docker exec -it shardsvr1 bash mongo --host 172.17.140.41 --port 9005 use admin rs.initiate( { _id : "rs_shardsvr1", members: [ { _id : 0, host : "172.17.140.41:9005",priority:5 }, { _id : 1, host : "172.17.140.42:9005",priority:3 }, { _id : 2, host : "172.17.140.43:9005",arbiterOnly:true} ] } ) |
docker run --name shardsvr2 -d -p 9006:27018 \ --entrypoint "mongod" \ -v /data/mongod/shard2:/home/mongod \ -v /data/mongod/conf/keyfile/:/data/keyfile/ \ -v /data/mongod/conf/shard2/:/data/conf/ \ mongo:4.0.21 -f /data/conf/mongod.conf |
mongo --host 172.17.140.42 --port 9006 use admin rs.initiate( { _id : "rs_shardsvr2", members: [ { _id : 0, host : "172.17.140.41:9006",arbiterOnly:true }, { _id : 1, host : "172.17.140.42:9006",priority:5 }, { _id : 2, host : "172.17.140.43:9006",priority:3 } ] } ) |
docker run --name shardsvr3 -d -p 9007:27018 \ --entrypoint "mongod" \ -v /data/mongod/shard3:/home/mongod \ -v /data/mongod/conf/keyfile/:/data/keyfile/ \ -v /data/mongod/conf/shard3/:/data/conf/ \ mongo:4.0.21 -f /data/conf/mongod.conf |
mongo --host 172.17.140.43 --port 9007 use admin rs.initiate( { _id : "rs_shardsvr3", members: [ { _id : 0, host : "172.17.140.41:9007",priority:3 }, { _id : 1, host : "172.17.140.42:9007",arbiterOnly:true }, { _id : 2, host : "172.17.140.43:9007",priority:5 } ] } ) |