debian安装mongoDB
Posted php、凯
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了debian安装mongoDB相关的知识,希望对你有一定的参考价值。
wget http://fastdl.mongodb.org/linux/mongodb-linux-i686-1.8.2.tgz
tar zxf mongodb-linux-i686-1.8.2.tgz
mv mongodb-linux-i686-1.8.2 /usr/local/mongodb
mkdir /data/mongodb
touch /var/log/mongodb/mongod.log
vim /etc/mongod.conf
插入内容
systemLog:
destination: file
path: "/var/log/mongodb/mongod.log"
logAppend: true
storage:
dbPath: "/data/mongodb"
journal:
enabled: true
processManagement:
fork: true
net:
bindIpAll: true
port: 27017
setParameter:
enableLocalhostAuthBypass: false
添加rc.local文件
cat <<EOF >/etc/rc.local
#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.
exit 0
EOF
赋予权限
chmod +x /etc/rc.local
启动rc.local服务
systemctl start rc-local
启动mongodb服务
/usr/local/mongodb/bin/mongod --config=/etc/mongod.conf
如果出现
mongod: error while loading shared libraries: libcurl.so.4: cannot open shared object file: No such file or directory
需要安装curl
apt-get install curl
切换到admin目录
use admin
添加管理用户root(所有)
db.createUser({user: "root",pwd: "*******",roles: [ { role: "root", db: "admin" } ]});
添加数据获取用户zz_api(读写)
db.createUser({user: "zz_api",pwd: "*******",roles: [ { role: "readWrite", db: "zz_web" } ]});
添加爬虫用户zz_spider(读写)
db.createUser({user: "zz_spider",pwd: "*******",roles: [ { role: "readWrite", db: "zz_web" } ]});
创建zz_web数据库
use zz_web
退出
exit
添加开机自启
vim /etc/rc.local
在exit 0之前添加
/usr/local/mongodb/bin/mongod --auth --config=/etc/mongodb.conf >/dev/null 2>&1
退出重启服务器测试
以上是关于debian安装mongoDB的主要内容,如果未能解决你的问题,请参考以下文章