2014年(9)
分类: NOSQL
2014-09-28 16:24:05
安装:
下载mongodb,
tar xf mongodb-linux-x86_64-2.6.4.gz
mv mongodb-linux-x86_64-2.6.4 /usr/local/mongodb
编辑/etc/profile 增加如下一行
export PATH/usr/local/mongodb/bin:${PATH}
执行命令:source /etc/profile
mkdir /data/mongodb -p
mkdir /data/logs/mongodb -p
管理脚本:
cat mongodb.sh
#!/bin/bash
DIRMONGODB='/usr/local/mongodb/'
DIRMONGODBDATA='/data/mongodb/'
MONGODBLOG='/data/logs/mongodb/mongodb.log'
MONGODBPORT='27017'
case "$1" in
start)
MONGODPID=$(ps -ef | grep "mongod" | grep "${MONGODBPORT}" | grep -v "grep" | awk '{print $2}')
if [ "${MONGODPID}" == "" ]
then
${DIRMONGODB}/bin/mongod --dbpath=${DIRMONGODBDATA} --logpath=${MONGODBLOG} --logappend --port=${MONGODBPORT} --auth --fork > /dev/null 2>&1
fi
echo "mongodb start success......"
;;
stop)
MONGODPID=$(ps -ef | grep "mongod" | grep "${MONGODBPORT}" | grep -v "grep" | awk '{print $2}')
if [ "${MONGODPID}" != "" ]
then
kill -2 ${MONGODPID}
fi
echo "mongodb stop success......"
;;
restart)
$0 stop
$0 start
;;
*)
echo "Usage:$0 {start|stop|restart}"
exit 1
esac
exit 0
权限:
创建超级用户,即访问不受限,use admin; db.createUser({user: "root", pwd: "root", roles: ["root"]})
其它数据库创建自己的用户,如:use test; db.createUser({user: "test", pwd: "test", roles: [{role: "readWrite", db: "test"}]})
这样,root用户能管理所数据库,test用户就只能管理test数据库了