Mongodb 之多实例

2016年12月13日

安装 mongodb

本文基于apt-get 安装的 mongodb , 其实这里编译还是apt 没什么差别

复制 mongod.conf

cp  /etc/mongod.conf  /etc/mongod27018.conf

更改大致如下 :

# mongod.conf

# for documentation of all options, see:
#   http://docs.mongodb.org/manual/reference/configuration-options/

# Where and how to store data.
#processManagement:
#    fork: true
#    pidFilePath: /var/run/mongodb/27017.pid

storage:
dbPath: /home/mongodb/27018/
#directoryPerDB: true
#indexBuildRetry: false
# quota:
#   enforced: false
#   maxFilesPerDB: 8
#  syncPeriodSecs: 60
# repairPath: "/var/lib/mongo/_tmp"
journal:
enabled: true
#   debugFlags: 1
#    commitIntervalMs: 100
#  engine:
#  mmapv1:
#  wiredTiger:

# where to write logging data.
systemLog:
destination: file
path: /var/log/mongodb/mongod27018.log
quiet: true
logAppend: true

# network interfaces
net:
port: 27018
bindIp: 0.0.0.0
http:
enabled: true
RESTInterfaceEnabled: false
#net.http.enabled
processManagement:
fork: true
pidFilePath: "/var/run/mongodb/mongod27018.pid"

#replication:
#  oplogSizeMB: 1024
#  replSetName: "mongo_zzz"
#  secondaryIndexPrefetch: "all"
#security:

replication:
oplogSizeMB: 1024
replSetName: mongo_zzz #集群唯一的名字

#operationProfiling:

#replication:

#sharding:

## Enterprise-Only Options:

#auditLog:

#snmp:

创建 dbPath mongodb 存储目录

创建启动脚本

cat /home/shell/momgod

#!/bin/sh
mongo_port=$2

case $mongo_port in
27017)
export project='MongoDB_Master'
;;
27018)
export project='MongoDB_Slave'
;;
27019)
export project='MongoDB_Slave'
;;
27020)
export project='MongoDB_Slave'
;;

*)
;;
esac

mongodconf=/etc/mongod$mongo_port.conf

echo  $project;
#su mongodb

function_start_momgo()
{
# printf "Starting MongoDB...\n"
if [ -f $mongodconf  ]
then
printf "Starting MongoDB...\n"
/usr/bin/mongod   --quiet --config $mongodconf  2>&1 > /dev/null &
# /usr/bin/mongod --quiet --config $mongodconf
else
echo "Are you sure the configuration file exist? Please Check !"
fi
}

function_stop_momgo()
{
#printf "Stoping MongoDB...\n"
if [ -f $mongodconf  ]
then
printf "Stoping MongoDB...\n"
/usr/bin/mongod  --config $mongodconf  --shutdown
else
echo "Please Check The Port Exist  Or This Mongodb Instance Is Running ?"
fi

}

function_connect_mongo()
{
mongo 127.0.0.1:$mongo_port
}

function_restart_momgo()
{
printf "Restarting MySQL...\n"
function_stop_momgo
sleep 3;
function_start_momgo
}

if [ "$1" = "start" ]; then
function_start_momgo
elif [ "$1" = "stop" ]; then
function_stop_momgo
elif [ "$1" = "restart" ]; then
function_restart_momgo
elif [ "$1" = "connect" ]; then
function_connect_mongo
#elif [ "$1" = "kill" ]; then
#    function_kill_mysql
else
printf "Usage: ./mysql {start|stop|restart|connect} port\n"
fi

chmod +x /home/shell/mongod

/home/shell/mongod start 27018

没有评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注