副本集
cd /opt/soft/mongodb
mkdir -p /opt/mongodb/data
mkdir -p /opt/mongodb/logs
touch /opt/mongodb/logs/mongodb.log
scp -r /opt/mongodb/ @slave01:/opt/
scp -r /opt/mongodb/ @slave02:/opt/
vi etc/profile
cd opt/soft/mongodb/
mkdir conf
cd conf
vi mongo.conf
systemLog:
destination:file
path:"/opt/mongodb/log/mongodb.log"
logAppend:true
storage:
dbPath:"/opt/mongodb/data"
journal:
enabled:true
processManagement:
fork:true
net:
port:27017
bindIp:192.168.217.80
scp -r /opt/soft/mongodb root@slave01:/opt/soft/
scp -r /opt/soft/mongodb root@slave02:/opt/soft/
scp -r /etc/profile root@slave01:/etc/profile
scp -r /etc/profile root@slave02:/etc/profile
cd /opt/soft/mongodb/bin
ls
./mongod --replSet itcast --dbpath=/opt/soft/mongodb/data/ --logpath=/opt/soft/mongodb/logs/mongodb.log --port 27017 --bind_ip master --logappend --fork
slave01
./mongod --replSet itcast --dbpath=/opt/soft/mongodb/data/ --logpath=/opt/soft/mongodb/logs/mongodb.log --port 27017 --bind_ip slave01 --logappend --fork
slave02
./mongod --replSet itcast --dbpath=/opt/soft/mongodb/data/ --logpath=/opt/soft/mongodb/logs/mongodb.log --port 27017 --bind_ip slave02 --logappend --fork
./mongo --host master --port 27017 (master)
./mongo --host slave01 --port 27017 (slave01)
./mongo --host slave02 --port 27017 (slave02)
rs.initiate()
rs.add("slave01:27017")
rs.add("slave02:27017")
rs.status()
use test
db.user.insert({"name":"bozai"})
db.user.find()
db.user.find() (slave02)
rs.slaveOk()
db.user.find()
分片
mkdir -p /opt/serves/mongodb_demo/shardcluster/configServer/configFile
mkdir -p /opt/serves/mongodb_demo/shardcluster/configServer/data
mkdir -p /opt/serves/mongodb_demo/shardcluster/configServer/logs
mkdir -p /opt/serves/mongodb_demo/shardcluster/shard/confile
mkdir -p /opt/serves/mongodb_demo/shardcluster/shard/shard1_data
mkdir -p /opt/serves/mongodb_demo/shardcluster/shard/shard2_data
mkdir -p /opt/serves/mongodb_demo/shardcluster/shard/shard3_data
mkdir -p /opt/serves/mongodb_demo/shardcluster/shard/logs
mkdir -p /opt/serves/mongodb_demo/shardcluster/mongos/configFile
mkdir -p /opt/serves/mongodb_demo/shardcluster/mongos/logs
touch /opt/serves/mongodb_demo/shardcluster/configServer/logs/config_server.log
touch /opt/serves/mongodb_demo/shardcluster/shard/logs/shard1.log
touch /opt/serves/mongodb_demo/shardcluster/shard/logs/shard2.log
touch /opt/serves/mongodb_demo/shardcluster/shard/logs/shard3.log
cd opt/serves/mongodb_demo/shardcluster/
tar -zxvf /mysoft/mongodb-linux-x86_64-rhel70-4.2.25.tgz
mv mongodb-linux-x86_64-rhel70-4.2.25/ mongodb
touch opt/serves/mongodb_demo/shardcluster/configServer/configFile/mongodb_config.conf
vi opt/serves/mongodb_demo/shardcluster/configServer/configFile/mongodb_config.conf
dbpath=/opt/servers/mongodb_demo/shardcluster/configServer/data
logpath=/opt/servers/mongodb_demo/shardcluster/configServer/logs/config_server.log
port=27022
bind_ip=master
logappend=true
fork=true
maxConns=5000
replSet=configs
configsvr=true
./mongo --host master --port 27022
rs.initiate()
rs.add("slave01:27022")
rs.add("slave02:27022")
db.user.find()
cd /
touch /opt/servers/mongodb_demo/shardcluster/shard/configFile/mongodb_shard1.conf
touch /opt/servers/mongodb_demo/shardcluster/shard/configFile/mongodb_shard2.conf
touch /opt/servers/mongodb_demo/shardcluster/shard/configFile/mongodb_shard3.conf
vi /opt/servers/mongodb_demo/shardcluster/shard/configFile/mongodb_shard1.conf
dbpath=/opt/soft/mongodb_demo/shardcluster/shard/shard1_data
logpath=/opt/soft/mongodb_demo/shardcluster/shard/logs/shard1.log
port=27018
bind_ip=master
logappend=true
fork=true
maxConns=5000
replSet=shard1
shardsvr=true
./mongod -f /opt/servers/mongodb_demo/shardcluster/shard/configFile/mongodb_shard1.conf