标签:var source 目录 -- 切换 成功 bin nal text
安装版本:3.0.7
安装机器:所有机器
安装过程:
$ tar -zxvf mongodb-${version}.tar.gz -C /opt/hadoop/
$ ln -s /opt/hadoop/mongodb-${version} /opt/hadoop/mongodb
# vim /etc/profile
export MONGODB_HOME=/opt/hadoop/mongodb
export PATH=${MONGODB_HOME}/bin:$PATH
# source /etc/profile
$ mkdir -p /opt/hadoop/mongodb/data/configsvr
$ mkdir -p /opt/hadoop/mongodb/data/rs0-0
$ mkdir -p /opt/hadoop/mongodb/data/rs1-0
$ vim /opt/hadoop/mongodb/conf/configsvr.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/configsvr.log"
pidFilePath: "/opt/hadoop/mongodb/configsvr.pid"
dbPath: "/opt/hadoop/mongodb/data/configsvr"
$ vim /opt/hadoop/mongodb/conf/mongos.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/mongos.log"
pidFilePath: "/opt/hadoop/mongodb/mongos.pid"
$ vim /opt/hadoop/mongodb/conf/rs0.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs0-0.log"
pidFilePath: "/opt/hadoop/mongodb/rs0-0.pid"
dbPath: "/opt/hadoop/mongodb/data/rs0-0"
$ vim /opt/hadoop/mongodb/conf/rs1.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs1-0.log"
pidFilePath: "/opt/hadoop/mongodb/rs1-0.pid"
dbPath: "/opt/hadoop/mongodb/data/rs1-0"
$ scp -r /opt/hadoop/mongodb-${version} hadoop@baseline02:/opt/hadoop
$ ln -s /opt/hadoop/mongodb-${version} /opt/hadoop/mongodb
$ mv /opt/hadoop/mongodb/data/rs0-0 /opt/hadoop/mongodb/data/rs0-1
$ mv /opt/hadoop/mongodb/data/rs1-0 /opt/hadoop/mongodb/data/rs1-1
$ vim /opt/hadoop/mongodb/conf/rs0.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs0-1.log"
pidFilePath: "/opt/hadoop/mongodb/rs0-1.pid"
dbPath: "/opt/hadoop/mongodb/data/rs0-1"
$ vim /opt/hadoop/mongodb/conf/rs1.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs1-1.log"
pidFilePath: "/opt/hadoop/mongodb/rs1-1.pid"
dbPath: "/opt/hadoop/mongodb/data/rs1-1"
$ scp -r /opt/hadoop/mongodb-${version} hadoop@baseline03:/opt/hadoop
$ ln -s /opt/hadoop/mongodb-${version} /opt/hadoop/mongodb
$ mv /opt/hadoop/mongodb/data/rs0-0 /opt/hadoop/mongodb/data/rs0-2
$ mv /opt/hadoop/mongodb/data/rs1-0 /opt/hadoop/mongodb/data/rs1-2
$ vim /opt/hadoop/mongodb/conf/rs0.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs0-2.log"
pidFilePath: "/opt/hadoop/mongodb/rs0-2.pid"
dbPath: "/opt/hadoop/mongodb/data/rs0-2"
$ vim /opt/hadoop/mongodb/conf/rs1.conf
修改以下内容
path: "/opt/hadoop/mongodb/logs/rs1-2.log"
pidFilePath: "/opt/hadoop/mongodb/rs1-2.pid"
dbPath: "/opt/hadoop/mongodb/data/rs1-2"
三台机器顺序启动mongod的服务:
$ mongod --config /opt/hadoop/mongodb/conf/rs0.conf
$ mongo baseline01:27017
连接成功后执行:
>rs0conf = {
_id: "rs0",
members: [
{
_id: 0,
host: "baseline01:27017"
}
]
}
>rs.initiate( rs0conf )
>rs.add("baseline02:27017")
>rs.add("baseline03:27017")
>rs.status() //半分钟后执行该命令,若出现一主两从则说明rs0配置成功
rs1配置:
三台机器顺序启动mongod的服务:
$ mongod --config /opt/hadoop/mongodb/conf/rs1.conf
在baseline01上执行连接到mongod实例:
$ mongo baseline01:27018
>rs1conf = {
_id: "rs1",
members: [
{
_id: 0,
host: "baseline01:27018"
}
]
}
>rs.initiate( rs1conf )
>rs.add("baseline02:27018")
>rs.add("baseline03:27018")
>rs.status() //半分钟后执行该命令,若出现一主两从则说明rs1配置成功
$ mongod --config /opt/hadoop/mongodb/conf/configsvr.conf
$ mongos --config /opt/hadoop/mongodb/conf/mongos.conf
$ mongo baseline01:27000
mongos> use admin
mongos>db.runCommand({addshard:"rs0/baseline01:27017,baseline02:27017,baseline03:27017"})
mongos>db.runCommand({addshard:"rs1/baseline01:27018,baseline02:27018,baseline03:27018"})
mongos>db.runCommand({listshards:1})
mongos>db.runCommand({enablesharding:"testdb"})
mongos>db.runCommand({shardcollection:"testdb.test_table",key:{id:1}})
$ mongo baseline01:27000
mongos>use testdb
mongos>for(var i = 1; i <= 50000; i++) db.test_table.insert( { "id":i, "name":"str"+i, "date":new Date() } )
WriteResult({ "nInserted" : 1 })
mongos>db.test_table.stats()
查看分片状态,若rs0和rs1上分别有数据,说明部署成功
标签:var source 目录 -- 切换 成功 bin nal text
原文地址:http://www.cnblogs.com/wyl9527/p/6395396.html