Open cavacn opened 8 years ago
es0
es1
es2
cp /etc/init.d/mongod /etc/init.d/mongod-config
cp /etc/init.d/mongod /etc/init.d/mongod-db1
cp /etc/init.d/mongod /etc/init.d/mongod-db2
cp /etc/init.d/mongod /etc/init.d/mongod-db3
vim /etc/init.d/mongod-db*
找到
CONFIGFILE=/etc/mongod.conf
依次修改CONFIGFILE=/etc/mongod-**.conf
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod-db1.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo-db1
directoryPerDB: true
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod-db1.pid # location of pidfile
# network interfaces
net:
port: 10001
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
sharding:
clusterRole: shardsvr
replication:
replSetName: shard1
## Enterprise-Only Options
#auditLog:
# mongod.conf
# for documentation of all options, see:
# http://docs.mongodb.org/manual/reference/configuration-options/
# where to write logging data.
systemLog:
destination: file
logAppend: true
path: /var/log/mongodb/mongod-config.log
# Where and how to store data.
storage:
dbPath: /var/lib/mongo-config
directoryPerDB: true
journal:
enabled: true
# engine:
# mmapv1:
# wiredTiger:
# how the process runs
processManagement:
fork: true # fork and run in background
pidFilePath: /var/run/mongodb/mongod-config.pid # location of pidfile
# network interfaces
net:
port: 20000
# bindIp: 127.0.0.1 # Listen to local interface only, comment to listen on all interfaces.
#security:
#operationProfiling:
#replication:
#sharding:
sharding:
clusterRole: configsvr
#replication:
# replSetName: shard1
## Enterprise-Only Options
#auditLog:
三台服务器都要做
service mongod-db1 start
service mongod-db2 start
service mongod-db3 start
service mongod-config start
nohup mongos --port 3000 --configdb host1.port,host2.port,host3.port &
mongo host:3000
mongos>use admin
mongos>db.runCommand({"addShard":"shardId/host:port"})
mongos>db.runCommand({"addShard":"shardId/host:port"})
mongos>db.runCommand({"addShard":"shardId/host:port"})
mongos>db.runCommand({listshards:1}) #查看状态
mongos>db.runCommand({"enablesharding":"库名"})
{ "ok" : 1 }
mongos> db.runCommand({"shardcollection":"库名.表名","key":{_id:'hashed'}})
{ "collectionsharded" : "库名.表名", "ok" : 1 }
安装mongodb
更新系统
安装mongodb