下载
wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-v4.2-latest.tgz
解压缩
tar zxvf mongodb-linux-x86_64-rhel70-v4.2-latest.tgz -C /opt/module/
重命名
mv /opt/module/mongodb-linux-x86_64-rhel70-4.2.0-81-g7897a0a /opt/module/mongodb
增加环境变量
## MONGODB_HOME
export MONGODB_HOME= /opt/module/mongodb
export PATH=$PATH:$MONGODB_HOME/bin
启动
[hadoop@hadoop11 mongodb]$ mkdir data
[hadoop@hadoop11 mongodb]$ mongod --dbpath=./data --logpath=./data/mongo.log --bind_ip=hadoop11 --fork --replSet=xiechuan
about to fork child process, waiting until server is ready for connections.
forked process: 11614
child process started successfully, parent exiting
配置
cfg = {
_id: "xiechuan",
members: [
{
_id: 0,
host: 'hadoop11:27017',
priority: 3
},
{
_id: 1,
host: 'hadoop12:27017',
priority: 2
},
{
_id: 2,
host: 'hadoop13:27017',
priority: 1
},
{
_id: 3,
host: 'hadoop14:27017',
arbiterOnly: true
}
]
};
[hadoop@hadoop11 mongodb]$ mongo hadoop11:27017
> use admin
switched to db admin
> cfg = {
... _id: "xiechuan",
... members: [
... {
... _id: 0,
... host: 'hadoop11:27017',
... priority: 3
... },
... {
... _id: 1,
... host: 'hadoop12:27017',
... priority: 2
... },
... {
... _id: 2,
... host: 'hadoop13:27017',
... priority: 1
... },
... {
... _id: 3,
... host: 'hadoop14:27017',
... arbiterOnly: true
... }
... ]
... };
{
"_id" : "xiechuan",
"members" : [
{
"_id" : 0,
"host" : "hadoop11:27017",
"priority" : 3
},
{
"_id" : 1,
"host" : "hadoop12:27017",
"priority" : 2
},
{
"_id" : 2,
"host" : "hadoop13:27017",
"priority" : 1
},
{
"_id" : 3,
"host" : "hadoop14:27017",
"arbiterOnly" : true
}
]
}
> rs.initiate(cfg)
{
"ok" : 1,
"$clusterTime" : {
"clusterTime" : Timestamp(1566798881, 1),
"signature" : {
"hash" : BinData(0,"AAAAAAAAAAAAAAAAAAAAAAAAAAA="),
"keyId"